<?php
namespace App\Entity\ReseauSociaux;
use App\Entity\Company;
use App\Entity\Product;
use App\Entity\ReseauSociaux\PostLike;
use App\Entity\User;
use App\Repository\ReseauSociaux\PublicationRepository;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\MaxDepth;
/**
* @ORM\Entity(repositoryClass=PublicationRepository::class)
*/
class Publication
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"post:read", "publication:read", "notif:read"})
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"post:read", "publication:read", "notif:read"})
*/
private $text;
/**
* @ORM\Column(type="array", nullable=true)
* @Groups({"post:read", "publication:read", "notif:read"})
*/
private $photo = [];
/**
* @ORM\ManyToOne(targetEntity=Espace::class, inversedBy="publications")
* @Groups({"post:read", "publication:read"})
*/
private $espace;
/**
* @ORM\OneToMany(targetEntity=Postphoto::class, mappedBy="publication", orphanRemoval=true)
* @Groups({"post:read", "publication:read"})
*/
private $postphotos;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="publications")
* @Groups({"post:read", "publication:read"})
*/
private $client;
/**
* @ORM\OneToMany(targetEntity=Comments::class, mappedBy="publication", orphanRemoval=true)
* @Groups({"post:read", "publication:read"})
*/
private $comments;
/**
* @ORM\Column(type="datetime", nullable=false)
* @Groups({"post:read", "publication:read", "notif:read"})
*/
private $postedAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"post:read", "notif:read"})
*/
private $updatedAt;
/**
* @ORM\Column(type="boolean", nullable=false)
* @Groups({"post:read", "publication:read"})
*/
private $is_deleted;
/**
* @ORM\Column(type="boolean", nullable=false)
* @Groups({"post:read", "publication:read"})
*/
private $inLive;
/**
* @ORM\OneToMany(targetEntity=PostLike::class, mappedBy="publication")
* Groups({"publication:read"})
*/
private $likes;
/**
* @ORM\OneToMany(targetEntity=SharePost::class, mappedBy="post")
* @Groups("publication:read")
*/
private $share;
/**
* @ORM\ManyToOne(targetEntity=Publication::class, inversedBy="publications")
* @Groups("publication:read")
* @MaxDepth(1)
*/
private $postShared;
/**
* @ORM\OneToMany(targetEntity=Publication::class, mappedBy="postShared")
* @Groups("publication:read")
* @MaxDepth(1)
*/
private $publications;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"post:read", "publication:read"})
*/
private $urlVideoLive;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="publications")
* @Groups({"post:read", "publication:read"})
*/
private $company;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="publications")
* @Groups({"post:read", "publication:read"})
*/
private $product_company;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="pub_company")
* @Groups({"post:read", "publication:read"})
*/
private $company_publier;
/**
* @ORM\Column(type="string", length=100, nullable=true)
* @Groups({"post:read", "publication:read"})
*/
private $urlThumbnailsVideo;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isArchived;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $archivedAt;
public function __construct()
{
$this->postphotos = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->likes = new ArrayCollection();
$this->share = new ArrayCollection();
$this->publications = new ArrayCollection();
}
/**
* @Groups("publication:read")
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @Groups("publication:read")
*/
public function getText(): ?string
{
return $this->text;
}
public function setText(?string $text): self
{
$this->text = $text;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getPhoto(): ?array
{
return $this->photo;
}
public function setPhoto(?array $photo): self
{
$this->photo = $photo;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getEspace(): ?Espace
{
return $this->espace;
}
public function setEspace(?Espace $espace): self
{
$this->espace = $espace;
return $this;
}
/**
* @return Collection|Postphoto[]
*/
public function getPostphotos(): Collection
{
return $this->postphotos;
}
public function addPostphoto(Postphoto $postphoto): self
{
if (!$this->postphotos->contains($postphoto)) {
$this->postphotos[] = $postphoto;
$postphoto->setPublication($this);
}
return $this;
}
public function removePostphoto(Postphoto $postphoto): self
{
if ($this->postphotos->removeElement($postphoto)) {
// set the owning side to null (unless already changed)
if ($postphoto->getPublication() === $this) {
$postphoto->setPublication(null);
}
}
return $this;
}
/**
* @Groups("publication:read")
*/
public function getClient(): ?User
{
return $this->client;
}
public function setClient(?User $client): self
{
$this->client = $client;
return $this;
}
/**
* @return Collection|Comments[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comments $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setPublication($this);
}
return $this;
}
public function removeComment(Comments $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getPublication() === $this) {
$comment->setPublication(null);
}
}
return $this;
}
/**
* Returns the number of comments for the publication
* @Groups("publication:read")
*/
public function getCommentsCount(): int
{
return $this->comments->count();
}
/**
* @Groups("publication:read")
*/
public function getPostedAt(): ?\DateTimeInterface
{
return $this->postedAt;
}
public function setPostedAt(?\DateTimeInterface $postedAt): self
{
$this->postedAt = $postedAt;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getIsDeleted(): ?bool
{
return $this->is_deleted;
}
public function setIsDeleted(?bool $is_deleted): self
{
$this->is_deleted = $is_deleted;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getInLive(): ?bool
{
return $this->inLive;
}
public function setInLIve(?bool $inLive): self
{
$this->inLive = $inLive;
return $this;
}
/**
* @return Collection|PostLike[]
*/
public function getLikes(): Collection
{
return $this->likes;
}
public function addLike(PostLike $like): self
{
if (!$this->likes->contains($like)) {
$this->likes[] = $like;
$like->setPublication($this);
}
return $this;
}
/**
* Returns the number of likes for the publication
* @Groups("publication:read")
*/
public function getLikesCount(): int
{
return $this->likes->count();
}
/**
* Permet de savoir si une publication est likée par un utilisateur
* @param User $user
* @return boolean
*/
public function isLikeByUser(User $user): bool
{
foreach ($this->likes as $like) {
if ($like->getUser() === $user) return true;
}
return false;
}
public function removeLike(PostLike $like): self
{
if ($this->likes->removeElement($like)) {
// set the owning side to null (unless already changed)
if ($like->getPublication() === $this) {
$like->setPublication(null);
}
}
return $this;
}
/**
* Permet de savoir si une publication est likée par un presatataire
* @param Company $company
* @return boolean
*/
public function isLikeByCompany(Company $company): bool
{
foreach ($this->likes as $like){
if ($like->getCompany() === $company) return true;
}
return false;
}
/**
* @return Collection|SharePost[]
*/
public function getShare(): Collection
{
return $this->share;
}
public function addShare(SharePost $share): self
{
if (!$this->share->contains($share)) {
$this->share[] = $share;
$share->setPost($this);
}
return $this;
}
/**
* Returns the number of shares for the publication
* @Groups("publication:read")
*/
public function getShareCount(): int
{
return $this->share->count();
}
public function removeShare(SharePost $share): self
{
if ($this->share->removeElement($share)) {
// set the owning side to null (unless already changed)
if ($share->getPost() === $this) {
$share->setPost(null);
}
}
return $this;
}
public function getPostShared(): ?self
{
return $this->postShared;
}
public function setPostShared(?self $postShared): self
{
$this->postShared = $postShared;
return $this;
}
/**
* @return Collection|self[]
*/
public function getPublications(): Collection
{
return $this->publications;
}
public function addPublication(self $publication): self
{
if (!$this->publications->contains($publication)) {
$this->publications[] = $publication;
$publication->setPostShared($this);
}
return $this;
}
public function removePublication(self $publication): self
{
if ($this->publications->removeElement($publication)) {
// set the owning side to null (unless already changed)
if ($publication->getPostShared() === $this) {
$publication->setPostShared(null);
}
}
return $this;
}
/**
* @Groups("publication:read")
*/
public function getUrlVideoLive(): ?string
{
return $this->urlVideoLive;
}
public function setUrlVideoLive(?string $urlVideoLive): self
{
$this->urlVideoLive = $urlVideoLive;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getProductCompany(): ?Product
{
return $this->product_company;
}
public function setProductCompany(?Product $product_company): self
{
$this->product_company = $product_company;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getCompanyPublier(): ?Company
{
return $this->company_publier;
}
public function setCompanyPublier(?Company $company_publier): self
{
$this->company_publier = $company_publier;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getUrlThumbnailsVideo(): ?string
{
return $this->urlThumbnailsVideo;
}
public function setUrlThumbnailsVideo(?string $urlThumbnailsVideo): self
{
$this->urlThumbnailsVideo = $urlThumbnailsVideo;
return $this;
}
/**
* @Groups("publication:read")
*/
public function getIsArchived(): ?bool
{
return $this->isArchived;
}
public function setIsArchived(?bool $isArchived): self
{
$this->isArchived = $isArchived;
return $this;
}
public function getArchivedAt(): ?\DateTimeInterface
{
return $this->archivedAt;
}
public function setArchivedAt(?\DateTimeInterface $archivedAt): self
{
$this->archivedAt = $archivedAt;
return $this;
}
}