src/Entity/Newsroom.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator as AppAssert;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Exception;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Greg0ire\Enum\Bridge\Symfony\Validator\Constraint\Enum as EnumAssert;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. /**
  17.  * @ORM\Entity(repositoryClass="App\Repository\NewsroomRepository")
  18.  * @Vich\Uploadable
  19.  * @AppAssert\DynamicValidationGroups(property="type", value="App\Enum\NewsroomType::INTERNAL", validationGroups={"TypeInternal"})
  20.  * @AppAssert\DynamicValidationGroups(property="type", value="App\Enum\NewsroomType::EXTERNAL", validationGroups={"TypeExternal"})
  21.  */
  22. class Newsroom
  23. {
  24.     use TimestampableEntity;
  25.     /**
  26.      * @ORM\Id()
  27.      * @ORM\GeneratedValue()
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=128)
  33.      * @Assert\NotBlank()
  34.      * @Assert\Length(max="128")
  35.      */
  36.     private $title;
  37.     /**
  38.      * @ORM\Column(type="string", length=128)
  39.      * @Gedmo\Slug(fields={"title"})
  40.      */
  41.     private $slug;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $author;
  46.     /**
  47.      * @ORM\Column(type="text")
  48.      * @Assert\NotBlank()
  49.      */
  50.     private $excerpt;
  51.     /**
  52.      * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="newsrooms")
  53.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  54.      */
  55.     private $company;
  56.     /**
  57.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  58.      */
  59.     private $image;
  60.     /**
  61.      * @Vich\UploadableField(mapping="newsroom_image", fileNameProperty="image.name",
  62.      *     size="image.size", mimeType="image.mimeType",
  63.      *     originalName="image.originalName",
  64.      *     dimensions="image.dimensions")
  65.      * @Assert\Image(
  66.      *     mimeTypes={"image/jpeg", "image/png", "image/gif"},
  67.      *     mimeTypesMessage="Allowed formats : .png, .jpeg, .jpg, gif "
  68.      *     )
  69.      */
  70.     private $imageFile;
  71.     /**
  72.      * @var string
  73.      *
  74.      * @ORM\Column(type="string", length=255)
  75.      */
  76.     private $imageAlt;
  77.     /**
  78.      * @var string
  79.      *
  80.      * @ORM\Column(type="string", length=64, nullable=false)
  81.      * @Assert\Length(max=64)
  82.      * @EnumAssert(class="App\Enum\NewsroomType")
  83.      * @Assert\NotBlank()
  84.      */
  85.     private $type;
  86.     /**
  87.      * @ORM\Column(type="text", nullable=true)
  88.      * @Assert\NotBlank(groups={"TypeInternal"})
  89.      */
  90.     private $content;
  91.     /**
  92.      * @ORM\Column(type="string", length=255, nullable=true)
  93.      * @Assert\Url()
  94.      * @Assert\NotBlank(groups={"TypeExternal"})
  95.      */
  96.     private $externalLink;
  97.     /**
  98.      * @ORM\Column(type="boolean")
  99.      * @Assert\Type("bool")
  100.      */
  101.     private $published;
  102.     /**
  103.      * @ORM\OneToMany(targetEntity="App\Entity\UserLike", mappedBy="newsroom", cascade={"persist"})
  104.      */
  105.     private $userLikes;
  106.     /**
  107.      * @ORM\Column(type="integer")
  108.      */
  109.     private $nbLikes;
  110.     /**
  111.      * @ORM\OneToMany(targetEntity="App\Entity\UserNewsroomComment", mappedBy="newsroom", orphanRemoval=true, cascade={"persist"})
  112.      */
  113.     private $userComments;
  114.     /**
  115.      * @ORM\Column(type="integer")
  116.      */
  117.     private $nbComments;
  118.     /**
  119.      * @ORM\Column(type="integer")
  120.      */
  121.     private $nbShares;
  122.     /**
  123.      * @ORM\OneToMany(targetEntity="App\Entity\UserShare", mappedBy="newsroom", cascade={"persist"})
  124.      */
  125.     private $userShares;
  126.     /**
  127.      * @ORM\OneToMany(targetEntity="App\Entity\FeedItem", cascade={"persist"}, mappedBy="newsroom", orphanRemoval=true)
  128.      */
  129.     private $feedItems;
  130.     /**
  131.      * @ORM\Column(type="boolean")
  132.      * @Assert\Type("bool")
  133.      */
  134.     private $highlighted;
  135.     /**
  136.      * @ORM\Column(type="boolean")
  137.      * @Assert\Type("bool")
  138.      */
  139.     private $announcement;
  140.     /**
  141.      * @var ArrayCollection
  142.      *
  143.      * @ORM\ManyToMany(targetEntity="App\Entity\Benefit")
  144.      */
  145.     private $benefits;
  146.     /**
  147.      * @var ArrayCollection
  148.      *
  149.      * @ORM\ManyToMany(targetEntity="App\Entity\SocialGroupIssue")
  150.      */
  151.     private $socialGroupIssues;
  152.     /**
  153.      * @ORM\Column(type="boolean")
  154.      * @Assert\Type("bool")
  155.      */
  156.     private $isDiNews;
  157.     /**
  158.      * @ORM\Column(type="boolean")
  159.      * @Assert\Type("bool")
  160.      */
  161.     private $isVideo;
  162.     /**
  163.      * Newsroom constructor.
  164.      */
  165.     public function __construct()
  166.     {
  167.         $this->published true;
  168.         $this->image = new EmbeddedFile();
  169.         $this->userLikes = new ArrayCollection();
  170.         $this->nbLikes 0;
  171.         $this->userComments = new ArrayCollection();
  172.         $this->nbComments 0;
  173.         $this->userShares = new ArrayCollection();
  174.         $this->nbShares 0;
  175.         $this->feedItems = new ArrayCollection();
  176.         $this->highlighted false;
  177.         $this->announcement false;
  178.         $this->benefits = new ArrayCollection();
  179.         $this->socialGroupIssues = new ArrayCollection();
  180.         $this->isDiNews false;
  181.         $this->isVideo false;
  182.     }
  183.     public function __toString()
  184.     {
  185.         return $this->title;
  186.     }
  187.     public function getId(): ?int
  188.     {
  189.         return $this->id;
  190.     }
  191.     public function getTitle(): ?string
  192.     {
  193.         return $this->title;
  194.     }
  195.     public function setTitle(string $title): self
  196.     {
  197.         $this->title $title;
  198.         return $this;
  199.     }
  200.     public function getAuthor(): ?string
  201.     {
  202.         return $this->author;
  203.     }
  204.     public function setAuthor(?string $author): self
  205.     {
  206.         $this->author $author;
  207.         return $this;
  208.     }
  209.     public function getContent(): ?string
  210.     {
  211.         return $this->content;
  212.     }
  213.     public function setContent(?string $content): self
  214.     {
  215.         $this->content $content;
  216.         return $this;
  217.     }
  218.     public function getExcerpt(): ?string
  219.     {
  220.         return $this->excerpt;
  221.     }
  222.     public function setExcerpt(string $excerpt): self
  223.     {
  224.         $this->excerpt $excerpt;
  225.         return $this;
  226.     }
  227.     public function getSlug(): ?string
  228.     {
  229.         return $this->slug;
  230.     }
  231.     public function setSlug(string $slug): self
  232.     {
  233.         $this->slug $slug;
  234.         return $this;
  235.     }
  236.     public function getPublished(): ?bool
  237.     {
  238.         return $this->published;
  239.     }
  240.     public function setPublished(bool $published): self
  241.     {
  242.         $this->published $published;
  243.         return $this;
  244.     }
  245.     public function getExternalLink(): ?string
  246.     {
  247.         return $this->externalLink;
  248.     }
  249.     public function setExternalLink(?string $externalLink): self
  250.     {
  251.         $this->externalLink $externalLink;
  252.         return $this;
  253.     }
  254.     public function getType(): ?string
  255.     {
  256.         return $this->type;
  257.     }
  258.     public function setType(string $type): self
  259.     {
  260.         $this->type $type;
  261.         return $this;
  262.     }
  263.     public function getCompany(): ?Company
  264.     {
  265.         return $this->company;
  266.     }
  267.     public function setCompany(?Company $company): self
  268.     {
  269.         $this->company $company;
  270.         return $this;
  271.     }
  272.     public function getImageFile(): ?File
  273.     {
  274.         return $this->imageFile;
  275.     }
  276.     /**
  277.      * @throws Exception
  278.      */
  279.     public function setImageFile(?File $image): self
  280.     {
  281.         $this->imageFile $image;
  282.         if ($image) {
  283.             $this->updatedAt = new DateTime();
  284.         }
  285.         return $this;
  286.     }
  287.     public function getImage(): EmbeddedFile
  288.     {
  289.         return $this->image;
  290.     }
  291.     public function setImage(EmbeddedFile $image): self
  292.     {
  293.         $this->image $image;
  294.         return $this;
  295.     }
  296.     public function setImageAlt(?string $imageAlt): self
  297.     {
  298.         $this->imageAlt $imageAlt;
  299.         return $this;
  300.     }
  301.     public function getImageAlt(): ?string
  302.     {
  303.         return $this->imageAlt;
  304.     }
  305.     /**
  306.      * @return Collection|UserLike[]
  307.      */
  308.     public function getUserLikes(): Collection
  309.     {
  310.         return $this->userLikes;
  311.     }
  312.     public function addUserLike(UserLike $userLike): self
  313.     {
  314.         if (!$this->userLikes->contains($userLike)) {
  315.             $this->userLikes[] = $userLike;
  316.             $userLike->setNewsroom($this);
  317.         }
  318.         return $this;
  319.     }
  320.     public function removeUserLike(UserLike $userLike): self
  321.     {
  322.         if ($this->userLikes->contains($userLike)) {
  323.             $this->userLikes->removeElement($userLike);
  324.             // set the owning side to null (unless already changed)
  325.             if ($userLike->getNewsroom() === $this) {
  326.                 $userLike->setNewsroom(null);
  327.             }
  328.         }
  329.         return $this;
  330.     }
  331.     public function getNbLikes(): ?int
  332.     {
  333.         return $this->nbLikes;
  334.     }
  335.     public function setNbLikes(int $nbLikes): self
  336.     {
  337.         $this->nbLikes $nbLikes;
  338.         return $this;
  339.     }
  340.     /**
  341.      * @return Collection|UserNewsroomComment[]
  342.      */
  343.     public function getUserComments(): Collection
  344.     {
  345.         return $this->userComments;
  346.     }
  347.     public function addUserComment(UserNewsroomComment $userComment): self
  348.     {
  349.         if (!$this->userComments->contains($userComment)) {
  350.             $this->userComments[] = $userComment;
  351.             $userComment->setNewsroom($this);
  352.         }
  353.         return $this;
  354.     }
  355.     public function removeUserComment(UserNewsroomComment $userComment): self
  356.     {
  357.         if ($this->userComments->contains($userComment)) {
  358.             $this->userComments->removeElement($userComment);
  359.             // set the owning side to null (unless already changed)
  360.             if ($userComment->getNewsroom() === $this) {
  361.                 $userComment->setNewsroom(null);
  362.             }
  363.         }
  364.         return $this;
  365.     }
  366.     public function getNbComments(): int
  367.     {
  368.         return $this->nbComments;
  369.     }
  370.     public function setNbComments(int $nbComments): self
  371.     {
  372.         $this->nbComments $nbComments;
  373.         return $this;
  374.     }
  375.     /**
  376.      * @return Collection|UserShare[]
  377.      */
  378.     public function getUserShares(): Collection
  379.     {
  380.         return $this->userShares;
  381.     }
  382.     public function addUserShare(UserShare $userShare): self
  383.     {
  384.         if (!$this->userShares->contains($userShare)) {
  385.             $this->userShares[] = $userShare;
  386.             $userShare->setNewsroom($this);
  387.         }
  388.         return $this;
  389.     }
  390.     public function removeUserShare(UserShare $userShare): self
  391.     {
  392.         if ($this->userShares->contains($userShare)) {
  393.             $this->userShares->removeElement($userShare);
  394.             // set the owning side to null (unless already changed)
  395.             if ($userShare->getNewsroom() === $this) {
  396.                 $userShare->setNewsroom(null);
  397.             }
  398.         }
  399.         return $this;
  400.     }
  401.     public function getNbShares(): ?int
  402.     {
  403.         return $this->nbShares;
  404.     }
  405.     public function setNbShares(int $nbShares): self
  406.     {
  407.         $this->nbShares $nbShares;
  408.         return $this;
  409.     }
  410.     /**
  411.      * @return Collection|FeedItem[]
  412.      */
  413.     public function getFeedItems(): Collection
  414.     {
  415.         return $this->feedItems;
  416.     }
  417.     public function addFeedItem(FeedItem $feedItem): self
  418.     {
  419.         if (!$this->feedItems->contains($feedItem)) {
  420.             $this->feedItems[] = $feedItem;
  421.             $feedItem->setNewsroom($this);
  422.         }
  423.         return $this;
  424.     }
  425.     public function removeFeedItem(FeedItem $feedItem): self
  426.     {
  427.         if ($this->feedItems->contains($feedItem)) {
  428.             $this->feedItems->removeElement($feedItem);
  429.             // set the owning side to null (unless already changed)
  430.             if ($feedItem->getNewsroom() === $this) {
  431.                 $feedItem->setNewsroom(null);
  432.             }
  433.         }
  434.         return $this;
  435.     }
  436.     public function getHighlighted(): ?bool
  437.     {
  438.         return $this->highlighted;
  439.     }
  440.     public function setHighlighted(bool $highlighted): self
  441.     {
  442.         $this->highlighted $highlighted;
  443.         return $this;
  444.     }
  445.     public function getAnnouncement(): ?bool
  446.     {
  447.         return $this->announcement;
  448.     }
  449.     public function setAnnouncement(bool $announcement): self
  450.     {
  451.         $this->announcement $announcement;
  452.         return $this;
  453.     }
  454.     /**
  455.      * @return Collection|Benefit[]
  456.      */
  457.     public function getBenefits(): Collection
  458.     {
  459.         return $this->benefits;
  460.     }
  461.     public function addBenefit(Benefit $benefit): self
  462.     {
  463.         if (!$this->benefits->contains($benefit)) {
  464.             $this->benefits[] = $benefit;
  465.         }
  466.         return $this;
  467.     }
  468.     public function removeBenefit(Benefit $benefit): self
  469.     {
  470.         if ($this->benefits->contains($benefit)) {
  471.             $this->benefits->removeElement($benefit);
  472.         }
  473.         return $this;
  474.     }
  475.     /**
  476.      * @return Collection|SocialGroupIssue[]
  477.      */
  478.     public function getSocialGroupIssues(): Collection
  479.     {
  480.         return $this->socialGroupIssues;
  481.     }
  482.     public function addSocialGroupIssue(SocialGroupIssue $socialGroupIssue): self
  483.     {
  484.         if (!$this->socialGroupIssues->contains($socialGroupIssue)) {
  485.             $this->socialGroupIssues[] = $socialGroupIssue;
  486.         }
  487.         return $this;
  488.     }
  489.     public function removeSocialGroupIssue(SocialGroupIssue $socialGroupIssue): self
  490.     {
  491.         if ($this->socialGroupIssues->contains($socialGroupIssue)) {
  492.             $this->socialGroupIssues->removeElement($socialGroupIssue);
  493.         }
  494.         return $this;
  495.     }
  496.     public function getIsDiNews(): ?bool
  497.     {
  498.         return $this->isDiNews;
  499.     }
  500.     public function setIsDiNews(bool $isDiNews): self
  501.     {
  502.         $this->isDiNews $isDiNews;
  503.         return $this;
  504.     }
  505.     public function getIsVideo(): ?bool
  506.     {
  507.         return $this->isVideo;
  508.     }
  509.     public function setIsVideo(bool $isVideo): self
  510.     {
  511.         $this->isVideo $isVideo;
  512.         return $this;
  513.     }
  514. }