src/Entity/UserSettings.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\User\Permission;
  4. use App\Enum\User\PermissionGroup;
  5. use App\Library\Utils\DateUtils;
  6. use App\Repository\UserSettingsRepository;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=UserSettingsRepository::class)
  10.  */
  11. class UserSettings
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="boolean", nullable=true)
  21.      */
  22.     private $canEditCalendarEvents;
  23.     /**
  24.      * @ORM\Column(type="boolean", nullable=true)
  25.      */
  26.     private $canEditStudents;
  27.     /**
  28.      * @ORM\Column(type="boolean", nullable=true)
  29.      */
  30.     private $canViewCandidates;
  31.     /**
  32.      * @ORM\Column(type="boolean", nullable=true)
  33.      */
  34.     private $canEditPayments;
  35.     /**
  36.      * @ORM\Column(type="boolean", nullable=true)
  37.      */
  38.     private $canReviewCandidates;
  39.     /**
  40.      * @ORM\Column(type="boolean", nullable=true)
  41.      */
  42.     private $canViewStudents;
  43.     /**
  44.      * @ORM\Column(type="boolean", nullable=true)
  45.      */
  46.     private $canViewCalendarEvents;
  47.     /**
  48.      * @ORM\Column(type="boolean", nullable=true)
  49.      */
  50.     private $canViewCalendarEventKinds;
  51.     /**
  52.      * @ORM\Column(type="boolean", nullable=true)
  53.      */
  54.     private $canEditCalendarEventKinds;
  55.     /**
  56.      * @ORM\Column(type="boolean", nullable=true)
  57.      */
  58.     private $canViewZoomReport;
  59.     /**
  60.      * @ORM\Column(type="boolean", nullable=true)
  61.      */
  62.     private $canViewPaymentsReport;
  63.     /**
  64.      * @ORM\Column(type="boolean", nullable=true)
  65.      */
  66.     private $canViewStudentsPersonalData;
  67.     /**
  68.      * @ORM\Column(type="boolean", nullable=true)
  69.      */
  70.     private $canViewPayments;
  71.     /**
  72.      * @ORM\Column(type="boolean", nullable=true)
  73.      */
  74.     private $canEditCandidates;
  75.     /**
  76.      * @ORM\Column(type="boolean", nullable=true)
  77.      */
  78.     private $canViewCampaigns;
  79.     /**
  80.      * @ORM\Column(type="boolean", nullable=true)
  81.      */
  82.     private $canViewPaymentRequisites;
  83.     /**
  84.      * @ORM\Column(type="boolean", nullable=true)
  85.      */
  86.     private $canSendCampaigns;
  87.     /**
  88.      * @ORM\Column(type="boolean", nullable=true)
  89.      */
  90.     private $canUseTestFeatures;
  91.     /**
  92.      * @ORM\Column(type="boolean", nullable=true)
  93.      */
  94.     private $canRemovePayments;
  95.     /**
  96.      * @ORM\Column(type="boolean", nullable=true)
  97.      */
  98.     private $canCompareTable;
  99.     /**
  100.      * @ORM\Column(type="boolean", nullable=true)
  101.      */
  102.     private $canEditCandidateAccessByReceipt;
  103.     /**
  104.      * @ORM\Column(type="boolean", nullable=true)
  105.      */
  106.     private $canEditAllCandidateParams;
  107.     /**
  108.      * @ORM\Column(type="boolean", nullable=true)
  109.      */
  110.     private $isCurator;
  111.     /**
  112.      * @ORM\Column(type="boolean", nullable=true)
  113.      */
  114.     private $canViewDelayedMessages;
  115.     /**
  116.      * @ORM\Column(type="boolean", nullable=true)
  117.      */
  118.     private $canViewCallLists;
  119.     /**
  120.      * @ORM\Column(type="boolean", nullable=true)
  121.      */
  122.     private $canEditCallLists;
  123.     /**
  124.      * @ORM\Column(type="boolean", nullable=true)
  125.      */
  126.     private $canRegisterForCalendarEvents;
  127.     /**
  128.      * @ORM\Column(type="boolean", nullable=true)
  129.      */
  130.     private $canViewInnerPayments;
  131.     /**
  132.      * @ORM\Column(type="boolean", nullable=true)
  133.      */
  134.     private $canEditInnerPayments;
  135.     /**
  136.      * @ORM\Column(type="boolean", nullable=true)
  137.      */
  138.     private $canViewCities;
  139.     /**
  140.      * @ORM\Column(type="boolean", nullable=true)
  141.      */
  142.     private $canEditCities;
  143.     /**
  144.      * @ORM\Column(type="boolean", nullable=true)
  145.      */
  146.     private $canViewEntityLog;
  147.     /**
  148.      * @ORM\Column(type="boolean", nullable=true)
  149.      */
  150.     private $canViewPersonsBalance;
  151.     /**
  152.      * @ORM\Column(type="boolean", nullable=true)
  153.      */
  154.     private $canViewFinanceCategories;
  155.     /**
  156.      * @ORM\Column(type="boolean", nullable=true)
  157.      */
  158.     private $canEditFinanceCategories;
  159.     /**
  160.      * @ORM\Column(type="boolean", nullable=true)
  161.      */
  162.     private $canViewInvoices;
  163.     /**
  164.      * @ORM\Column(type="boolean", nullable=true)
  165.      */
  166.     private $canViewTransactions;
  167.     /**
  168.      * @ORM\Column(type="boolean", nullable=true)
  169.      */
  170.     private $canViewJobs;
  171.     /**
  172.      * @ORM\Column(type="boolean", nullable=true)
  173.      */
  174.     private $canEditAppSettings;
  175.     /**
  176.      * @ORM\Column(type="datetime", nullable=true)
  177.      */
  178.     private $startCalendarEventsDate;
  179.     /**
  180.      * @ORM\Column(type="datetime", nullable=true)
  181.      */
  182.     private $endCalendarEventsDate;
  183.     /**
  184.      * @ORM\Column(type="string", length=100, nullable=true)
  185.      */
  186.     private $calendarEventsDateRangeName;
  187.     /**
  188.      * @ORM\Column(type="boolean", nullable=true)
  189.      */
  190.     private $canManageCommands;
  191.     public function __construct()
  192.     {
  193.         $this->startCalendarEventsDate = $this->getInitStartDate();
  194.         $this->endCalendarEventsDate = $this->getInitEndDate();
  195.     }
  196.     private function getInitStartDate(): \DateTimeInterface
  197.     {
  198.         return (new \DateTime())->modify("-1 month first day of this month");
  199.     }
  200.     private function getInitEndDate(): \DateTimeInterface
  201.     {
  202.         return (new \DateTime())->modify("+6 month last day of this month");
  203.     }
  204.     public function getId(): ?int
  205.     {
  206.         return $this->id;
  207.     }
  208.     public function isCanEditCalendarEvents(): ?bool
  209.     {
  210.         return $this->canEditCalendarEvents;
  211.     }
  212.     public function setCanEditCalendarEvents(?bool $canEditCalendarEvents): self
  213.     {
  214.         $this->canEditCalendarEvents = $canEditCalendarEvents;
  215.         return $this;
  216.     }
  217.     public function isCanEditStudents(): ?bool
  218.     {
  219.         return $this->canEditStudents;
  220.     }
  221.     public function setCanEditStudents(?bool $canEditStudents): self
  222.     {
  223.         $this->canEditStudents = $canEditStudents;
  224.         return $this;
  225.     }
  226.     public function isCanViewCandidates(): ?bool
  227.     {
  228.         return $this->canViewCandidates;
  229.     }
  230.     public function setCanViewCandidates(?bool $canViewCandidates): self
  231.     {
  232.         $this->canViewCandidates = $canViewCandidates;
  233.         return $this;
  234.     }
  235.     public function isCanEditPayments(): ?bool
  236.     {
  237.         return $this->canEditPayments;
  238.     }
  239.     public function setCanEditPayments(?bool $canEditPayments): self
  240.     {
  241.         $this->canEditPayments = $canEditPayments;
  242.         return $this;
  243.     }
  244.     public function isCanReviewCandidates(): ?bool
  245.     {
  246.         return $this->canReviewCandidates;
  247.     }
  248.     public function setCanReviewCandidates(?bool $canReviewCandidates): self
  249.     {
  250.         $this->canReviewCandidates = $canReviewCandidates;
  251.         return $this;
  252.     }
  253.     public function isCanViewStudents(): ?bool
  254.     {
  255.         return $this->canViewStudents;
  256.     }
  257.     public function setCanViewStudents(?bool $canViewStudents): self
  258.     {
  259.         $this->canViewStudents = $canViewStudents;
  260.         return $this;
  261.     }
  262.     public function isCanViewCalendarEvents(): ?bool
  263.     {
  264.         return $this->canViewCalendarEvents;
  265.     }
  266.     public function setCanViewCalendarEvents(?bool $canViewCalendarEvents): self
  267.     {
  268.         $this->canViewCalendarEvents = $canViewCalendarEvents;
  269.         return $this;
  270.     }
  271.     public function isCanViewCalendarEventKinds(): ?bool
  272.     {
  273.         return $this->canViewCalendarEventKinds;
  274.     }
  275.     public function setCanViewCalendarEventKinds(?bool $canViewCalendarEventKinds): self
  276.     {
  277.         $this->canViewCalendarEventKinds = $canViewCalendarEventKinds;
  278.         return $this;
  279.     }
  280.     public function isCanEditCalendarEventKinds(): ?bool
  281.     {
  282.         return $this->canEditCalendarEventKinds;
  283.     }
  284.     public function setCanEditCalendarEventKinds(?bool $canEditCalendarEventKinds): self
  285.     {
  286.         $this->canEditCalendarEventKinds = $canEditCalendarEventKinds;
  287.         return $this;
  288.     }
  289.     public function isCanViewZoomReport(): ?bool
  290.     {
  291.         return $this->canViewZoomReport;
  292.     }
  293.     public function setCanViewZoomReport(?bool $canViewZoomReport): self
  294.     {
  295.         $this->canViewZoomReport = $canViewZoomReport;
  296.         return $this;
  297.     }
  298.     public function isCanViewPaymentsReport(): ?bool
  299.     {
  300.         return $this->canViewPaymentsReport;
  301.     }
  302.     public function setCanViewPaymentsReport(?bool $canViewPaymentsReport): self
  303.     {
  304.         $this->canViewPaymentsReport = $canViewPaymentsReport;
  305.         return $this;
  306.     }
  307.     public function isCanViewStudentsPersonalData(): ?bool
  308.     {
  309.         return $this->canViewStudentsPersonalData;
  310.     }
  311.     public function setCanViewStudentsPersonalData(?bool $canViewStudentsPersonalData): self
  312.     {
  313.         $this->canViewStudentsPersonalData = $canViewStudentsPersonalData;
  314.         return $this;
  315.     }
  316.     public function isCanViewPayments(): ?bool
  317.     {
  318.         return $this->canViewPayments;
  319.     }
  320.     public function setCanViewPayments(?bool $canViewPayments): self
  321.     {
  322.         $this->canViewPayments = $canViewPayments;
  323.         return $this;
  324.     }
  325.     public function setPermission(string $key, bool $value): self
  326.     {
  327.         $this->$key = $value;
  328.         return $this;
  329.     }
  330.     public function getPermission(string $key): bool
  331.     {
  332.         return $this->$key ?? false;
  333.     }
  334.     public function getAllPermissionsGrouped(array $options = null): array
  335.     {
  336.         $options = array_merge([
  337.             'grantedOnly' => false,
  338.         ], $options ?? []);
  339.         $data = [];
  340.         foreach (PermissionGroup::getAsArray() as $group) {
  341.             $data[$group] = [
  342.                 "text" => PermissionGroup::getText($group),
  343.                 "permissions" => [],
  344.             ];
  345.             foreach (Permission::getAsArray() as $permission) {
  346.                 if (PermissionGroup::getGroup($permission) === $group) {
  347.                     if ($options['grantedOnly'] && !$this->getPermission($permission)) {
  348.                         continue;
  349.                     }
  350.                     $data[$group]["permissions"][$permission] = [
  351.                         "text" => Permission::getText($permission),
  352.                         "value" => $this->getPermission($permission),
  353.                         "shortText" => Permission::getShortText($permission),
  354.                     ];
  355.                 }
  356.             }
  357.         }
  358.         return $data;
  359.     }
  360.     public function isCanEditCandidates(): ?bool
  361.     {
  362.         return $this->canEditCandidates;
  363.     }
  364.     public function setCanEditCandidates(?bool $canEditCandidates): self
  365.     {
  366.         $this->canEditCandidates = $canEditCandidates;
  367.         return $this;
  368.     }
  369.     public function isCanViewCampaigns(): ?bool
  370.     {
  371.         return $this->canViewCampaigns;
  372.     }
  373.     public function setCanViewCampaigns(?bool $canViewCampaigns): self
  374.     {
  375.         $this->canViewCampaigns = $canViewCampaigns;
  376.         return $this;
  377.     }
  378.     public function isCanViewPaymentRequisites(): ?bool
  379.     {
  380.         return $this->canViewPaymentRequisites;
  381.     }
  382.     public function setCanViewPaymentRequisites(?bool $canViewPaymentRequisites): self
  383.     {
  384.         $this->canViewPaymentRequisites = $canViewPaymentRequisites;
  385.         return $this;
  386.     }
  387.     public function isCanSendCampaigns(): ?bool
  388.     {
  389.         return $this->canSendCampaigns;
  390.     }
  391.     public function setCanSendCampaigns(?bool $canSendCampaigns): self
  392.     {
  393.         $this->canSendCampaigns = $canSendCampaigns;
  394.         return $this;
  395.     }
  396.     public function isCanUseTestFeatures(): ?bool
  397.     {
  398.         return $this->canUseTestFeatures;
  399.     }
  400.     public function setCanUseTestFeatures(?bool $canUseTestFeatures): self
  401.     {
  402.         $this->canUseTestFeatures = $canUseTestFeatures;
  403.         return $this;
  404.     }
  405.     public function isCanRemovePayments(): ?bool
  406.     {
  407.         return $this->canRemovePayments;
  408.     }
  409.     public function setCanRemovePayments(?bool $canRemovePayments): self
  410.     {
  411.         $this->canRemovePayments = $canRemovePayments;
  412.         return $this;
  413.     }
  414.     public function isCanCompareTable(): ?bool
  415.     {
  416.         return $this->canCompareTable;
  417.     }
  418.     public function setCanCompareTable(?bool $canCompareTable): self
  419.     {
  420.         $this->canCompareTable = $canCompareTable;
  421.         return $this;
  422.     }
  423.     public function isCanEditCandidateAccessByReceipt(): ?bool
  424.     {
  425.         return $this->isCanEditAllCandidateParams() || $this->canEditCandidateAccessByReceipt;
  426.     }
  427.     public function setCanEditCandidateAccessByReceipt(?bool $canEditCandidateAccessByReceipt): self
  428.     {
  429.         $this->canEditCandidateAccessByReceipt = $canEditCandidateAccessByReceipt;
  430.         return $this;
  431.     }
  432.     public function isCanEditAllCandidateParams(): ?bool
  433.     {
  434.         return $this->canEditAllCandidateParams;
  435.     }
  436.     public function setCanEditAllCandidateParams(?bool $canEditAllCandidateParams): self
  437.     {
  438.         $this->canEditAllCandidateParams = $canEditAllCandidateParams;
  439.         return $this;
  440.     }
  441.     public function isIsCurator(): ?bool
  442.     {
  443.         return $this->isCurator;
  444.     }
  445.     public function setIsCurator(?bool $isCurator): self
  446.     {
  447.         $this->isCurator = $isCurator;
  448.         return $this;
  449.     }
  450.     public function isCanViewDelayedMessages(): ?bool
  451.     {
  452.         return $this->canViewDelayedMessages;
  453.     }
  454.     public function setCanViewDelayedMessages(?bool $canViewDelayedMessages): self
  455.     {
  456.         $this->canViewDelayedMessages = $canViewDelayedMessages;
  457.         return $this;
  458.     }
  459.     public function isCanViewCallLists(): ?bool
  460.     {
  461.         return $this->canViewCallLists;
  462.     }
  463.     public function setCanViewCallLists(?bool $canViewCallLists): self
  464.     {
  465.         $this->canViewCallLists = $canViewCallLists;
  466.         return $this;
  467.     }
  468.     public function isCanEditCallLists(): ?bool
  469.     {
  470.         return $this->canEditCallLists;
  471.     }
  472.     public function setCanEditCallLists(?bool $canEditCallLists): self
  473.     {
  474.         $this->canEditCallLists = $canEditCallLists;
  475.         return $this;
  476.     }
  477.     public function isCanRegisterForCalendarEvents(): ?bool
  478.     {
  479.         return $this->canRegisterForCalendarEvents;
  480.     }
  481.     public function setCanRegisterForCalendarEvents(?bool $canRegisterForCalendarEvents): self
  482.     {
  483.         $this->canRegisterForCalendarEvents = $canRegisterForCalendarEvents;
  484.         return $this;
  485.     }
  486.     public function isCanViewInnerPayments(): ?bool
  487.     {
  488.         return $this->canViewInnerPayments;
  489.     }
  490.     public function setCanViewInnerPayments(?bool $canViewInnerPayments): self
  491.     {
  492.         $this->canViewInnerPayments = $canViewInnerPayments;
  493.         return $this;
  494.     }
  495.     public function isCanEditInnerPayments(): ?bool
  496.     {
  497.         return $this->canEditInnerPayments;
  498.     }
  499.     public function setCanEditInnerPayments(?bool $canEditInnerPayments): self
  500.     {
  501.         $this->canEditInnerPayments = $canEditInnerPayments;
  502.         return $this;
  503.     }
  504.     public function isCanViewCities(): ?bool
  505.     {
  506.         return $this->canViewCities;
  507.     }
  508.     public function setCanViewCities(?bool $canViewCities): self
  509.     {
  510.         $this->canViewCities = $canViewCities;
  511.         return $this;
  512.     }
  513.     public function isCanEditCities(): ?bool
  514.     {
  515.         return $this->canEditCities;
  516.     }
  517.     public function setCanEditCities(?bool $canEditCities): self
  518.     {
  519.         $this->canEditCities = $canEditCities;
  520.         return $this;
  521.     }
  522.     public function isCanViewEntityLog(): ?bool
  523.     {
  524.         return $this->canViewEntityLog;
  525.     }
  526.     public function setCanViewEntityLog(?bool $canViewEntityLog): self
  527.     {
  528.         $this->canViewEntityLog = $canViewEntityLog;
  529.         return $this;
  530.     }
  531.     public function isCanViewPersonsBalance(): ?bool
  532.     {
  533.         return $this->canViewPersonsBalance;
  534.     }
  535.     public function setCanViewPersonsBalance(?bool $canViewPersonsBalance): self
  536.     {
  537.         $this->canViewPersonsBalance = $canViewPersonsBalance;
  538.         return $this;
  539.     }
  540.     public function isCanViewFinanceCategories(): ?bool
  541.     {
  542.         return $this->canViewFinanceCategories;
  543.     }
  544.     public function setCanViewFinanceCategories(?bool $canViewFinanceCategories): self
  545.     {
  546.         $this->canViewFinanceCategories = $canViewFinanceCategories;
  547.         return $this;
  548.     }
  549.     public function isCanEditFinanceCategories(): ?bool
  550.     {
  551.         return $this->canEditFinanceCategories;
  552.     }
  553.     public function setCanEditFinanceCategories(?bool $canEditFinanceCategories): self
  554.     {
  555.         $this->canEditFinanceCategories = $canEditFinanceCategories;
  556.         return $this;
  557.     }
  558.     public function isCanViewInvoices(): ?bool
  559.     {
  560.         return $this->canViewInvoices;
  561.     }
  562.     public function setCanViewInvoices(?bool $canViewInvoices): self
  563.     {
  564.         $this->canViewInvoices = $canViewInvoices;
  565.         return $this;
  566.     }
  567.     public function isCanViewTransactions(): ?bool
  568.     {
  569.         return $this->canViewTransactions;
  570.     }
  571.     public function setCanViewTransactions(?bool $canViewTransactions): self
  572.     {
  573.         $this->canViewTransactions = $canViewTransactions;
  574.         return $this;
  575.     }
  576.     public function isCanViewJobs(): ?bool
  577.     {
  578.         return $this->canViewJobs;
  579.     }
  580.     public function setCanViewJobs(?bool $canViewJobs): self
  581.     {
  582.         $this->canViewJobs = $canViewJobs;
  583.         return $this;
  584.     }
  585.     public function isCanEditAppSettings(): ?bool
  586.     {
  587.         return $this->canEditAppSettings;
  588.     }
  589.     public function setCanEditAppSettings(?bool $canEditAppSettings): self
  590.     {
  591.         $this->canEditAppSettings = $canEditAppSettings;
  592.         return $this;
  593.     }
  594.     public function canViewRegistries(): bool
  595.     {
  596.         return $this->isCanViewCalendarEventKinds() || $this->isCanEditCalendarEventKinds()
  597.             || $this->isCanViewStudents() || $this->isCanEditStudents()
  598.             || $this->isCanViewCandidates() || $this->isCanEditCandidates()
  599.             || $this->isCanViewCities() || $this->isCanEditCities();
  600.     }
  601.     public function getStartCalendarEventsDate(): ?\DateTimeInterface
  602.     {
  603.         if ($this->getCalendarEventsDateRangeName()) {
  604.             return DateUtils::getDateRangeByRangeName($this->getCalendarEventsDateRangeName())[0];
  605.         }
  606.         if (!$this->startCalendarEventsDate ||
  607.             $this->startCalendarEventsDate < new \DateTime("01.01.1999")) {
  608.             $this->startCalendarEventsDate = $this->getInitStartDate();
  609.         }
  610.         return $this->startCalendarEventsDate;
  611.     }
  612.     public function setStartCalendarEventsDate(?\DateTimeInterface $startCalendarEventsDate): self
  613.     {
  614.         $this->startCalendarEventsDate = $startCalendarEventsDate;
  615.         return $this;
  616.     }
  617.     public function getEndCalendarEventsDate(): ?\DateTimeInterface
  618.     {
  619.         if ($this->getCalendarEventsDateRangeName()) {
  620.             return DateUtils::getDateRangeByRangeName($this->getCalendarEventsDateRangeName())[1];
  621.         }
  622.         if (!$this->endCalendarEventsDate ||
  623.             $this->endCalendarEventsDate < new \DateTime("01.01.1999")) {
  624.             $this->endCalendarEventsDate = $this->getInitEndDate();
  625.         }
  626.         return $this->endCalendarEventsDate;
  627.     }
  628.     public function setEndCalendarEventsDate(?\DateTimeInterface $endCalendarEventsDate): self
  629.     {
  630.         $this->endCalendarEventsDate = $endCalendarEventsDate;
  631.         return $this;
  632.     }
  633.     public function getCalendarEventsDateRangeName(): ?string
  634.     {
  635.         return $this->calendarEventsDateRangeName;
  636.     }
  637.     public function setCalendarEventsDateRangeName(?string $calendarEventsDateRangeName): self
  638.     {
  639.         $this->calendarEventsDateRangeName = $calendarEventsDateRangeName;
  640.         return $this;
  641.     }
  642.     public static function getFieldText(string $fieldName): string
  643.     {
  644.         return Permission::getText($fieldName);
  645.     }
  646.     public function isCanManageCommands(): ?bool
  647.     {
  648.         return $this->canManageCommands;
  649.     }
  650.     public function setCanManageCommands(?bool $canManageCommands): self
  651.     {
  652.         $this->canManageCommands = $canManageCommands;
  653.         return $this;
  654.     }
  655. }