<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-03-21
* Time: 19:42
*/
namespace App\Entity\Profile\Comment;
use App\Entity\Profile\Profile;
use App\Entity\System\IpAddress;
use App\Entity\User;
use App\Repository\ProfileCommentRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
#[ORM\Table(name: 'profile_comments')]
#[ORM\Entity(repositoryClass: ProfileCommentRepository::class)]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'account_type', type: 'string', length: 12)]
#[ORM\DiscriminatorMap(['customer' => CommentByCustomer::class, 'advertiser' => CommentByAdvertiser::class, 'support' => CommentBySupport::class])]
abstract class Comment
{
use SoftDeleteableEntity;
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected int $id;
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true)]
#[ORM\ManyToOne(targetEntity: Comment::class)]
protected ?CommentByCustomer $parent;
//, inversedBy="comments"
#[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id', nullable: true)]
#[ORM\ManyToOne(targetEntity: Profile::class, inversedBy: 'comments')]
protected ?Profile $profile;
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
#[ORM\ManyToOne(targetEntity: User::class)]
protected ?User $user;
#[ORM\Column(name: 'text', type: 'text')]
protected string $text;
#[ORM\Column(name: 'created_at', type: 'datetimetz_immutable')]
protected \DateTimeImmutable $createdAt;
#[ORM\JoinColumn(name: 'ip_address_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: IpAddress::class, inversedBy: 'profileComments')]
protected ?IpAddress $ipAddress;
public function __construct(Profile $profile, ?CommentByCustomer $parent, ?User $user, string $text, \DateTimeImmutable $createdAt)
{
$this->parent = $parent;
$this->profile = $profile;
$this->user = $user;
$this->text = $text;
$this->createdAt = $createdAt;
}
public function getId(): int
{
return $this->id;
}
public function getParent(): ?CommentByCustomer
{
return $this->parent;
}
public function getUser(): ?User
{
return $this->user;
}
public function getProfile(): Profile
{
return $this->profile;
}
public function getText(): string
{
return $this->text;
}
public function setText(string $text): void
{
$this->text = $text;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): void
{
$this->createdAt = $createdAt;
}
public function clearRelations(): void
{
$this->profile = null;
$this->user = null;
}
public function getIpAddress(): ?IpAddress
{
return $this->ipAddress;
}
}