src/Entity/Person.php line 15

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