src/Entity/Student.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\Student\Status;
  4. use App\Repository\StudentRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=StudentRepository::class)
  10.  */
  11. class Student
  12. {
  13.     const MAX_LEVEl = 9;
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="smallint", nullable=true)
  22.      */
  23.     private $level = null;
  24.     /**
  25.      * @ORM\OneToOne(targetEntity=Person::class, mappedBy="student")
  26.      */
  27.     private $person;
  28.     /**
  29.      * @ORM\OneToMany(targetEntity=StudentLevel::class, mappedBy="student")
  30.      */
  31.     private $levels;
  32.     /**
  33.      * @ORM\Column(type="enum", options={"values"="student_enum", "default"="active"})
  34.      */
  35.     private $status = Status::STATUS_STUDENT_ACTIVE;
  36.     private ?string $studentLevelChangeComment = null;
  37.     private ?CalendarEvent $studentLevelCalendarEvent = null;
  38.     /**
  39.      * @ORM\Column(type="datetime")
  40.      */
  41.     private $createdAt;
  42.     /**
  43.      * @ORM\Column(type="boolean", nullable=true)
  44.      */
  45.     private $candidateReviewIsNotRequired;
  46.     /**
  47.      * @ORM\Column(type="boolean", nullable=true)
  48.      */
  49.     private $freeCalendarEventsAccess;
  50.     public function __construct()
  51.     {
  52.         $this->levels = new ArrayCollection();
  53.         $this->createdAt = new \DateTime();
  54.     }
  55.     public function getLevelText(): string
  56.     {
  57.         if ($this->getLevel() < 0 || $this->getLevel() === null) {
  58.             return "нет уровня";
  59.         }
  60.         if ($this->getLevel() === 0) {
  61.             return "баз. ур.";
  62.         }
  63.         return (string)$this->getLevel() . " ур.";
  64.     }
  65.     public function getShortInfo(array $options = null): string
  66.     {
  67.         return $this->getPerson()->getName($options) . (" (" . $this->getLevelText() . ")");
  68.     }
  69.     public function getNameLevelCityText(): string
  70.     {
  71.         $person = $this->getPerson();
  72.         return $person->getName() . " (" . $this->getLevelText() . ", " .$person->getCityText() . ")";
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getLevel(): ?int
  79.     {
  80.         if (!Status::isAnyStudentStatus($this->getStatus())) {
  81.             return null;
  82.         }
  83.         return $this->level;
  84.     }
  85.     public function setLevel(?int $level): self
  86.     {
  87.         $this->level = $level;
  88.         return $this;
  89.     }
  90.     public function getPerson(): ?Person
  91.     {
  92.         return $this->person;
  93.     }
  94.     public function setPerson(?Person $person): self
  95.     {
  96.         // unset the owning side of the relation if necessary
  97.         if ($person === null && $this->person !== null) {
  98.             $this->person->setStudent(null);
  99.         }
  100.         // set the owning side of the relation if necessary
  101.         if ($person !== null && $person->getStudent() !== $this) {
  102.             $person->setStudent($this);
  103.         }
  104.         $this->person = $person;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection<int, StudentLevel>
  109.      */
  110.     public function getLevels(): Collection
  111.     {
  112.         return $this->levels;
  113.     }
  114.     public function addLevel(StudentLevel $level): self
  115.     {
  116.         if (!$this->levels->contains($level)) {
  117.             $this->levels[] = $level;
  118.             $level->setStudent($this);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removeLevel(StudentLevel $level): self
  123.     {
  124.         if ($this->levels->removeElement($level)) {
  125.             // set the owning side to null (unless already changed)
  126.             if ($level->getStudent() === $this) {
  127.                 $level->setStudent(null);
  128.             }
  129.         }
  130.         return $this;
  131.     }
  132.     public function getStatus()
  133.     {
  134.         return $this->status;
  135.     }
  136.     public function setStatus($status): self
  137.     {
  138.         $this->status = $status;
  139.         return $this;
  140.     }
  141.     public function getStatusText(): ?string
  142.     {
  143.         return Status::getText($this->getStatus());
  144.     }
  145.     public function getStatusCssClass($prefix = null): ?string
  146.     {
  147.         return Status::getCssClass($this->getStatus(), $prefix);
  148.     }
  149.     public function getCreatedAt(): ?\DateTimeInterface
  150.     {
  151.         return $this->createdAt;
  152.     }
  153.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  154.     {
  155.         $this->createdAt = $createdAt;
  156.         return $this;
  157.     }
  158.     public function isCandidateReviewIsNotRequired(): ?bool
  159.     {
  160.         return $this->candidateReviewIsNotRequired;
  161.     }
  162.     public function setCandidateReviewIsNotRequired(?bool $candidateReviewIsNotRequired): self
  163.     {
  164.         $this->candidateReviewIsNotRequired = $candidateReviewIsNotRequired;
  165.         return $this;
  166.     }
  167.     public function isFreeCalendarEventsAccess(): ?bool
  168.     {
  169.         return $this->freeCalendarEventsAccess;
  170.     }
  171.     public function setFreeCalendarEventsAccess(?bool $freeCalendarEventsAccess): self
  172.     {
  173.         $this->freeCalendarEventsAccess = $freeCalendarEventsAccess;
  174.         return $this;
  175.     }
  176.     public function getStudentLevelChangeComment(): ?string
  177.     {
  178.         return $this->studentLevelChangeComment;
  179.     }
  180.     public function setStudentLevelChangeComment(?string $studentLevelChangeComment): self
  181.     {
  182.         $this->studentLevelChangeComment = $studentLevelChangeComment;
  183.         return $this;
  184.     }
  185.     public function getStudentLevelCalendarEvent(): ?CalendarEvent
  186.     {
  187.         return $this->studentLevelCalendarEvent;
  188.     }
  189.     public function setStudentLevelCalendarEvent(?CalendarEvent $studentLevelCalendarEvent): self
  190.     {
  191.         $this->studentLevelCalendarEvent = $studentLevelCalendarEvent;
  192.         return $this;
  193.     }
  194. }