src/Entity/Profile/Comment/Comment.php line 23

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-21
  5.  * Time: 19:42
  6.  */
  7. namespace App\Entity\Profile\Comment;
  8. use App\Entity\Profile\Profile;
  9. use App\Entity\System\IpAddress;
  10. use App\Entity\User;
  11. use App\Repository\ProfileCommentRepository;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. #[ORM\Table(name: 'profile_comments')]
  16. #[ORM\Entity(repositoryClass: ProfileCommentRepository::class)]
  17. #[ORM\InheritanceType('SINGLE_TABLE')]
  18. #[ORM\DiscriminatorColumn(name: 'account_type', type: 'string', length: 12)]
  19. #[ORM\DiscriminatorMap(['customer' => CommentByCustomer::class, 'advertiser' => CommentByAdvertiser::class, 'support' => CommentBySupport::class])]
  20. abstract class Comment
  21. {
  22.     use SoftDeleteableEntity;
  23.     #[ORM\Id]
  24.     #[ORM\Column(name: 'id', type: 'integer')]
  25.     #[ORM\GeneratedValue(strategy: 'AUTO')]
  26.     protected int $id;
  27.     #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true)]
  28.     #[ORM\ManyToOne(targetEntity: Comment::class)]
  29.     protected ?CommentByCustomer $parent;
  30.     //, inversedBy="comments"
  31.     #[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id', nullable: true)]
  32.     #[ORM\ManyToOne(targetEntity: Profile::class, inversedBy: 'comments')]
  33.     protected ?Profile $profile;
  34.     #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
  35.     #[ORM\ManyToOne(targetEntity: User::class)]
  36.     #[Groups(['preview', 'comments'])]
  37.     protected ?User $user;
  38.     #[ORM\Column(name: 'text', type: 'text')]
  39.     #[Groups(['preview', 'comments'])]
  40.     protected string $text;
  41.     #[ORM\Column(name: 'created_at', type: 'datetimetz_immutable')]
  42.     #[Groups(['preview', 'comments'])]
  43.     protected \DateTimeImmutable $createdAt;
  44.     #[ORM\JoinColumn(name: 'ip_address_id', referencedColumnName: 'id')]
  45.     #[ORM\ManyToOne(targetEntity: IpAddress::class, inversedBy: 'profileComments')]
  46.     protected ?IpAddress $ipAddress;
  47.     public function __construct(Profile $profile, ?CommentByCustomer $parent, ?User $user, string $text, \DateTimeImmutable $createdAt)
  48.     {
  49.         $this->parent = $parent;
  50.         $this->profile = $profile;
  51.         $this->user = $user;
  52.         $this->text = $text;
  53.         $this->createdAt = $createdAt;
  54.     }
  55.     public function getId(): int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getParent(): ?CommentByCustomer
  60.     {
  61.         return $this->parent;
  62.     }
  63.     public function getUser(): ?User
  64.     {
  65.         return $this->user;
  66.     }
  67.     public function getProfile(): Profile
  68.     {
  69.         return $this->profile;
  70.     }
  71.     public function getText(): string
  72.     {
  73.         return $this->text;
  74.     }
  75.     public function setText(string $text): void
  76.     {
  77.         $this->text = $text;
  78.     }
  79.     public function getCreatedAt(): \DateTimeImmutable
  80.     {
  81.         return $this->createdAt;
  82.     }
  83.     public function setCreatedAt(\DateTimeImmutable $createdAt): void
  84.     {
  85.         $this->createdAt = $createdAt;
  86.     }
  87.     public function clearRelations(): void
  88.     {
  89.         $this->profile = null;
  90.         $this->user = null;
  91.     }
  92.     public function getIpAddress(): ?IpAddress
  93.     {
  94.         return $this->ipAddress;
  95.     }
  96. }