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