<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: 'App\Repository\AnnouncementRepository')]
class Announcement
{
#[Groups(['LogService'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[Groups(['LogService'])]
#[ORM\Column(type: 'string', length: 255)]
private $subject;
#[Groups(['LogService'])]
#[ORM\Column(type: 'text', nullable: true)]
private $message;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'announcements')]
#[ORM\JoinColumn(nullable: false)]
private $company;
#[ORM\ManyToOne(targetEntity: Office::class, inversedBy: 'announcements')]
#[ORM\JoinColumn(nullable: true)]
private $office;
#[ORM\ManyToMany(targetEntity: Department::class, inversedBy: 'announcements')]
private $departments;
#[Groups(['LogService'])]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: false)]
private $createdBy;
#[Groups(['LogService'])]
#[ORM\Column(type: 'datetime')]
private $createdAt;
#[Groups(['LogService'])]
#[ORM\Column(type: 'datetime')]
private $publishAt;
#[Groups(['LogService'])]
#[ORM\ManyToOne(targetEntity: User::class)]
private $updatedBy;
#[Groups(['LogService'])]
#[ORM\Column(type: 'datetime', nullable: true)]
private $updatedAt;
#[ORM\ManyToMany(targetEntity: User::class)]
private $readBy;
public function __construct()
{
$this->departments = new ArrayCollection();
$this->readBy = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSubject(): ?string
{
return $this->subject;
}
public function setSubject(string $subject): self
{
$this->subject = $subject;
return $this;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(?string $message): self
{
$this->message = $message;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getOffice(): ?Office
{
return $this->office;
}
public function setOffice(?Office $office): self
{
$this->office = $office;
return $this;
}
/**
* @return Collection|Department[]
*/
public function getDepartments(): Collection
{
return $this->departments;
}
public function addDepartment(Department $department): self
{
if (!$this->departments->contains($department)) {
$this->departments[] = $department;
}
return $this;
}
public function removeDepartment(Department $department): self
{
if ($this->departments->contains($department)) {
$this->departments->removeElement($department);
}
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getPublishAt(): ?\DateTimeInterface
{
return $this->publishAt;
}
public function setPublishAt(\DateTimeInterface $publishAt): self
{
$this->publishAt = $publishAt;
return $this;
}
function departmentFilterIds()
{
$id = [];
foreach ($this->getDepartments() as $department) {
if (!in_array($department->getId(), $id))
array_push($id, $department->getId());
}
$id = count($id) == 0 ? 0 : $id;
return implode(' ', $id);
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|User[]
*/
public function getReadBy(): Collection
{
return $this->readBy;
}
public function addReadBy(User $readBy): self
{
if (!$this->readBy->contains($readBy)) {
$this->readBy[] = $readBy;
}
return $this;
}
public function removeReadBy(User $readBy): self
{
if ($this->readBy->contains($readBy)) {
$this->readBy->removeElement($readBy);
}
return $this;
}
public function statusHTML($user){
if($this->updatedAt != null && count($this->readBy) == 0){ //need to find a way to put updated
return '<span class="font-weight-bold text-accent">Updated</span>';
} elseif ($this->readBy->contains($user)) {
return '<span class="text-gray">Read</span>';
} else {
return '<span class="font-weight-bold text-accent">New</span>';
}
}
}