src/Entity/Announcement.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass'App\Repository\AnnouncementRepository')]
  8. class Announcement
  9. {
  10.     #[Groups(['LogService'])]
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private $id;
  15.     #[Groups(['LogService'])]
  16.     #[ORM\Column(type'string'length255)]
  17.     private $subject;
  18.     #[Groups(['LogService'])]
  19.     #[ORM\Column(type'text'nullabletrue)]
  20.     private $message;
  21.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'announcements')]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private $company;
  24.     #[ORM\ManyToOne(targetEntityOffice::class, inversedBy'announcements')]
  25.     #[ORM\JoinColumn(nullabletrue)]
  26.     private $office;
  27.     #[ORM\ManyToMany(targetEntityDepartment::class, inversedBy'announcements')]
  28.     private $departments;
  29.     #[Groups(['LogService'])]
  30.     #[ORM\ManyToOne(targetEntityUser::class)]
  31.     #[ORM\JoinColumn(nullablefalse)]
  32.     private $createdBy;
  33.     #[Groups(['LogService'])]
  34.     #[ORM\Column(type'datetime')]
  35.     private $createdAt;
  36.     #[Groups(['LogService'])]
  37.     #[ORM\Column(type'datetime')]
  38.     private $publishAt;
  39.     #[Groups(['LogService'])]
  40.     #[ORM\ManyToOne(targetEntityUser::class)]
  41.     private $updatedBy;
  42.     #[Groups(['LogService'])]
  43.     #[ORM\Column(type'datetime'nullabletrue)]
  44.     private $updatedAt;
  45.     #[ORM\ManyToMany(targetEntityUser::class)]
  46.     private $readBy;
  47.     public function __construct()
  48.     {
  49.         $this->departments = new ArrayCollection();
  50.         $this->readBy = new ArrayCollection();
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getSubject(): ?string
  57.     {
  58.         return $this->subject;
  59.     }
  60.     public function setSubject(string $subject): self
  61.     {
  62.         $this->subject $subject;
  63.         return $this;
  64.     }
  65.     public function getMessage(): ?string
  66.     {
  67.         return $this->message;
  68.     }
  69.     public function setMessage(?string $message): self
  70.     {
  71.         $this->message $message;
  72.         return $this;
  73.     }
  74.     public function getCompany(): ?Company
  75.     {
  76.         return $this->company;
  77.     }
  78.     public function setCompany(?Company $company): self
  79.     {
  80.         $this->company $company;
  81.         return $this;
  82.     }
  83.     public function getOffice(): ?Office
  84.     {
  85.         return $this->office;
  86.     }
  87.     public function setOffice(?Office $office): self
  88.     {
  89.         $this->office $office;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @return Collection|Department[]
  94.      */
  95.     public function getDepartments(): Collection
  96.     {
  97.         return $this->departments;
  98.     }
  99.     public function addDepartment(Department $department): self
  100.     {
  101.         if (!$this->departments->contains($department)) {
  102.             $this->departments[] = $department;
  103.         }
  104.         return $this;
  105.     }
  106.     public function removeDepartment(Department $department): self
  107.     {
  108.         if ($this->departments->contains($department)) {
  109.             $this->departments->removeElement($department);
  110.         }
  111.         return $this;
  112.     }
  113.     public function getCreatedBy(): ?User
  114.     {
  115.         return $this->createdBy;
  116.     }
  117.     public function setCreatedBy(?User $createdBy): self
  118.     {
  119.         $this->createdBy $createdBy;
  120.         return $this;
  121.     }
  122.     public function getCreatedAt(): ?\DateTimeInterface
  123.     {
  124.         return $this->createdAt;
  125.     }
  126.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  127.     {
  128.         $this->createdAt $createdAt;
  129.         return $this;
  130.     }
  131.     public function getPublishAt(): ?\DateTimeInterface
  132.     {
  133.         return $this->publishAt;
  134.     }
  135.     public function setPublishAt(\DateTimeInterface $publishAt): self
  136.     {
  137.         $this->publishAt $publishAt;
  138.         return $this;
  139.     }
  140.     
  141.     function departmentFilterIds()
  142.     {
  143.         $id = [];
  144.         foreach ($this->getDepartments() as $department) {
  145.             if (!in_array($department->getId(), $id))
  146.                 array_push($id$department->getId());
  147.         }
  148.         $id count($id) == $id;
  149.         return implode(' '$id);
  150.     }
  151.     public function getUpdatedBy(): ?User
  152.     {
  153.         return $this->updatedBy;
  154.     }
  155.     public function setUpdatedBy(?User $updatedBy): self
  156.     {
  157.         $this->updatedBy $updatedBy;
  158.         return $this;
  159.     }
  160.     public function getUpdatedAt(): ?\DateTimeInterface
  161.     {
  162.         return $this->updatedAt;
  163.     }
  164.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  165.     {
  166.         $this->updatedAt $updatedAt;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection|User[]
  171.      */
  172.     public function getReadBy(): Collection
  173.     {
  174.         return $this->readBy;
  175.     }
  176.     public function addReadBy(User $readBy): self
  177.     {
  178.         if (!$this->readBy->contains($readBy)) {
  179.             $this->readBy[] = $readBy;
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeReadBy(User $readBy): self
  184.     {
  185.         if ($this->readBy->contains($readBy)) {
  186.             $this->readBy->removeElement($readBy);
  187.         }
  188.         return $this;
  189.     }
  190.     public function statusHTML($user){
  191.         if($this->updatedAt != null && count($this->readBy) == 0){ //need to find a way to put updated
  192.             return '<span class="font-weight-bold text-accent">Updated</span>';
  193.         } elseif ($this->readBy->contains($user)) {
  194.             return '<span class="text-gray">Read</span>';
  195.         } else {
  196.             return '<span class="font-weight-bold text-accent">New</span>';
  197.         }
  198.     }
  199. }