<?php
namespace App\Entity\Shop\Product;
use App\Entity\BaseEntity;
use App\Entity\Generic\Customer\Customer;
use App\Repository\Shop\Product\ProductReviewRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: ProductReviewRepository::class)]
class ProductReview extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\ManyToOne(inversedBy: 'productReviews')]
#[ORM\JoinColumn(nullable: false)]
private ?Product $product = null;
#[ORM\ManyToOne(inversedBy: 'productReviews')]
#[ORM\JoinColumn(nullable: false)]
private ?Customer $author = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $content = null;
#[ORM\Column]
private array $pros = [];
#[ORM\Column]
private array $cons = [];
#[ORM\Column]
private ?int $rating = null;
#[ORM\Column]
private ?bool $recommend = null;
#[ORM\Column]
private ?bool $approved = null;
#[ORM\OneToMany(mappedBy: 'review', targetEntity: ProductReviewVote::class)]
private Collection $productReviewVotes;
#[ORM\OneToMany(mappedBy: 'review', targetEntity: ProductReviewReply::class)]
private Collection $productReviewReplies;
public function __construct()
{
parent::__construct();
$this->setApproved(0);
$this->productReviewVotes = new ArrayCollection();
$this->productReviewReplies = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
public function getAuthor(): ?Customer
{
return $this->author;
}
public function setAuthor(?Customer $author): static
{
$this->author = $author;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): static
{
$this->content = $content;
return $this;
}
public function getPros(): array
{
return $this->pros;
}
public function setPros(array $pros): static
{
$this->pros = $pros;
return $this;
}
public function getCons(): array
{
return $this->cons;
}
public function setCons(array $cons): static
{
$this->cons = $cons;
return $this;
}
public function getRating(): ?int
{
return $this->rating;
}
public function setRating(int $rating): static
{
$this->rating = $rating;
return $this;
}
public function isRecommend(): ?bool
{
return $this->recommend;
}
public function setRecommend(bool $recommend): static
{
$this->recommend = $recommend;
return $this;
}
public function isApproved(): ?bool
{
return $this->approved;
}
public function setApproved(bool $approved): static
{
$this->approved = $approved;
return $this;
}
/**
* @return Collection<int, ProductReviewVote>
*/
public function getProductReviewVotes(): Collection
{
return $this->productReviewVotes;
}
public function addProductReviewVote(ProductReviewVote $productReviewVote): static
{
if (!$this->productReviewVotes->contains($productReviewVote)) {
$this->productReviewVotes->add($productReviewVote);
$productReviewVote->setReview($this);
}
return $this;
}
public function removeProductReviewVote(ProductReviewVote $productReviewVote): static
{
if ($this->productReviewVotes->removeElement($productReviewVote)) {
// set the owning side to null (unless already changed)
if ($productReviewVote->getReview() === $this) {
$productReviewVote->setReview(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductReviewReply>
*/
public function getProductReviewReplies(): Collection
{
return $this->productReviewReplies;
}
public function addProductReviewReply(ProductReviewReply $productReviewReply): static
{
if (!$this->productReviewReplies->contains($productReviewReply)) {
$this->productReviewReplies->add($productReviewReply);
$productReviewReply->setReview($this);
}
return $this;
}
public function removeProductReviewReply(ProductReviewReply $productReviewReply): static
{
if ($this->productReviewReplies->removeElement($productReviewReply)) {
// set the owning side to null (unless already changed)
if ($productReviewReply->getReview() === $this) {
$productReviewReply->setReview(null);
}
}
return $this;
}
}