src/Entity/Candidate.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\Candidate\Status;
  4. use App\Repository\CandidateRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass=CandidateRepository::class)
  8.  */
  9. class Candidate
  10. {
  11.     const CANDIDATE_FIELD_STATUS 'candidate_status';
  12.     const CANDIDATE_FIELD_PERSON 'candidate_person';
  13.     const CANDIDATE_FIELD_AUTHOR 'candidate_author';
  14.     const CANDIDATE_FIELD_CALENDAR_EVENT 'candidate_calendar_event';
  15.     const CANDIDATE_FIELD_CREATED_AT 'candidate_created_at';
  16.     const CANDIDATE_FIELD_APPROVED_AT 'candidate_approved_at';
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="enum", options={"values": "candidate_enum"})
  25.      */
  26.     private $status Status::STATUS_DRAFT;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity=User::class)
  29.      * @ORM\JoinColumn(nullable=false)
  30.      */
  31.     private $author;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=Person::class)
  34.      * @ORM\JoinColumn(nullable=true)
  35.      */
  36.     private $person;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity=CalendarEvent::class)
  39.      */
  40.     private $calendarEvent;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private $createdAt;
  45.     /**
  46.      * @ORM\Column(type="text", nullable=true)
  47.      */
  48.     private $viewerComment;
  49.     /**
  50.      * @ORM\Column(type="datetime", nullable=true)
  51.      */
  52.     private $approvedAt;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity=Image::class, cascade={"persist", "remove"})
  55.      */
  56.     private $image;
  57.     /**
  58.      * @ORM\Column(type="text", nullable=true)
  59.      */
  60.     private $comment;
  61.     /**
  62.      * @ORM\Column(type="boolean", nullable=true)
  63.      */
  64.     private $paymentDeferment;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity=User::class)
  67.      */
  68.     private $selectedAuthor;
  69.     /**
  70.      * @ORM\Column(type="text", nullable=true)
  71.      */
  72.     private $recommendations;
  73.     /**
  74.      * @ORM\ManyToOne(targetEntity=User::class)
  75.      */
  76.     private $curator;
  77.     /**
  78.      * @ORM\Column(type="datetime")
  79.      */
  80.     private $updatedAt;
  81.     public function __construct()
  82.     {
  83.         $this->createdAt = new \DateTime();
  84.         $this->updatedAt = new \DateTime();
  85.     }
  86.     public function getId(): ?int
  87.     {
  88.         return $this->id;
  89.     }
  90.     public function getStatus()
  91.     {
  92.         return $this->status;
  93.     }
  94.     public function isStatusApproved(): bool
  95.     {
  96.         return $this->status === Status::STATUS_APPROVED;
  97.     }
  98.     public function isStatusDeclined(): bool
  99.     {
  100.         return $this->status === Status::STATUS_DECLINED;
  101.     }
  102.     public function setStatus($status): self
  103.     {
  104.         $this->status $status;
  105.         if ($status == Status::STATUS_APPROVED && !$this->getApprovedAt()) {
  106.             $this->setApprovedAt(new \DateTime());
  107.         }
  108.         return $this;
  109.     }
  110.     public function getAuthor(): ?User
  111.     {
  112.         // if ($this->getSelectedAuthor()) {
  113.         //     return $this->getSelectedAuthor();
  114.         // }
  115.         return $this->author;
  116.     }
  117.     public function setAuthor(?User $author): self
  118.     {
  119.         $this->author $author;
  120.         return $this;
  121.     }
  122.     public function getPerson(): ?Person
  123.     {
  124.         return $this->person;
  125.     }
  126.     public function setPerson(?Person $person): self
  127.     {
  128.         $this->person $person;
  129.         return $this;
  130.     }
  131.     public function getCalendarEvent(): ?CalendarEvent
  132.     {
  133.         return $this->calendarEvent;
  134.     }
  135.     public function setCalendarEvent(?CalendarEvent $calendarEvent): self
  136.     {
  137.         $this->calendarEvent $calendarEvent;
  138.         return $this;
  139.     }
  140.     public function getCreatedAt(): ?\DateTimeInterface
  141.     {
  142.         return $this->createdAt;
  143.     }
  144.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  145.     {
  146.         $this->createdAt $createdAt;
  147.         return $this;
  148.     }
  149.     public function getViewerComment(): ?string
  150.     {
  151.         return $this->viewerComment;
  152.     }
  153.     public function setViewerComment(?string $viewerComment): self
  154.     {
  155.         $this->viewerComment $viewerComment;
  156.         return $this;
  157.     }
  158.     public function getApprovedAt(): ?\DateTimeInterface
  159.     {
  160.         return $this->approvedAt;
  161.     }
  162.     public function setApprovedAt(?\DateTimeInterface $approvedAt): self
  163.     {
  164.         $this->approvedAt $approvedAt;
  165.         return $this;
  166.     }
  167.     public function getImage(): ?Image
  168.     {
  169.         return $this->image;
  170.     }
  171.     public function setImage(?Image $image): self
  172.     {
  173.         $this->image $image;
  174.         return $this;
  175.     }
  176.     public function getComment(): ?string
  177.     {
  178.         return $this->comment;
  179.     }
  180.     public function setComment(?string $comment): self
  181.     {
  182.         $this->comment $comment;
  183.         return $this;
  184.     }
  185.     public function getStatusText(): string
  186.     {
  187.         return Status::getText($this->status);
  188.     }
  189.     public function getVirtualStatusText(): string
  190.     {
  191.         if (($this->getCalendarEvent() && !$this->getCalendarEvent()->isIsCandidateReviewRequired())
  192.             || ($this->getPerson()->getStudent() && $this->getPerson()->getStudent()->isCandidateReviewIsNotRequired())) {
  193.             return Status::getText(Status::STATUS_NOT_REQUIRED);
  194.         }
  195.         return Status::getText($this->status);
  196.     }
  197.     public function getCssClass(): string
  198.     {
  199.         return Status::getCssClass($this->status);
  200.     }
  201.     public function getVirtualCssClass(): string
  202.     {
  203.         if (($this->getCalendarEvent() && !$this->getCalendarEvent()->isIsCandidateReviewRequired())
  204.             || ($this->getPerson()->getStudent() && $this->getPerson()->getStudent()->isCandidateReviewIsNotRequired())) {
  205.             return Status::getCssClass(Status::STATUS_NOT_REQUIRED);
  206.         }
  207.         return Status::getCssClass($this->status);
  208.     }
  209.     public function isPaymentDeferment(): ?bool
  210.     {
  211.         return $this->paymentDeferment;
  212.     }
  213.     public function setPaymentDeferment(?bool $paymentDeferment): self
  214.     {
  215.         $this->paymentDeferment $paymentDeferment;
  216.         return $this;
  217.     }
  218.     public function getSelectedAuthor(): ?User
  219.     {
  220.         return $this->selectedAuthor;
  221.     }
  222.     public function setSelectedAuthor(?User $selectedAuthor): self
  223.     {
  224.         $this->selectedAuthor $selectedAuthor;
  225.         return $this;
  226.     }
  227.     public function getRecommendations(): ?string
  228.     {
  229.         return $this->recommendations;
  230.     }
  231.     public function setRecommendations(?string $recommendations): self
  232.     {
  233.         $this->recommendations $recommendations;
  234.         return $this;
  235.     }
  236.     public function getCurator(): ?User
  237.     {
  238.         return $this->curator;
  239.     }
  240.     public function setCurator(?User $curator): self
  241.     {
  242.         $this->curator $curator;
  243.         return $this;
  244.     }
  245.     public function getUpdatedAt(): ?\DateTimeInterface
  246.     {
  247.         if (!$this->updatedAt) {
  248.             return $this->getCreatedAt();
  249.         }
  250.         return $this->updatedAt;
  251.     }
  252.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  253.     {
  254.         $this->updatedAt $updatedAt;
  255.         return $this;
  256.     }
  257.     public function isTimeToSendReviewResultMessage(): array
  258.     {
  259.         $result = [
  260.             "result" => false,
  261.             'waitMinutes' => null,
  262.         ];
  263.         $minutesLeftSinceUpdate = (int)ceil((time() - $this->getUpdatedAt()->getTimestamp()) / 60);
  264.         if ($this->getCalendarEvent()->getHoursLeftBeforeStart() >= &&
  265.             $minutesLeftSinceUpdate 15
  266.         ) {
  267.             $result['result'] = false;
  268.             $result['waitMinutes'] = 15 $minutesLeftSinceUpdate;
  269.         } else {
  270.             $result['result'] = true;
  271.         }
  272.         return $result;
  273.     }
  274. }