src/Entity/CalendarEventKind.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CalendarEventKindRepository;
  4. use App\Service\EntityService;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass=CalendarEventKindRepository::class)
  8.  */
  9. class CalendarEventKind
  10. {
  11.     /**
  12.      * @ORM\Id
  13.      * @ORM\GeneratedValue
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\Column(type="string", length=255)
  19.      */
  20.     private $name;
  21.     /**
  22.      * @var string|null
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $title;
  26.     /**
  27.      * @var int|null
  28.      * @ORM\Column(type="smallint", nullable=true)
  29.      */
  30.     private $fromLevel;
  31.     /**
  32.      * @var int|null
  33.      * @ORM\Column(type="smallint", nullable=true)
  34.      */
  35.     private $toLevel;
  36.     /**
  37.      * @var int|null
  38.      * @ORM\Column(type="smallint", nullable=true)
  39.      */
  40.     private $earnLevel;
  41.     /**
  42.      * @var string|null
  43.      * @ORM\Column(type="enum", options={"values"="calendar_event_kind_enum"})
  44.      */
  45.     private $calendarEventType;
  46.     /**
  47.      * @var bool|null
  48.      * @ORM\Column(type="boolean", nullable=true)
  49.      */
  50.     private $isCandidateReviewRequired;
  51.     /**
  52.      * @ORM\Column(type="datetime")
  53.      */
  54.     private $createdAt;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $nameRegex;
  59.     /**
  60.      * @ORM\Column(type="string", length=20, unique=true)
  61.      */
  62.     private $kindId;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=FinanceCategory::class)
  65.      * @ORM\JoinColumn(nullable=true)
  66.      */
  67.     private $financeCategory;
  68.     public function __construct()
  69.     {
  70.         $this->createdAt = new \DateTime();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getName(): ?string
  77.     {
  78.         return $this->name;
  79.     }
  80.     public function setName(string $name): self
  81.     {
  82.         $this->name $name;
  83.         return $this;
  84.     }
  85.     public function getCreatedAt(): ?\DateTimeInterface
  86.     {
  87.         return $this->createdAt;
  88.     }
  89.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  90.     {
  91.         $this->createdAt $createdAt;
  92.         return $this;
  93.     }
  94.     public function getNameRegex(): ?string
  95.     {
  96.         return $this->nameRegex;
  97.     }
  98.     public function getNameRegexWords(): array
  99.     {
  100.         if (!$this->getNameRegex()) {
  101.             return [];
  102.         }
  103.         $wordsStr $this->getNameRegex();
  104.         return preg_split("/, */"$wordsStr, -1PREG_SPLIT_NO_EMPTY);
  105.     }
  106.     public function getNameFullRegex(): ?string
  107.     {
  108.         static $nonLetterRegex "[^а-яА-ЯёЁ\s\-]";
  109.         if (!$this->getNameRegex()) {
  110.             return null;
  111.         }
  112.         $words $this->getNameRegexWords();
  113. //        $words = array_map(function ($word) use ($nonLetterRegex) {
  114. //            $word = preg_quote($word, "/");
  115. //            $word .= "($nonLetterRegex|$)";
  116. //            return $word;
  117. //        }, $words);
  118.         return "/" implode("|"$words) . "/iu";
  119.     }
  120.     public function setNameRegex(?string $nameRegex): self
  121.     {
  122.         $this->nameRegex $nameRegex;
  123.         return $this;
  124.     }
  125.     public function getKindId(): ?string
  126.     {
  127.         return $this->kindId;
  128.     }
  129.     public function setKindId(string $kindId): self
  130.     {
  131.         $this->kindId $kindId;
  132.         return $this;
  133.     }
  134.     public function getFinanceCategory(): ?FinanceCategory
  135.     {
  136.         return $this->financeCategory;
  137.     }
  138.     public function setFinanceCategory(?FinanceCategory $financeCategory): self
  139.     {
  140.         if ($this->getFinanceCategory()
  141.             && !EntityService::isSameEntity($this->getFinanceCategory(), $financeCategory)) {
  142.             //todo другое решение
  143.             //временное решение - создать другой вид мероприятия и использовать его
  144.             throw new \Exception("Нельзя изменить статью финансов вида мероприятия, т.к. "
  145.             "она может использоваться в связанных финансовых транзакциях. Обратитесь к администратору."
  146.             " Возможное решение: создайте новый вид мероприятия с нужной статьей финансов и используйте его.");
  147.         }
  148.         $this->financeCategory $financeCategory;
  149.         return $this;
  150.     }
  151.     public function getTitle(): ?string
  152.     {
  153.         return $this->title;
  154.     }
  155.     public function setTitle(?string $title): self
  156.     {
  157.         $this->title $title;
  158.         return $this;
  159.     }
  160.     public function getFromLevel(): ?int
  161.     {
  162.         return $this->fromLevel;
  163.     }
  164.     public function setFromLevel(?int $fromLevel): self
  165.     {
  166.         $this->fromLevel $fromLevel;
  167.         return $this;
  168.     }
  169.     public function getEarnLevel(): ?int
  170.     {
  171.         return $this->earnLevel;
  172.     }
  173.     public function setEarnLevel(?int $earnLevel): self
  174.     {
  175.         $this->earnLevel $earnLevel;
  176.         return $this;
  177.     }
  178.     public function getCalendarEventType(): ?string
  179.     {
  180.         return $this->calendarEventType;
  181.     }
  182.     public function setCalendarEventType(?string $calendarEventType): self
  183.     {
  184.         $this->calendarEventType $calendarEventType;
  185.         return $this;
  186.     }
  187.     public function getIsCandidateReviewRequired(): ?bool
  188.     {
  189.         return $this->isCandidateReviewRequired;
  190.     }
  191.     public function setIsCandidateReviewRequired(?bool $isCandidateReviewRequired): self
  192.     {
  193.         $this->isCandidateReviewRequired $isCandidateReviewRequired;
  194.         return $this;
  195.     }
  196.     public function getToLevel(): ?int
  197.     {
  198.         return $this->toLevel;
  199.     }
  200.     public function setToLevel(?int $toLevel): self
  201.     {
  202.         $this->toLevel $toLevel;
  203.         return $this;
  204.     }
  205. }