src/Entity/Person.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\Student\Status;
  4. use App\Enum\Student\VirtualStatus;
  5. use App\Library\Utils\Other\Other;
  6. use App\Repository\PersonRepository;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=PersonRepository::class)
  10.  */
  11. class Person
  12. {
  13.     const PERSON_FIELD_NAME 'person_name';
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $firstName;
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $lastName;
  28.     /**
  29.      * @ORM\OneToOne(targetEntity=Student::class, inversedBy="person", cascade={"persist", "remove"})
  30.      */
  31.     private $student;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=City::class)
  34.      */
  35.     private $city;
  36.     /**
  37.      * @ORM\Column(type="string", length=255, nullable=true)
  38.      */
  39.     private $phone;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private $email;
  44.     /**
  45.      * @ORM\OneToOne(targetEntity=Image::class, cascade={"persist", "remove"})
  46.      */
  47.     private $image;
  48.     /**
  49.      * @ORM\Column(type="text", nullable=true)
  50.      */
  51.     private $comment;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     private $lastName2;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $telegramUserId;
  60.     /**
  61.      * @ORM\Column(type="boolean", nullable=true, options={"default"=true})
  62.      */
  63.     private $canSendTelegramCampaigns true;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity=Person::class)
  66.      */
  67.     private $messageReceiver;
  68.     /**
  69.      * @ORM\Column(type="boolean", nullable=true)
  70.      */
  71.     private $isStudent;
  72.     /**
  73.      * @ORM\Column(type="boolean", nullable=true)
  74.      */
  75.     private $isSubscriber;
  76.     private $virtualStudentStatus VirtualStatus::VIRTUAL_STATUS_SUBSCRIBER;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $surname;
  81.     /**
  82.      * @ORM\Column(type="datetime")
  83.      */
  84.     private $createdAt;
  85.     public function __construct()
  86.     {
  87.         $this->createdAt = new \DateTime();
  88.     }
  89.     public function getId(): ?int
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function getFirstName(): ?string
  94.     {
  95.         return $this->firstName;
  96.     }
  97.     public function setFirstName(string $firstName): self
  98.     {
  99.         $this->firstName $firstName;
  100.         return $this;
  101.     }
  102.     public function getLastName(): ?string
  103.     {
  104.         return $this->lastName;
  105.     }
  106.     public function setLastName(string $lastName): self
  107.     {
  108.         $this->lastName $lastName;
  109.         return $this;
  110.     }
  111.     public function getStudent(): ?Student
  112.     {
  113.         return $this->student;
  114.     }
  115.     public function setStudent(?Student $student): self
  116.     {
  117.         $this->student $student;
  118.         return $this;
  119.     }
  120.     public function getName(array $options null): string
  121.     {
  122.         $options array_merge(
  123.             [
  124.                 "lastNameFirst" => false
  125.             ], ($options ?? [])
  126.         );
  127.         $name = ($options["lastNameFirst"] ? $this->getLastFirstName() : $this->firstName ' ' $this->lastName );
  128.         return $name;
  129.     }
  130.     public function isSameName($name): bool
  131.     {
  132.         $nameParts explode(' '$name);
  133.         if (count($nameParts) === 2) {
  134.             $firstName $nameParts[0];
  135.             $lastName $nameParts[1];
  136.             $firstName mb_strtolower($firstName'UTF-8');
  137.             $lastName mb_strtolower($lastName'UTF-8');
  138.             $currentFirstName mb_strtolower($this->firstName'UTF-8');
  139.             $currentLastName mb_strtolower($this->lastName'UTF-8');
  140.             return ($firstName == $currentFirstName && $lastName == $currentLastName)
  141.                 || ($firstName == $currentLastName && $lastName == $currentFirstName);
  142.         } else {
  143.             return false;
  144.         }
  145.     }
  146.     public function getLastFirstName(): string
  147.     {
  148.         return $this->lastName ' ' $this->firstName;
  149.     }
  150.     public function getLastName2FirstName(): string
  151.     {
  152.         return $this->lastName2 ' ' $this->firstName;
  153.     }
  154.     public function getNameAndCityText(): string
  155.     {
  156.         return $this->getName() . " (" .
  157.             ($this->getCity() && trim($this->getCity()->getName()) ? $this->getCity()->getName() : "город не указан")
  158.             . ")";
  159.     }
  160.     public function getCityText(): string
  161.     {
  162.         return $this->getCity() ? $this->getCity()->getName() : "город не указан";
  163.     }
  164.     public function getCity(): ?City
  165.     {
  166.         return $this->city;
  167.     }
  168.     public function setCity(?City $city): self
  169.     {
  170.         $this->city $city;
  171.         return $this;
  172.     }
  173.     public function getPhone(): ?string
  174.     {
  175.         return $this->phone;
  176.     }
  177.     public function setPhone(?string $phone): self
  178.     {
  179.         $this->phone $phone;
  180.         return $this;
  181.     }
  182.     public function getEmail(): ?string
  183.     {
  184.         return $this->email;
  185.     }
  186.     public function setEmail(?string $email): self
  187.     {
  188.         $this->email $email;
  189.         return $this;
  190.     }
  191.     public function getImage(): ?Image
  192.     {
  193.         return $this->image;
  194.     }
  195.     public function setImage(?Image $image): self
  196.     {
  197.         $this->image $image;
  198.         return $this;
  199.     }
  200.     public function getComment(): ?string
  201.     {
  202.         return $this->comment;
  203.     }
  204.     public function setComment(?string $comment): self
  205.     {
  206.         $this->comment $comment;
  207.         return $this;
  208.     }
  209.     public function addComment(string $textbool $checkContains true,
  210.                                bool $ucfirst falsebool $addDot false): void
  211.     {
  212.         if ($ucfirst) {
  213.             $text mb_ucfirst($text'UTF-8');
  214.         }
  215.         if ($addDot && mb_substr($text, -1null'UTF-8') !== '.') {
  216.             $text .= '.';
  217.         }
  218.         $newComment trim($this->comment ?? "");
  219.         if (!$checkContains || mb_strpos($newComment $textnull'UTF-8') === false) {
  220.             $newComment $newComment
  221.                 . ($addDot && $newComment && mb_substr($newComment, -1null'UTF-8') !== '.' '.' '')
  222.                 . ($newComment ?  "\n" "")
  223.                 . $text;
  224.             $this->setComment($newComment);
  225.         }
  226.     }
  227.     public function getLastName2(): ?string
  228.     {
  229.         return $this->lastName2;
  230.     }
  231.     public function setLastName2(?string $lastName2): self
  232.     {
  233.         $this->lastName2 $lastName2;
  234.         return $this;
  235.     }
  236.     public function getTelegramUserId(): ?string
  237.     {
  238.         return $this->telegramUserId;
  239.     }
  240.     public function setTelegramUserId(?string $telegramUserId): self
  241.     {
  242.         $this->telegramUserId $telegramUserId;
  243.         return $this;
  244.     }
  245.     public function isCanSendTelegramCampaigns(): ?bool
  246.     {
  247.         return $this->canSendTelegramCampaigns;
  248.     }
  249.     public function setCanSendTelegramCampaigns(?bool $canSendTelegramCampaigns): self
  250.     {
  251.         $this->canSendTelegramCampaigns $canSendTelegramCampaigns;
  252.         return $this;
  253.     }
  254.     public function getMessageReceiver(): ?self
  255.     {
  256.         return $this->messageReceiver;
  257.     }
  258.     public function setMessageReceiver(?self $messageReceiver): self
  259.     {
  260.         $this->messageReceiver $messageReceiver;
  261.         return $this;
  262.     }
  263.     public function isIsStudent(): ?bool
  264.     {
  265.         return $this->isStudent;
  266.     }
  267.     public function setIsStudent(?bool $isStudent): self
  268.     {
  269.         $this->isStudent $isStudent;
  270.         return $this;
  271.     }
  272.     public function isIsSubscriber(): ?bool
  273.     {
  274.         return $this->isSubscriber;
  275.     }
  276.     public function setIsSubscriber(?bool $isSubscriber): self
  277.     {
  278.         $this->isSubscriber $isSubscriber;
  279.         return $this;
  280.     }
  281.     public function getVirtualStudentStatus(): ?string
  282.     {
  283.         if ($this->isIsStudent()) {
  284.             return $this->getStudent()->getStatus();
  285.         } elseif ($this->isIsSubscriber()) {
  286.             return VirtualStatus::VIRTUAL_STATUS_SUBSCRIBER;
  287.         }
  288.         return null;
  289.     }
  290.     public function setVirtualStudentStatus(?string $virtualStatus): void
  291.     {
  292.         if ($virtualStatus === VirtualStatus::VIRTUAL_STATUS_SUBSCRIBER) {
  293.             $this->setIsSubscriber(true);
  294.             $this->setIsStudent(false);
  295.         } elseif (Status::isCorrect($virtualStatus)) {
  296.             $this->setIsStudent(true);
  297.             $this->setIsSubscriber(false);
  298.             $this->getStudent()->setStatus($virtualStatus);
  299.         } else {
  300.             throw new \Exception("Unknown: " $virtualStatus);
  301.         }
  302.     }
  303.     public function getVirtualStudentStatusText(): ?string
  304.     {
  305.         if (Status::isCorrect($this->getVirtualStudentStatus())) {
  306.             return $this->getStudent()->getStatusText();
  307.         }
  308.         return VirtualStatus::getText($this->getVirtualStudentStatus());
  309.     }
  310.     public function getVirtualStudentStatusCssClass($prefix null): ?string
  311.     {
  312.         if (Status::isCorrect($this->getVirtualStudentStatus())) {
  313.             return $this->getStudent()->getStatusCssClass($prefix);
  314.         }
  315.         return VirtualStatus::getCssClass($this->getVirtualStudentStatus(), $prefix);
  316.     }
  317.     public function getSurname(): ?string
  318.     {
  319.         return $this->surname;
  320.     }
  321.     public function setSurname(?string $surname): self
  322.     {
  323.         $this->surname $surname;
  324.         return $this;
  325.     }
  326.     public function getCreatedAt(): ?\DateTimeInterface
  327.     {
  328.         return $this->createdAt;
  329.     }
  330.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  331.     {
  332.         $this->createdAt $createdAt;
  333.         return $this;
  334.     }
  335.     public function isCalendarEventStatusAllowed(CalendarEvent $calendarEvent): bool
  336.     {
  337.         return $this->getVirtualStudentStatus() == $calendarEvent->getRequireStudentStatus();
  338.     }
  339. }