src/Entity/Blog.php line 28

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