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="datetime", nullable=true)
  173.      */
  174.     private $startCalendarEventsDate;
  175.     /**
  176.      * @ORM\Column(type="datetime", nullable=true)
  177.      */
  178.     private $endCalendarEventsDate;
  179.     /**
  180.      * @ORM\Column(type="string", length=20, nullable=true)
  181.      */
  182.     private $calendarEventsDateRangeName;
  183.     public function __construct()
  184.     {
  185.         $this->startCalendarEventsDate $this->getInitStartDate();
  186.         $this->endCalendarEventsDate $this->getInitEndDate();
  187.     }
  188.     private function getInitStartDate(): \DateTimeInterface
  189.     {
  190.         return (new \DateTime())->modify("-1 month first day of this month");
  191.     }
  192.     private function getInitEndDate(): \DateTimeInterface
  193.     {
  194.         return (new \DateTime())->modify("+6 month last day of this month");
  195.     }
  196.     public function getId(): ?int
  197.     {
  198.         return $this->id;
  199.     }
  200.     public function isCanEditCalendarEvents(): ?bool
  201.     {
  202.         return $this->canEditCalendarEvents;
  203.     }
  204.     public function setCanEditCalendarEvents(?bool $canEditCalendarEvents): self
  205.     {
  206.         $this->canEditCalendarEvents $canEditCalendarEvents;
  207.         return $this;
  208.     }
  209.     public function isCanEditStudents(): ?bool
  210.     {
  211.         return $this->canEditStudents;
  212.     }
  213.     public function setCanEditStudents(?bool $canEditStudents): self
  214.     {
  215.         $this->canEditStudents $canEditStudents;
  216.         return $this;
  217.     }
  218.     public function isCanViewCandidates(): ?bool
  219.     {
  220.         return $this->canViewCandidates;
  221.     }
  222.     public function setCanViewCandidates(?bool $canViewCandidates): self
  223.     {
  224.         $this->canViewCandidates $canViewCandidates;
  225.         return $this;
  226.     }
  227.     public function isCanEditPayments(): ?bool
  228.     {
  229.         return $this->canEditPayments;
  230.     }
  231.     public function setCanEditPayments(?bool $canEditPayments): self
  232.     {
  233.         $this->canEditPayments $canEditPayments;
  234.         return $this;
  235.     }
  236.     public function isCanReviewCandidates(): ?bool
  237.     {
  238.         return $this->canReviewCandidates;
  239.     }
  240.     public function setCanReviewCandidates(?bool $canReviewCandidates): self
  241.     {
  242.         $this->canReviewCandidates $canReviewCandidates;
  243.         return $this;
  244.     }
  245.     public function isCanViewStudents(): ?bool
  246.     {
  247.         return $this->canViewStudents;
  248.     }
  249.     public function setCanViewStudents(?bool $canViewStudents): self
  250.     {
  251.         $this->canViewStudents $canViewStudents;
  252.         return $this;
  253.     }
  254.     public function isCanViewCalendarEvents(): ?bool
  255.     {
  256.         return $this->canViewCalendarEvents;
  257.     }
  258.     public function setCanViewCalendarEvents(?bool $canViewCalendarEvents): self
  259.     {
  260.         $this->canViewCalendarEvents $canViewCalendarEvents;
  261.         return $this;
  262.     }
  263.     public function isCanViewCalendarEventKinds(): ?bool
  264.     {
  265.         return $this->canViewCalendarEventKinds;
  266.     }
  267.     public function setCanViewCalendarEventKinds(?bool $canViewCalendarEventKinds): self
  268.     {
  269.         $this->canViewCalendarEventKinds $canViewCalendarEventKinds;
  270.         return $this;
  271.     }
  272.     public function isCanEditCalendarEventKinds(): ?bool
  273.     {
  274.         return $this->canEditCalendarEventKinds;
  275.     }
  276.     public function setCanEditCalendarEventKinds(?bool $canEditCalendarEventKinds): self
  277.     {
  278.         $this->canEditCalendarEventKinds $canEditCalendarEventKinds;
  279.         return $this;
  280.     }
  281.     public function isCanViewZoomReport(): ?bool
  282.     {
  283.         return $this->canViewZoomReport;
  284.     }
  285.     public function setCanViewZoomReport(?bool $canViewZoomReport): self
  286.     {
  287.         $this->canViewZoomReport $canViewZoomReport;
  288.         return $this;
  289.     }
  290.     public function isCanViewPaymentsReport(): ?bool
  291.     {
  292.         return $this->canViewPaymentsReport;
  293.     }
  294.     public function setCanViewPaymentsReport(?bool $canViewPaymentsReport): self
  295.     {
  296.         $this->canViewPaymentsReport $canViewPaymentsReport;
  297.         return $this;
  298.     }
  299.     public function isCanViewStudentsPersonalData(): ?bool
  300.     {
  301.         return $this->canViewStudentsPersonalData;
  302.     }
  303.     public function setCanViewStudentsPersonalData(?bool $canViewStudentsPersonalData): self
  304.     {
  305.         $this->canViewStudentsPersonalData $canViewStudentsPersonalData;
  306.         return $this;
  307.     }
  308.     public function isCanViewPayments(): ?bool
  309.     {
  310.         return $this->canViewPayments;
  311.     }
  312.     public function setCanViewPayments(?bool $canViewPayments): self
  313.     {
  314.         $this->canViewPayments $canViewPayments;
  315.         return $this;
  316.     }
  317.     public function setPermission(string $keybool $value): self
  318.     {
  319.         $this->$key $value;
  320.         return $this;
  321.     }
  322.     public function getPermission(string $key): bool
  323.     {
  324.         return $this->$key ?? false;
  325.     }
  326.     public function getAllPermissionsGrouped(array $options null): array
  327.     {
  328.         $options array_merge([
  329.             'grantedOnly' => false,
  330.         ], $options ?? []);
  331.         $data = [];
  332.         foreach (PermissionGroup::getAsArray() as $group) {
  333.             $data[$group] = [
  334.                 "text" => PermissionGroup::getText($group),
  335.                 "permissions" => [],
  336.             ];
  337.             foreach (Permission::getAsArray() as $permission) {
  338.                 if (PermissionGroup::getGroup($permission) === $group) {
  339.                     if ($options['grantedOnly'] && !$this->getPermission($permission)) {
  340.                         continue;
  341.                     }
  342.                     $data[$group]["permissions"][$permission] = [
  343.                         "text" => Permission::getText($permission),
  344.                         "value" => $this->getPermission($permission),
  345.                         "shortText" => Permission::getShortText($permission),
  346.                     ];
  347.                 }
  348.             }
  349.         }
  350.         return $data;
  351.     }
  352.     public function isCanEditCandidates(): ?bool
  353.     {
  354.         return $this->canEditCandidates;
  355.     }
  356.     public function setCanEditCandidates(?bool $canEditCandidates): self
  357.     {
  358.         $this->canEditCandidates $canEditCandidates;
  359.         return $this;
  360.     }
  361.     public function isCanViewCampaigns(): ?bool
  362.     {
  363.         return $this->canViewCampaigns;
  364.     }
  365.     public function setCanViewCampaigns(?bool $canViewCampaigns): self
  366.     {
  367.         $this->canViewCampaigns $canViewCampaigns;
  368.         return $this;
  369.     }
  370.     public function isCanViewPaymentRequisites(): ?bool
  371.     {
  372.         return $this->canViewPaymentRequisites;
  373.     }
  374.     public function setCanViewPaymentRequisites(?bool $canViewPaymentRequisites): self
  375.     {
  376.         $this->canViewPaymentRequisites $canViewPaymentRequisites;
  377.         return $this;
  378.     }
  379.     public function isCanSendCampaigns(): ?bool
  380.     {
  381.         return $this->canSendCampaigns;
  382.     }
  383.     public function setCanSendCampaigns(?bool $canSendCampaigns): self
  384.     {
  385.         $this->canSendCampaigns $canSendCampaigns;
  386.         return $this;
  387.     }
  388.     public function isCanUseTestFeatures(): ?bool
  389.     {
  390.         return $this->canUseTestFeatures;
  391.     }
  392.     public function setCanUseTestFeatures(?bool $canUseTestFeatures): self
  393.     {
  394.         $this->canUseTestFeatures $canUseTestFeatures;
  395.         return $this;
  396.     }
  397.     public function isCanRemovePayments(): ?bool
  398.     {
  399.         return $this->canRemovePayments;
  400.     }
  401.     public function setCanRemovePayments(?bool $canRemovePayments): self
  402.     {
  403.         $this->canRemovePayments $canRemovePayments;
  404.         return $this;
  405.     }
  406.     public function isCanCompareTable(): ?bool
  407.     {
  408.         return $this->canCompareTable;
  409.     }
  410.     public function setCanCompareTable(?bool $canCompareTable): self
  411.     {
  412.         $this->canCompareTable $canCompareTable;
  413.         return $this;
  414.     }
  415.     public function isCanEditCandidateAccessByReceipt(): ?bool
  416.     {
  417.         return $this->isCanEditAllCandidateParams() || $this->canEditCandidateAccessByReceipt;
  418.     }
  419.     public function setCanEditCandidateAccessByReceipt(?bool $canEditCandidateAccessByReceipt): self
  420.     {
  421.         $this->canEditCandidateAccessByReceipt $canEditCandidateAccessByReceipt;
  422.         return $this;
  423.     }
  424.     public function isCanEditAllCandidateParams(): ?bool
  425.     {
  426.         return $this->canEditAllCandidateParams;
  427.     }
  428.     public function setCanEditAllCandidateParams(?bool $canEditAllCandidateParams): self
  429.     {
  430.         $this->canEditAllCandidateParams $canEditAllCandidateParams;
  431.         return $this;
  432.     }
  433.     public function isIsCurator(): ?bool
  434.     {
  435.         return $this->isCurator;
  436.     }
  437.     public function setIsCurator(?bool $isCurator): self
  438.     {
  439.         $this->isCurator $isCurator;
  440.         return $this;
  441.     }
  442.     public function isCanViewDelayedMessages(): ?bool
  443.     {
  444.         return $this->canViewDelayedMessages;
  445.     }
  446.     public function setCanViewDelayedMessages(?bool $canViewDelayedMessages): self
  447.     {
  448.         $this->canViewDelayedMessages $canViewDelayedMessages;
  449.         return $this;
  450.     }
  451.     public function isCanViewCallLists(): ?bool
  452.     {
  453.         return $this->canViewCallLists;
  454.     }
  455.     public function setCanViewCallLists(?bool $canViewCallLists): self
  456.     {
  457.         $this->canViewCallLists $canViewCallLists;
  458.         return $this;
  459.     }
  460.     public function isCanEditCallLists(): ?bool
  461.     {
  462.         return $this->canEditCallLists;
  463.     }
  464.     public function setCanEditCallLists(?bool $canEditCallLists): self
  465.     {
  466.         $this->canEditCallLists $canEditCallLists;
  467.         return $this;
  468.     }
  469.     public function isCanRegisterForCalendarEvents(): ?bool
  470.     {
  471.         return $this->canRegisterForCalendarEvents;
  472.     }
  473.     public function setCanRegisterForCalendarEvents(?bool $canRegisterForCalendarEvents): self
  474.     {
  475.         $this->canRegisterForCalendarEvents $canRegisterForCalendarEvents;
  476.         return $this;
  477.     }
  478.     public function isCanViewInnerPayments(): ?bool
  479.     {
  480.         return $this->canViewInnerPayments;
  481.     }
  482.     public function setCanViewInnerPayments(?bool $canViewInnerPayments): self
  483.     {
  484.         $this->canViewInnerPayments $canViewInnerPayments;
  485.         return $this;
  486.     }
  487.     public function isCanEditInnerPayments(): ?bool
  488.     {
  489.         return $this->canEditInnerPayments;
  490.     }
  491.     public function setCanEditInnerPayments(?bool $canEditInnerPayments): self
  492.     {
  493.         $this->canEditInnerPayments $canEditInnerPayments;
  494.         return $this;
  495.     }
  496.     public function isCanViewCities(): ?bool
  497.     {
  498.         return $this->canViewCities;
  499.     }
  500.     public function setCanViewCities(?bool $canViewCities): self
  501.     {
  502.         $this->canViewCities $canViewCities;
  503.         return $this;
  504.     }
  505.     public function isCanEditCities(): ?bool
  506.     {
  507.         return $this->canEditCities;
  508.     }
  509.     public function setCanEditCities(?bool $canEditCities): self
  510.     {
  511.         $this->canEditCities $canEditCities;
  512.         return $this;
  513.     }
  514.     public function isCanViewEntityLog(): ?bool
  515.     {
  516.         return $this->canViewEntityLog;
  517.     }
  518.     public function setCanViewEntityLog(?bool $canViewEntityLog): self
  519.     {
  520.         $this->canViewEntityLog $canViewEntityLog;
  521.         return $this;
  522.     }
  523.     public function isCanViewPersonsBalance(): ?bool
  524.     {
  525.         return $this->canViewPersonsBalance;
  526.     }
  527.     public function setCanViewPersonsBalance(?bool $canViewPersonsBalance): self
  528.     {
  529.         $this->canViewPersonsBalance $canViewPersonsBalance;
  530.         return $this;
  531.     }
  532.     public function isCanViewFinanceCategories(): ?bool
  533.     {
  534.         return $this->canViewFinanceCategories;
  535.     }
  536.     public function setCanViewFinanceCategories(?bool $canViewFinanceCategories): self
  537.     {
  538.         $this->canViewFinanceCategories $canViewFinanceCategories;
  539.         return $this;
  540.     }
  541.     public function isCanEditFinanceCategories(): ?bool
  542.     {
  543.         return $this->canEditFinanceCategories;
  544.     }
  545.     public function setCanEditFinanceCategories(?bool $canEditFinanceCategories): self
  546.     {
  547.         $this->canEditFinanceCategories $canEditFinanceCategories;
  548.         return $this;
  549.     }
  550.     public function isCanViewInvoices(): ?bool
  551.     {
  552.         return $this->canViewInvoices;
  553.     }
  554.     public function setCanViewInvoices(?bool $canViewInvoices): self
  555.     {
  556.         $this->canViewInvoices $canViewInvoices;
  557.         return $this;
  558.     }
  559.     public function isCanViewTransactions(): ?bool
  560.     {
  561.         return $this->canViewTransactions;
  562.     }
  563.     public function setCanViewTransactions(?bool $canViewTransactions): self
  564.     {
  565.         $this->canViewTransactions $canViewTransactions;
  566.         return $this;
  567.     }
  568.     public function isCanViewJobs(): ?bool
  569.     {
  570.         return $this->canViewJobs;
  571.     }
  572.     public function setCanViewJobs(?bool $canViewJobs): self
  573.     {
  574.         $this->canViewJobs $canViewJobs;
  575.         return $this;
  576.     }
  577.     public function canViewRegistries(): bool
  578.     {
  579.         return $this->isCanViewCalendarEventKinds() || $this->isCanEditCalendarEventKinds()
  580.             || $this->isCanViewStudents() || $this->isCanEditStudents()
  581.             || $this->isCanViewCandidates() || $this->isCanEditCandidates()
  582.             || $this->isCanViewCities() || $this->isCanEditCities();
  583.     }
  584.     public function getStartCalendarEventsDate(): ?\DateTimeInterface
  585.     {
  586.         if ($this->getCalendarEventsDateRangeName()) {
  587.             return DateUtils::getDateRangeByRangeName($this->getCalendarEventsDateRangeName())[0];
  588.         }
  589.         if (!$this->startCalendarEventsDate ||
  590.             $this->startCalendarEventsDate < new \DateTime("01.01.1999")) {
  591.             $this->startCalendarEventsDate $this->getInitStartDate();
  592.         }
  593.         return $this->startCalendarEventsDate;
  594.     }
  595.     public function setStartCalendarEventsDate(?\DateTimeInterface $startCalendarEventsDate): self
  596.     {
  597.         $this->startCalendarEventsDate $startCalendarEventsDate;
  598.         return $this;
  599.     }
  600.     public function getEndCalendarEventsDate(): ?\DateTimeInterface
  601.     {
  602.         if ($this->getCalendarEventsDateRangeName()) {
  603.             return DateUtils::getDateRangeByRangeName($this->getCalendarEventsDateRangeName())[1];
  604.         }
  605.         if (!$this->endCalendarEventsDate ||
  606.             $this->endCalendarEventsDate < new \DateTime("01.01.1999")) {
  607.             $this->endCalendarEventsDate $this->getInitEndDate();
  608.         }
  609.         return $this->endCalendarEventsDate;
  610.     }
  611.     public function setEndCalendarEventsDate(?\DateTimeInterface $endCalendarEventsDate): self
  612.     {
  613.         $this->endCalendarEventsDate $endCalendarEventsDate;
  614.         return $this;
  615.     }
  616.     public function getCalendarEventsDateRangeName(): ?string
  617.     {
  618.         return $this->calendarEventsDateRangeName;
  619.     }
  620.     public function setCalendarEventsDateRangeName(?string $calendarEventsDateRangeName): self
  621.     {
  622.         $this->calendarEventsDateRangeName $calendarEventsDateRangeName;
  623.         return $this;
  624.     }
  625.     public static function getFieldText(string $fieldName): string
  626.     {
  627.         return Permission::getText($fieldName);
  628.     }
  629. }