src/Entity/Review.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator\ReviewValid;
  4. use DateTime;
  5. use DateTimeImmutable;
  6. use DateTimeInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\ReviewRepository")
  14.  * @ReviewValid()
  15.  */
  16. class Review
  17. {
  18.     use TimestampableEntity;
  19.     /**
  20.      * @var DateTime
  21.      *
  22.      * @ORM\Column(type="datetime")
  23.      */
  24.     protected $publishedAt;
  25.     /**
  26.      * @ORM\Id()
  27.      * @ORM\GeneratedValue()
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      * @Assert\Length(max=255)
  34.      */
  35.     private $title;
  36.     /**
  37.      * @ORM\Column(type="text", nullable=true)
  38.      * @Assert\NotBlank(groups={"ReviewContent"})
  39.      */
  40.     private $content;
  41.     /**
  42.      * @ORM\Column(type="smallint", nullable=true)
  43.      * @Assert\NotBlank(groups={"ReviewScores"})
  44.      * @Assert\Range(min="0", max="10", groups={"ReviewScores"})
  45.      */
  46.     private $diversityAcrossOrganization;
  47.     /**
  48.      * @ORM\Column(type="smallint", nullable=true)
  49.      * @Assert\NotBlank(groups={"ReviewScores"})
  50.      * @Assert\Range(min="0", max="10", groups={"ReviewScores"})
  51.      */
  52.     private $diversityInLeadership;
  53.     /**
  54.      * @ORM\Column(type="smallint", nullable=true)
  55.      * @Assert\NotBlank(groups={"ReviewScores"})
  56.      * @Assert\Range(min="0", max="10", groups={"ReviewScores"})
  57.      */
  58.     private $workLikeBalance;
  59.     /**
  60.      * @ORM\Column(type="smallint", nullable=true)
  61.      * @Assert\NotBlank(groups={"ReviewScores"})
  62.      * @Assert\Range(min="0", max="10", groups={"ReviewScores"})
  63.      */
  64.     private $overallInclusiveness;
  65.     /**
  66.      * @ORM\Column(type="smallint",  nullable=true)
  67.      * @Assert\NotBlank(groups={"ReviewScores"})
  68.      * @Assert\Range(min="0", max="10", groups={"ReviewScores"})
  69.      */
  70.     private $benefitsAndResources;
  71.     /**
  72.      * @ORM\Column(type="decimal", precision=8, scale=6, nullable=true)
  73.      * @Assert\Range(min="0", max="10")
  74.      */
  75.     private $enps;
  76.     /**
  77.      * @ORM\Column(type="decimal", precision=8, scale=6, nullable=true)
  78.      * @Assert\Range(min="0", max="10")
  79.      */
  80.     private $average;
  81.     /**
  82.      * @ORM\Column(type="integer", options={"unsigned"=true})
  83.      */
  84.     private $nbLikes;
  85.     /**
  86.      * @ORM\Column(type="boolean")
  87.      * @Assert\Type(type="boolean")
  88.      */
  89.     private $isAnonymous;
  90.     /**
  91.      * @ORM\Column(type="text", nullable=true)
  92.      */
  93.     private $companyAnswer;
  94.     /**
  95.      * @ORM\Column(type="datetime", nullable=true)
  96.      */
  97.     private $companyAnswerAt;
  98.     /**
  99.      * @ORM\ManyToOne(targetEntity="App\Entity\Company",inversedBy="reviews")
  100.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  101.      */
  102.     private $company;
  103.     /**
  104.      * @ORM\Column(type="text", nullable=true)
  105.      */
  106.     private $companyNotExisting;
  107.     /**
  108.      * @ORM\ManyToOne(targetEntity="App\Entity\User",inversedBy="reviews")
  109.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  110.      */
  111.     private $user;
  112.     /**
  113.      * @ORM\OneToMany(targetEntity="App\Entity\UserLike", mappedBy="review", cascade={"persist"})
  114.      */
  115.     private $userLikes;
  116.     /**
  117.      * @ORM\ManyToMany(targetEntity="App\Entity\ReviewTag")
  118.      */
  119.     private $reviewTags;
  120.     /**
  121.      * @ORM\OneToMany(targetEntity="App\Entity\UserShare", mappedBy="review", cascade={"persist"})
  122.      */
  123.     private $userShares;
  124.     /**
  125.      * @ORM\Column(type="integer")
  126.      */
  127.     private $nbShares;
  128.     /**
  129.      * @ORM\Column(type="boolean")
  130.      * @Assert\Type(type="boolean")
  131.      */
  132.     private $flagged;
  133.     /**
  134.      * @ORM\Column(type="boolean")
  135.      * @Assert\Type(type="boolean")
  136.      */
  137.     private $blocked;
  138.     /**
  139.      * @ORM\Column(type="boolean")
  140.      * @Assert\Type(type="boolean")
  141.      */
  142.     private $notified;
  143.     /**
  144.      * @var DateTimeImmutable
  145.      *
  146.      * @ORM\Column(type="datetimetz_immutable", nullable=true)
  147.      */
  148.     private $verifiedAt;
  149.     /**
  150.      * @ORM\Column(type="boolean")
  151.      * @Assert\Type(type="boolean")
  152.      */
  153.     private $verified;
  154.     /**
  155.      * @ORM\Column(type="boolean")
  156.      * @Assert\Type(type="boolean")
  157.      */
  158.     private $notRated;
  159.     /**
  160.      * virtual property.
  161.      */
  162.     private $summaryTitle;
  163.     /**
  164.      * virtual property.
  165.      */
  166.     private $summaryDescription;
  167.     /**
  168.      * @ORM\OneToMany(targetEntity="App\Entity\UserComment", mappedBy="review")
  169.      */
  170.     private $userComments;
  171.     /**
  172.      * @ORM\Column(type="integer")
  173.      */
  174.     private $nb_comments;
  175.     public function __construct()
  176.     {
  177.         $this->reviewTags = new ArrayCollection();
  178.         $this->nbLikes 0;
  179.         $this->isAnonymous true;
  180.         $this->userLikes = new ArrayCollection();
  181.         $this->userShares = new ArrayCollection();
  182.         $this->nbShares 0;
  183.         $this->flagged false;
  184.         $this->blocked false;
  185.         $this->verified false;
  186.         $this->createdAt = new \DateTime();
  187.         $this->publishedAt = new DateTime('+3 hours');
  188.         $this->updatedAt = new \DateTime();
  189.         $this->notRated false;
  190.         $this->notified false;
  191.         $this->userComments = new ArrayCollection();
  192.     }
  193.     /**
  194.      * @return mixed
  195.      */
  196.     public function __toString()
  197.     {
  198.         return $this->title ?? '';
  199.     }
  200.     public function getId(): ?int
  201.     {
  202.         return $this->id;
  203.     }
  204.     public function getTitle(): ?string
  205.     {
  206.         return $this->title;
  207.     }
  208.     public function setTitle(?string $title): self
  209.     {
  210.         $this->title $title;
  211.         return $this;
  212.     }
  213.     public function getContent(): ?string
  214.     {
  215.         return $this->content;
  216.     }
  217.     public function setContent(?string $content): self
  218.     {
  219.         $this->content $content;
  220.         return $this;
  221.     }
  222.     public function getDiversityAcrossOrganization(): ?int
  223.     {
  224.         return $this->diversityAcrossOrganization;
  225.     }
  226.     public function setDiversityAcrossOrganization(?int $diversityAcrossOrganization): self
  227.     {
  228.         $this->diversityAcrossOrganization $diversityAcrossOrganization;
  229.         return $this;
  230.     }
  231.     public function getDiversityInLeadership(): ?int
  232.     {
  233.         return $this->diversityInLeadership;
  234.     }
  235.     public function setDiversityInLeadership(?int $diversityInLeadership): self
  236.     {
  237.         $this->diversityInLeadership $diversityInLeadership;
  238.         return $this;
  239.     }
  240.     public function getWorkLikeBalance(): ?int
  241.     {
  242.         return $this->workLikeBalance;
  243.     }
  244.     public function setWorkLikeBalance(?int $workLikeBalance): self
  245.     {
  246.         $this->workLikeBalance $workLikeBalance;
  247.         return $this;
  248.     }
  249.     public function getOverallInclusiveness(): ?int
  250.     {
  251.         return $this->overallInclusiveness;
  252.     }
  253.     public function setOverallInclusiveness(?int $overallInclusiveness): self
  254.     {
  255.         $this->overallInclusiveness $overallInclusiveness;
  256.         return $this;
  257.     }
  258.     public function getBenefitsAndResources(): ?int
  259.     {
  260.         return $this->benefitsAndResources;
  261.     }
  262.     public function setBenefitsAndResources(?int $benefitsAndResources): self
  263.     {
  264.         $this->benefitsAndResources $benefitsAndResources;
  265.         return $this;
  266.     }
  267.     public function getEnps(): ?int
  268.     {
  269.         return $this->enps;
  270.     }
  271.     public function setEnps(?int $enps): self
  272.     {
  273.         $this->enps $enps;
  274.         return $this;
  275.     }
  276.     public function getAverage()
  277.     {
  278.         return $this->average;
  279.     }
  280.     public function setAverage($average): self
  281.     {
  282.         $this->average $average;
  283.         return $this;
  284.     }
  285.     public function getNbLikes(): ?int
  286.     {
  287.         return $this->nbLikes;
  288.     }
  289.     public function setNbLikes(int $nbLikes): self
  290.     {
  291.         $this->nbLikes $nbLikes;
  292.         return $this;
  293.     }
  294.     public function getIsAnonymous(): ?bool
  295.     {
  296.         return $this->isAnonymous;
  297.     }
  298.     public function setIsAnonymous(bool $isAnonymous): self
  299.     {
  300.         $this->isAnonymous $isAnonymous;
  301.         return $this;
  302.     }
  303.     public function getCompanyAnswer(): ?string
  304.     {
  305.         return $this->companyAnswer;
  306.     }
  307.     public function setCompanyAnswer(?string $companyAnswer): self
  308.     {
  309.         $this->companyAnswer $companyAnswer;
  310.         return $this;
  311.     }
  312.     public function getCompanyAnswerAt(): ?DateTimeInterface
  313.     {
  314.         return $this->companyAnswerAt;
  315.     }
  316.     public function setCompanyAnswerAt(?DateTimeInterface $companyAnswerAt): self
  317.     {
  318.         $this->companyAnswerAt $companyAnswerAt;
  319.         return $this;
  320.     }
  321.     public function getNbShares(): ?int
  322.     {
  323.         return $this->nbShares;
  324.     }
  325.     public function setNbShares(int $nbShares): self
  326.     {
  327.         $this->nbShares $nbShares;
  328.         return $this;
  329.     }
  330.     public function getFlagged(): ?bool
  331.     {
  332.         return $this->flagged;
  333.     }
  334.     public function setFlagged(bool $flagged): self
  335.     {
  336.         $this->flagged $flagged;
  337.         return $this;
  338.     }
  339.     public function getBlocked(): ?bool
  340.     {
  341.         return $this->blocked;
  342.     }
  343.     public function setBlocked(bool $blocked): self
  344.     {
  345.         $this->blocked $blocked;
  346.         return $this;
  347.     }
  348.     public function getVerified(): ?bool
  349.     {
  350.         return $this->verified;
  351.     }
  352.     public function setVerified(bool $verified): self
  353.     {
  354.         $this->verified $verified;
  355.         return $this;
  356.     }
  357.     public function getPublishedAt(): ?DateTimeInterface
  358.     {
  359.         return $this->publishedAt;
  360.     }
  361.     public function setPublishedAt(DateTimeInterface $publishedAt): self
  362.     {
  363.         $this->publishedAt $publishedAt;
  364.         return $this;
  365.     }
  366.     public function getCompany(): ?Company
  367.     {
  368.         return $this->company;
  369.     }
  370.     public function setCompany(?Company $company): self
  371.     {
  372.         $this->company $company;
  373.         return $this;
  374.     }
  375.     public function getCompanyNotExisting(): ?string
  376.     {
  377.         return $this->companyNotExisting;
  378.     }
  379.     public function setCompanyNotExisting(?string $companyNotExisting): self
  380.     {
  381.         $this->companyNotExisting $companyNotExisting;
  382.         return $this;
  383.     }
  384.     public function getUser(): ?User
  385.     {
  386.         return $this->user;
  387.     }
  388.     public function setUser(?User $user): self
  389.     {
  390.         $this->user $user;
  391.         return $this;
  392.     }
  393.     /**
  394.      * @return Collection|UserLike[]
  395.      */
  396.     public function getUserLikes(): Collection
  397.     {
  398.         return $this->userLikes;
  399.     }
  400.     public function addUserLike(UserLike $userLike): self
  401.     {
  402.         if (!$this->userLikes->contains($userLike)) {
  403.             $this->userLikes[] = $userLike;
  404.             $userLike->setReview($this);
  405.         }
  406.         return $this;
  407.     }
  408.     public function removeUserLike(UserLike $userLike): self
  409.     {
  410.         if ($this->userLikes->contains($userLike)) {
  411.             $this->userLikes->removeElement($userLike);
  412.             // set the owning side to null (unless already changed)
  413.             if ($userLike->getReview() === $this) {
  414.                 $userLike->setReview(null);
  415.             }
  416.         }
  417.         return $this;
  418.     }
  419.     /**
  420.      * @return Collection|ReviewTag[]
  421.      */
  422.     public function getReviewTags(): Collection
  423.     {
  424.         return $this->reviewTags;
  425.     }
  426.     public function addReviewTag(ReviewTag $reviewTag): self
  427.     {
  428.         if (!$this->reviewTags->contains($reviewTag)) {
  429.             $this->reviewTags[] = $reviewTag;
  430.         }
  431.         return $this;
  432.     }
  433.     public function removeReviewTag(ReviewTag $reviewTag): self
  434.     {
  435.         if ($this->reviewTags->contains($reviewTag)) {
  436.             $this->reviewTags->removeElement($reviewTag);
  437.         }
  438.         return $this;
  439.     }
  440.     /**
  441.      * @return Collection|UserShare[]
  442.      */
  443.     public function getUserShares(): Collection
  444.     {
  445.         return $this->userShares;
  446.     }
  447.     public function addUserShare(UserShare $userShare): self
  448.     {
  449.         if (!$this->userShares->contains($userShare)) {
  450.             $this->userShares[] = $userShare;
  451.             $userShare->setReview($this);
  452.         }
  453.         return $this;
  454.     }
  455.     public function removeUserShare(UserShare $userShare): self
  456.     {
  457.         if ($this->userShares->contains($userShare)) {
  458.             $this->userShares->removeElement($userShare);
  459.             // set the owning side to null (unless already changed)
  460.             if ($userShare->getReview() === $this) {
  461.                 $userShare->setReview(null);
  462.             }
  463.         }
  464.         return $this;
  465.     }
  466.     public function getNotRated(): ?bool
  467.     {
  468.         return $this->notRated;
  469.     }
  470.     public function setNotRated(bool $notRated): self
  471.     {
  472.         $this->notRated $notRated;
  473.         return $this;
  474.     }
  475.     public function getNotified(): ?bool
  476.     {
  477.         return $this->notified;
  478.     }
  479.     public function setNotified(bool $notified): self
  480.     {
  481.         $this->notified $notified;
  482.         return $this;
  483.     }
  484.     public function getVerifiedAt(): ?DateTimeImmutable
  485.     {
  486.         return $this->verifiedAt;
  487.     }
  488.     public function setVerifiedAt(?DateTimeImmutable $verifiedAt): self
  489.     {
  490.         $this->verifiedAt $verifiedAt;
  491.         return $this;
  492.     }
  493.     public function getSummaryTitle(): ?string
  494.     {
  495.         $summaryTitle = (int) $this->getAverage();
  496.         $summaryTitle = (!empty($summaryTitle) ? $summaryTitle.'/10'.((null !== $this->getTitle()) ? ' - ' '') : '');
  497.         $summaryTitle .= (null !== $this->getTitle() ? $this->getTitle() : '');
  498.         return $summaryTitle;
  499.     }
  500.     public function getSummaryDescription(): ?string
  501.     {
  502.         $summaryDescription $this->getContent();
  503.         if (empty($summaryDescription)) {
  504.             $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());
  505.         }
  506.         return $summaryDescription;
  507.     }
  508.     /**
  509.      * @return Collection|UserComment[]
  510.      */
  511.     public function getUserComments(): Collection
  512.     {
  513.         return $this->userComments;
  514.     }
  515.     public function addUserComment(UserComment $userComment): self
  516.     {
  517.         if (!$this->userComments->contains($userComment)) {
  518.             $this->userComments[] = $userComment;
  519.             $userComment->setReview($this);
  520.         }
  521.         return $this;
  522.     }
  523.     public function removeUserComment(UserComment $userComment): self
  524.     {
  525.         if ($this->userComments->contains($userComment)) {
  526.             $this->userComments->removeElement($userComment);
  527.             // set the owning side to null (unless already changed)
  528.             if ($userComment->getReview() === $this) {
  529.                 $userComment->setReview(null);
  530.             }
  531.         }
  532.         return $this;
  533.     }
  534.     public function getNbComments(): ?int
  535.     {
  536.         return $this->nb_comments;
  537.     }
  538.     public function setNbComments(int $nb_comments): self
  539.     {
  540.         $this->nb_comments $nb_comments;
  541.         return $this;
  542.     }
  543. }