<?php
namespace App\Entity;
use App\Validator\ReviewValid;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\ReviewRepository")
* @ReviewValid()
*/
class Review
{
use TimestampableEntity;
/**
* @var DateTime
*
* @ORM\Column(type="datetime")
*/
protected $publishedAt;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(max=255)
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
* @Assert\NotBlank(groups={"ReviewContent"})
*/
private $content;
/**
* @ORM\Column(type="smallint", nullable=true)
* @Assert\NotBlank(groups={"ReviewScores"})
* @Assert\Range(min="0", max="10", groups={"ReviewScores"})
*/
private $diversityAcrossOrganization;
/**
* @ORM\Column(type="smallint", nullable=true)
* @Assert\NotBlank(groups={"ReviewScores"})
* @Assert\Range(min="0", max="10", groups={"ReviewScores"})
*/
private $diversityInLeadership;
/**
* @ORM\Column(type="smallint", nullable=true)
* @Assert\NotBlank(groups={"ReviewScores"})
* @Assert\Range(min="0", max="10", groups={"ReviewScores"})
*/
private $workLikeBalance;
/**
* @ORM\Column(type="smallint", nullable=true)
* @Assert\NotBlank(groups={"ReviewScores"})
* @Assert\Range(min="0", max="10", groups={"ReviewScores"})
*/
private $overallInclusiveness;
/**
* @ORM\Column(type="smallint", nullable=true)
* @Assert\NotBlank(groups={"ReviewScores"})
* @Assert\Range(min="0", max="10", groups={"ReviewScores"})
*/
private $benefitsAndResources;
/**
* @ORM\Column(type="decimal", precision=8, scale=6, nullable=true)
* @Assert\Range(min="0", max="10")
*/
private $enps;
/**
* @ORM\Column(type="decimal", precision=8, scale=6, nullable=true)
* @Assert\Range(min="0", max="10")
*/
private $average;
/**
* @ORM\Column(type="integer", options={"unsigned"=true})
*/
private $nbLikes;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $isAnonymous;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $companyAnswer;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $companyAnswerAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company",inversedBy="reviews")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $company;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $companyNotExisting;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User",inversedBy="reviews")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $user;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserLike", mappedBy="review", cascade={"persist"})
*/
private $userLikes;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ReviewTag")
*/
private $reviewTags;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserShare", mappedBy="review", cascade={"persist"})
*/
private $userShares;
/**
* @ORM\Column(type="integer")
*/
private $nbShares;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $flagged;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $blocked;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $notified;
/**
* @var DateTimeImmutable
*
* @ORM\Column(type="datetimetz_immutable", nullable=true)
*/
private $verifiedAt;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $verified;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $notRated;
/**
* virtual property.
*/
private $summaryTitle;
/**
* virtual property.
*/
private $summaryDescription;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserComment", mappedBy="review")
*/
private $userComments;
/**
* @ORM\Column(type="integer")
*/
private $nb_comments;
public function __construct()
{
$this->reviewTags = new ArrayCollection();
$this->nbLikes = 0;
$this->isAnonymous = true;
$this->userLikes = new ArrayCollection();
$this->userShares = new ArrayCollection();
$this->nbShares = 0;
$this->flagged = false;
$this->blocked = false;
$this->verified = false;
$this->createdAt = new \DateTime();
$this->publishedAt = new DateTime('+3 hours');
$this->updatedAt = new \DateTime();
$this->notRated = false;
$this->notified = false;
$this->userComments = new ArrayCollection();
}
/**
* @return mixed
*/
public function __toString()
{
return $this->title ?? '';
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getDiversityAcrossOrganization(): ?int
{
return $this->diversityAcrossOrganization;
}
public function setDiversityAcrossOrganization(?int $diversityAcrossOrganization): self
{
$this->diversityAcrossOrganization = $diversityAcrossOrganization;
return $this;
}
public function getDiversityInLeadership(): ?int
{
return $this->diversityInLeadership;
}
public function setDiversityInLeadership(?int $diversityInLeadership): self
{
$this->diversityInLeadership = $diversityInLeadership;
return $this;
}
public function getWorkLikeBalance(): ?int
{
return $this->workLikeBalance;
}
public function setWorkLikeBalance(?int $workLikeBalance): self
{
$this->workLikeBalance = $workLikeBalance;
return $this;
}
public function getOverallInclusiveness(): ?int
{
return $this->overallInclusiveness;
}
public function setOverallInclusiveness(?int $overallInclusiveness): self
{
$this->overallInclusiveness = $overallInclusiveness;
return $this;
}
public function getBenefitsAndResources(): ?int
{
return $this->benefitsAndResources;
}
public function setBenefitsAndResources(?int $benefitsAndResources): self
{
$this->benefitsAndResources = $benefitsAndResources;
return $this;
}
public function getEnps(): ?int
{
return $this->enps;
}
public function setEnps(?int $enps): self
{
$this->enps = $enps;
return $this;
}
public function getAverage()
{
return $this->average;
}
public function setAverage($average): self
{
$this->average = $average;
return $this;
}
public function getNbLikes(): ?int
{
return $this->nbLikes;
}
public function setNbLikes(int $nbLikes): self
{
$this->nbLikes = $nbLikes;
return $this;
}
public function getIsAnonymous(): ?bool
{
return $this->isAnonymous;
}
public function setIsAnonymous(bool $isAnonymous): self
{
$this->isAnonymous = $isAnonymous;
return $this;
}
public function getCompanyAnswer(): ?string
{
return $this->companyAnswer;
}
public function setCompanyAnswer(?string $companyAnswer): self
{
$this->companyAnswer = $companyAnswer;
return $this;
}
public function getCompanyAnswerAt(): ?DateTimeInterface
{
return $this->companyAnswerAt;
}
public function setCompanyAnswerAt(?DateTimeInterface $companyAnswerAt): self
{
$this->companyAnswerAt = $companyAnswerAt;
return $this;
}
public function getNbShares(): ?int
{
return $this->nbShares;
}
public function setNbShares(int $nbShares): self
{
$this->nbShares = $nbShares;
return $this;
}
public function getFlagged(): ?bool
{
return $this->flagged;
}
public function setFlagged(bool $flagged): self
{
$this->flagged = $flagged;
return $this;
}
public function getBlocked(): ?bool
{
return $this->blocked;
}
public function setBlocked(bool $blocked): self
{
$this->blocked = $blocked;
return $this;
}
public function getVerified(): ?bool
{
return $this->verified;
}
public function setVerified(bool $verified): self
{
$this->verified = $verified;
return $this;
}
public function getPublishedAt(): ?DateTimeInterface
{
return $this->publishedAt;
}
public function setPublishedAt(DateTimeInterface $publishedAt): self
{
$this->publishedAt = $publishedAt;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getCompanyNotExisting(): ?string
{
return $this->companyNotExisting;
}
public function setCompanyNotExisting(?string $companyNotExisting): self
{
$this->companyNotExisting = $companyNotExisting;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|UserLike[]
*/
public function getUserLikes(): Collection
{
return $this->userLikes;
}
public function addUserLike(UserLike $userLike): self
{
if (!$this->userLikes->contains($userLike)) {
$this->userLikes[] = $userLike;
$userLike->setReview($this);
}
return $this;
}
public function removeUserLike(UserLike $userLike): self
{
if ($this->userLikes->contains($userLike)) {
$this->userLikes->removeElement($userLike);
// set the owning side to null (unless already changed)
if ($userLike->getReview() === $this) {
$userLike->setReview(null);
}
}
return $this;
}
/**
* @return Collection|ReviewTag[]
*/
public function getReviewTags(): Collection
{
return $this->reviewTags;
}
public function addReviewTag(ReviewTag $reviewTag): self
{
if (!$this->reviewTags->contains($reviewTag)) {
$this->reviewTags[] = $reviewTag;
}
return $this;
}
public function removeReviewTag(ReviewTag $reviewTag): self
{
if ($this->reviewTags->contains($reviewTag)) {
$this->reviewTags->removeElement($reviewTag);
}
return $this;
}
/**
* @return Collection|UserShare[]
*/
public function getUserShares(): Collection
{
return $this->userShares;
}
public function addUserShare(UserShare $userShare): self
{
if (!$this->userShares->contains($userShare)) {
$this->userShares[] = $userShare;
$userShare->setReview($this);
}
return $this;
}
public function removeUserShare(UserShare $userShare): self
{
if ($this->userShares->contains($userShare)) {
$this->userShares->removeElement($userShare);
// set the owning side to null (unless already changed)
if ($userShare->getReview() === $this) {
$userShare->setReview(null);
}
}
return $this;
}
public function getNotRated(): ?bool
{
return $this->notRated;
}
public function setNotRated(bool $notRated): self
{
$this->notRated = $notRated;
return $this;
}
public function getNotified(): ?bool
{
return $this->notified;
}
public function setNotified(bool $notified): self
{
$this->notified = $notified;
return $this;
}
public function getVerifiedAt(): ?DateTimeImmutable
{
return $this->verifiedAt;
}
public function setVerifiedAt(?DateTimeImmutable $verifiedAt): self
{
$this->verifiedAt = $verifiedAt;
return $this;
}
public function getSummaryTitle(): ?string
{
$summaryTitle = (int) $this->getAverage();
$summaryTitle = (!empty($summaryTitle) ? $summaryTitle.'/10'.((null !== $this->getTitle()) ? ' - ' : '') : '');
$summaryTitle .= (null !== $this->getTitle() ? $this->getTitle() : '');
return $summaryTitle;
}
public function getSummaryDescription(): ?string
{
$summaryDescription = $this->getContent();
if (empty($summaryDescription)) {
$summaryDescription = sprintf('Diversity Across Organization: %d - Diversity In Leadership: %d - Work / Life Balance: %d - Overall Inclusiveness: %d - Benefits & Resources: %d - eNPS: %d ', $this->getDiversityAcrossOrganization(), $this->getDiversityInLeadership(), $this->getWorkLikeBalance(), $this->getOverallInclusiveness(), $this->getBenefitsAndResources(), $this->getEnps());
}
return $summaryDescription;
}
/**
* @return Collection|UserComment[]
*/
public function getUserComments(): Collection
{
return $this->userComments;
}
public function addUserComment(UserComment $userComment): self
{
if (!$this->userComments->contains($userComment)) {
$this->userComments[] = $userComment;
$userComment->setReview($this);
}
return $this;
}
public function removeUserComment(UserComment $userComment): self
{
if ($this->userComments->contains($userComment)) {
$this->userComments->removeElement($userComment);
// set the owning side to null (unless already changed)
if ($userComment->getReview() === $this) {
$userComment->setReview(null);
}
}
return $this;
}
public function getNbComments(): ?int
{
return $this->nb_comments;
}
public function setNbComments(int $nb_comments): self
{
$this->nb_comments = $nb_comments;
return $this;
}
}