src/Entity/CalendarEventKind.php line 13

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