<?php
namespace App\Entity;
use App\Repository\ProjectNotificationRepository;
use App\String\Constant;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProjectNotificationRepository::class)]
class ProjectNotification
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $category = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $title = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $subtitle = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(nullable: true)]
private ?bool $isRead = null;
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'projectNotifications')]
private Collection $user;
#[ORM\Column(length: 255, nullable: true)]
private ?string $link = null;
public function __construct()
{
$this->user = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): self
{
$this->category = $category;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getSubtitle(): ?string
{
return $this->subtitle;
}
public function setSubtitle(?string $subtitle): self
{
$this->subtitle = $subtitle;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function isIsRead(): ?bool
{
return $this->isRead;
}
public function setIsRead(?bool $isRead): self
{
$this->isRead = $isRead;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUser(): Collection
{
return $this->user;
}
public function addUser(User $user): self
{
if (!$this->user->contains($user)) {
$this->user->add($user);
}
return $this;
}
public function removeUser(User $user): self
{
$this->user->removeElement($user);
return $this;
}
public function getNotificationHtml()
{
$category = $this->category;
$icon = '';
switch($category) {
case Constant::NOTIFICATION_UPDATE:
$icon = '<i class="fa fa-2x fa-heart me-3" style="color: #e15426"></i>';
default:
$icon = '<i class="fa fa-2x fa-heart me-3" style="color: #e15426"></i>';
break;
}
$isRead = '';
if ($this->isRead) {
$isRead = 'isread';
}
$html = '<div class="d-flex align-items-center '.$isRead.'"><a href="'. $this->link .'" target="_blank" style="position: absolute; width: 100%; height: 100%; left: 0;"></a>'.$icon.
'<div> <span>'. $this->title .'</span>'.
'<div> <span>'. $this->subtitle .'</span>'.
'</div></div>';
return $html;
}
public function getLink(): ?string
{
return $this->link;
}
public function setLink(?string $link): self
{
$this->link = $link;
return $this;
}
public function markAsRead(): self
{
if ($this->isRead === null) {
$this->isRead = false;
return $this;
}
$this->isRead = true;
return $this;
}
}