<?php
namespace App\Entity;
use App\Validator as AppAssert;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Greg0ire\Enum\Bridge\Symfony\Validator\Constraint\Enum as EnumAssert;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\NewsroomRepository")
* @Vich\Uploadable
* @AppAssert\DynamicValidationGroups(property="type", value="App\Enum\NewsroomType::INTERNAL", validationGroups={"TypeInternal"})
* @AppAssert\DynamicValidationGroups(property="type", value="App\Enum\NewsroomType::EXTERNAL", validationGroups={"TypeExternal"})
*/
class Newsroom
{
use TimestampableEntity;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
* @Assert\NotBlank()
* @Assert\Length(max="128")
*/
private $title;
/**
* @ORM\Column(type="string", length=128)
* @Gedmo\Slug(fields={"title"})
*/
private $slug;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $author;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank()
*/
private $excerpt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="newsrooms")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $company;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*/
private $image;
/**
* @Vich\UploadableField(mapping="newsroom_image", fileNameProperty="image.name",
* size="image.size", mimeType="image.mimeType",
* originalName="image.originalName",
* dimensions="image.dimensions")
* @Assert\Image(
* mimeTypes={"image/jpeg", "image/png", "image/gif"},
* mimeTypesMessage="Allowed formats : .png, .jpeg, .jpg, gif "
* )
*/
private $imageFile;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $imageAlt;
/**
* @var string
*
* @ORM\Column(type="string", length=64, nullable=false)
* @Assert\Length(max=64)
* @EnumAssert(class="App\Enum\NewsroomType")
* @Assert\NotBlank()
*/
private $type;
/**
* @ORM\Column(type="text", nullable=true)
* @Assert\NotBlank(groups={"TypeInternal"})
*/
private $content;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Url()
* @Assert\NotBlank(groups={"TypeExternal"})
*/
private $externalLink;
/**
* @ORM\Column(type="boolean")
* @Assert\Type("bool")
*/
private $published;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserLike", mappedBy="newsroom", cascade={"persist"})
*/
private $userLikes;
/**
* @ORM\Column(type="integer")
*/
private $nbLikes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserNewsroomComment", mappedBy="newsroom", orphanRemoval=true, cascade={"persist"})
*/
private $userComments;
/**
* @ORM\Column(type="integer")
*/
private $nbComments;
/**
* @ORM\Column(type="integer")
*/
private $nbShares;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserShare", mappedBy="newsroom", cascade={"persist"})
*/
private $userShares;
/**
* @ORM\OneToMany(targetEntity="App\Entity\FeedItem", cascade={"persist"}, mappedBy="newsroom", orphanRemoval=true)
*/
private $feedItems;
/**
* @ORM\Column(type="boolean")
* @Assert\Type("bool")
*/
private $highlighted;
/**
* @ORM\Column(type="boolean")
* @Assert\Type("bool")
*/
private $announcement;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Benefit")
*/
private $benefits;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="App\Entity\SocialGroupIssue")
*/
private $socialGroupIssues;
/**
* @ORM\Column(type="boolean")
* @Assert\Type("bool")
*/
private $isDiNews;
/**
* @ORM\Column(type="boolean")
* @Assert\Type("bool")
*/
private $isVideo;
/**
* Newsroom constructor.
*/
public function __construct()
{
$this->published = true;
$this->image = new EmbeddedFile();
$this->userLikes = new ArrayCollection();
$this->nbLikes = 0;
$this->userComments = new ArrayCollection();
$this->nbComments = 0;
$this->userShares = new ArrayCollection();
$this->nbShares = 0;
$this->feedItems = new ArrayCollection();
$this->highlighted = false;
$this->announcement = false;
$this->benefits = new ArrayCollection();
$this->socialGroupIssues = new ArrayCollection();
$this->isDiNews = false;
$this->isVideo = false;
}
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 getAuthor(): ?string
{
return $this->author;
}
public function setAuthor(?string $author): self
{
$this->author = $author;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getExcerpt(): ?string
{
return $this->excerpt;
}
public function setExcerpt(string $excerpt): self
{
$this->excerpt = $excerpt;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): self
{
$this->published = $published;
return $this;
}
public function getExternalLink(): ?string
{
return $this->externalLink;
}
public function setExternalLink(?string $externalLink): self
{
$this->externalLink = $externalLink;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @throws Exception
*/
public function setImageFile(?File $image): self
{
$this->imageFile = $image;
if ($image) {
$this->updatedAt = new DateTime();
}
return $this;
}
public function getImage(): EmbeddedFile
{
return $this->image;
}
public function setImage(EmbeddedFile $image): self
{
$this->image = $image;
return $this;
}
public function setImageAlt(?string $imageAlt): self
{
$this->imageAlt = $imageAlt;
return $this;
}
public function getImageAlt(): ?string
{
return $this->imageAlt;
}
/**
* @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->setNewsroom($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->getNewsroom() === $this) {
$userLike->setNewsroom(null);
}
}
return $this;
}
public function getNbLikes(): ?int
{
return $this->nbLikes;
}
public function setNbLikes(int $nbLikes): self
{
$this->nbLikes = $nbLikes;
return $this;
}
/**
* @return Collection|UserNewsroomComment[]
*/
public function getUserComments(): Collection
{
return $this->userComments;
}
public function addUserComment(UserNewsroomComment $userComment): self
{
if (!$this->userComments->contains($userComment)) {
$this->userComments[] = $userComment;
$userComment->setNewsroom($this);
}
return $this;
}
public function removeUserComment(UserNewsroomComment $userComment): self
{
if ($this->userComments->contains($userComment)) {
$this->userComments->removeElement($userComment);
// set the owning side to null (unless already changed)
if ($userComment->getNewsroom() === $this) {
$userComment->setNewsroom(null);
}
}
return $this;
}
public function getNbComments(): int
{
return $this->nbComments;
}
public function setNbComments(int $nbComments): self
{
$this->nbComments = $nbComments;
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->setNewsroom($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->getNewsroom() === $this) {
$userShare->setNewsroom(null);
}
}
return $this;
}
public function getNbShares(): ?int
{
return $this->nbShares;
}
public function setNbShares(int $nbShares): self
{
$this->nbShares = $nbShares;
return $this;
}
/**
* @return Collection|FeedItem[]
*/
public function getFeedItems(): Collection
{
return $this->feedItems;
}
public function addFeedItem(FeedItem $feedItem): self
{
if (!$this->feedItems->contains($feedItem)) {
$this->feedItems[] = $feedItem;
$feedItem->setNewsroom($this);
}
return $this;
}
public function removeFeedItem(FeedItem $feedItem): self
{
if ($this->feedItems->contains($feedItem)) {
$this->feedItems->removeElement($feedItem);
// set the owning side to null (unless already changed)
if ($feedItem->getNewsroom() === $this) {
$feedItem->setNewsroom(null);
}
}
return $this;
}
public function getHighlighted(): ?bool
{
return $this->highlighted;
}
public function setHighlighted(bool $highlighted): self
{
$this->highlighted = $highlighted;
return $this;
}
public function getAnnouncement(): ?bool
{
return $this->announcement;
}
public function setAnnouncement(bool $announcement): self
{
$this->announcement = $announcement;
return $this;
}
/**
* @return Collection|Benefit[]
*/
public function getBenefits(): Collection
{
return $this->benefits;
}
public function addBenefit(Benefit $benefit): self
{
if (!$this->benefits->contains($benefit)) {
$this->benefits[] = $benefit;
}
return $this;
}
public function removeBenefit(Benefit $benefit): self
{
if ($this->benefits->contains($benefit)) {
$this->benefits->removeElement($benefit);
}
return $this;
}
/**
* @return Collection|SocialGroupIssue[]
*/
public function getSocialGroupIssues(): Collection
{
return $this->socialGroupIssues;
}
public function addSocialGroupIssue(SocialGroupIssue $socialGroupIssue): self
{
if (!$this->socialGroupIssues->contains($socialGroupIssue)) {
$this->socialGroupIssues[] = $socialGroupIssue;
}
return $this;
}
public function removeSocialGroupIssue(SocialGroupIssue $socialGroupIssue): self
{
if ($this->socialGroupIssues->contains($socialGroupIssue)) {
$this->socialGroupIssues->removeElement($socialGroupIssue);
}
return $this;
}
public function getIsDiNews(): ?bool
{
return $this->isDiNews;
}
public function setIsDiNews(bool $isDiNews): self
{
$this->isDiNews = $isDiNews;
return $this;
}
public function getIsVideo(): ?bool
{
return $this->isVideo;
}
public function setIsVideo(bool $isVideo): self
{
$this->isVideo = $isVideo;
return $this;
}
}