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

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