src/Entity/Saloon/Comment/CommentByCustomer.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Saloon\Comment;
  3. use App\Entity\Account\Customer;
  4. use App\Entity\Saloon\Saloon;
  5. use App\Entity\System\IpAddress;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity]
  10. class CommentByCustomer extends Comment
  11. {
  12.     const MARKS = [12345];
  13.     #[ORM\Column(name'mark'type'smallint'options: ['default' => 0])]
  14.     protected int $mark 0;
  15.     #[ORM\OneToMany(targetEntityComment::class, mappedBy'parent'cascade: ['all'], orphanRemovaltrue)]
  16.     #[ORM\OrderBy(['createdAt' => 'ASC'])]
  17.     protected Collection $comments;
  18.     public function __construct(Saloon $saloon, ?CommentByCustomer $parent, ?Customer $userstring $textint $mark\DateTimeImmutable $createdAt, ?IpAddress $ipAddress null)
  19.     {
  20.         parent::__construct($saloon$parent$user$text$createdAt);
  21.         $this->mark $mark;
  22.         $this->comments = new ArrayCollection();
  23.         if($ipAddress)
  24.             $this->ipAddress $ipAddress;
  25.     }
  26.     public function getMark(): int
  27.     {
  28.         return $this->mark;
  29.     }
  30.     public function setMark(int $mark): void
  31.     {
  32.         $this->mark $mark;
  33.     }
  34.     public function getComments(): Collection
  35.     {
  36.         return $this->comments;
  37.     }
  38.     public function addComment(Comment $comment)
  39.     {
  40.         return $this->comments->add($comment);
  41.     }
  42.     public function removeComment(Comment $comment)
  43.     {
  44.         return $this->comments->removeElement($comment);
  45.     }
  46.     public function isCommentedByAdvertiser(): bool
  47.     {
  48.         return $this->comments->filter(function(Comment $comment): bool {
  49.             return $comment instanceof CommentByAdvertiser;
  50.         })->count() > 0;
  51.     }
  52.     public function isCommentedBySupport(): bool
  53.     {
  54.         return $this->comments->filter(function(Comment $comment): bool {
  55.             return $comment instanceof CommentBySupport;
  56.         })->count() > 0;
  57.     }
  58.     public function getLastCommentByAdvertiser(): ?CommentByAdvertiser
  59.     {
  60.         $replies $this->comments->filter(function(Comment $comment): bool {
  61.             return $comment instanceof CommentByAdvertiser;
  62.         });
  63.         return $replies->count() > $replies->last() : null;
  64.     }
  65.     public function getLastCommentBySupport(): ?CommentBySupport
  66.     {
  67.         $replies $this->comments->filter(function(Comment $comment): bool {
  68.             return $comment instanceof CommentBySupport;
  69.         });
  70.         return $replies->count() > $replies->last() : null;
  71.     }
  72. }