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