src/Entity/Profile/Comment/CommentByCustomer.php line 15

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