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