src/Entity/ReseauSociaux/Publication.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ReseauSociaux;
  3. use App\Entity\Company;
  4. use App\Entity\Product;
  5. use App\Entity\ReseauSociaux\PostLike;
  6. use App\Entity\User;
  7. use App\Repository\ReseauSociaux\PublicationRepository;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Serializer\Annotation\MaxDepth;
  13. /**
  14.  * @ORM\Entity(repositoryClass=PublicationRepository::class)
  15.  */
  16. class Publication
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      * @Groups({"post:read", "publication:read", "notif:read"})
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="text", nullable=true)
  27.      * @Groups({"post:read", "publication:read", "notif:read"})
  28.      */
  29.     private $text;
  30.     /**
  31.      * @ORM\Column(type="array", nullable=true)
  32.      * @Groups({"post:read", "publication:read", "notif:read"})
  33.      */
  34.     private $photo = [];
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Espace::class, inversedBy="publications")
  37.      * @Groups({"post:read", "publication:read"})
  38.      */
  39.     private $espace;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=Postphoto::class, mappedBy="publication", orphanRemoval=true)
  42.      * @Groups({"post:read", "publication:read"})
  43.      */
  44.     private $postphotos;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="publications")
  47.      * @Groups({"post:read", "publication:read"})
  48.      */
  49.     private $client;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity=Comments::class, mappedBy="publication", orphanRemoval=true)
  52.      * @Groups({"post:read", "publication:read"})
  53.      */
  54.     private $comments;
  55.     /**
  56.      * @ORM\Column(type="datetime", nullable=false)
  57.      * @Groups({"post:read", "publication:read", "notif:read"})
  58.      */
  59.     private $postedAt;
  60.     /**
  61.      * @ORM\Column(type="datetime", nullable=true)
  62.      * @Groups({"post:read", "notif:read"})
  63.      */
  64.     private $updatedAt;
  65.     /**
  66.      * @ORM\Column(type="boolean", nullable=false)
  67.      * @Groups({"post:read", "publication:read"})
  68.      */
  69.     private $is_deleted;
  70.     
  71.     /**
  72.      * @ORM\Column(type="boolean", nullable=false)
  73.      * @Groups({"post:read", "publication:read"})
  74.      */
  75.     private $inLive;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=PostLike::class, mappedBy="publication")
  78.      * Groups({"publication:read"})
  79.      */
  80.     private $likes;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=SharePost::class, mappedBy="post")
  83.      * @Groups("publication:read")
  84.      */
  85.     private $share;
  86.     /**
  87.      * @ORM\ManyToOne(targetEntity=Publication::class, inversedBy="publications")
  88.      * @Groups("publication:read")
  89.      * @MaxDepth(1)
  90.      */
  91.     private $postShared;
  92.     /**
  93.      * @ORM\OneToMany(targetEntity=Publication::class, mappedBy="postShared")
  94.      * @Groups("publication:read")
  95.      * @MaxDepth(1)
  96.      */
  97.     private $publications;
  98.     /**
  99.      * @ORM\Column(type="string", length=255, nullable=true)
  100.      * @Groups({"post:read", "publication:read"})
  101.      */
  102.     private $urlVideoLive;
  103.     /**
  104.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="publications")
  105.      * @Groups({"post:read", "publication:read"})
  106.      */
  107.     private $company;
  108.     /**
  109.      * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="publications")
  110.      * @Groups({"post:read", "publication:read"})
  111.      */
  112.     private $product_company;
  113.     /**
  114.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="pub_company")
  115.      * @Groups({"post:read", "publication:read"})
  116.      */
  117.     private $company_publier;
  118.     /**
  119.      * @ORM\Column(type="string", length=100, nullable=true)
  120.      * @Groups({"post:read", "publication:read"})
  121.      */
  122.     private $urlThumbnailsVideo;
  123.     /**
  124.      * @ORM\Column(type="boolean", nullable=true)
  125.      */
  126.     private $isArchived;
  127.     /**
  128.      * @ORM\Column(type="datetime", nullable=true)
  129.      */
  130.     private $archivedAt;
  131.     public function __construct()
  132.     {
  133.         $this->postphotos = new ArrayCollection();
  134.         $this->comments = new ArrayCollection();
  135.         $this->likes = new ArrayCollection();
  136.         $this->share = new ArrayCollection();
  137.         $this->publications = new ArrayCollection();
  138.     }
  139.     /**
  140.      * @Groups("publication:read")
  141.      */
  142.     public function getId(): ?int
  143.     {
  144.         return $this->id;
  145.     }
  146.     /**
  147.      * @Groups("publication:read")
  148.      */
  149.     public function getText(): ?string
  150.     {
  151.         return $this->text;
  152.     }
  153.     public function setText(?string $text): self
  154.     {
  155.         $this->text $text;
  156.         return $this;
  157.     }
  158.     /**
  159.      * @Groups("publication:read")
  160.      */
  161.     public function getPhoto(): ?array
  162.     {
  163.         return $this->photo;
  164.     }
  165.     public function setPhoto(?array $photo): self
  166.     {
  167.         $this->photo $photo;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @Groups("publication:read")
  172.      */
  173.     public function getEspace(): ?Espace
  174.     {
  175.         return $this->espace;
  176.     }
  177.     public function setEspace(?Espace $espace): self
  178.     {
  179.         $this->espace $espace;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return Collection|Postphoto[]
  184.      */
  185.     public function getPostphotos(): Collection
  186.     {
  187.         return $this->postphotos;
  188.     }
  189.     public function addPostphoto(Postphoto $postphoto): self
  190.     {
  191.         if (!$this->postphotos->contains($postphoto)) {
  192.             $this->postphotos[] = $postphoto;
  193.             $postphoto->setPublication($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removePostphoto(Postphoto $postphoto): self
  198.     {
  199.         if ($this->postphotos->removeElement($postphoto)) {
  200.             // set the owning side to null (unless already changed)
  201.             if ($postphoto->getPublication() === $this) {
  202.                 $postphoto->setPublication(null);
  203.             }
  204.         }
  205.         return $this;
  206.     }
  207.     /**
  208.      * @Groups("publication:read")
  209.      */
  210.     public function getClient(): ?User
  211.     {
  212.         return $this->client;
  213.     }
  214.     public function setClient(?User $client): self
  215.     {
  216.         $this->client $client;
  217.         return $this;
  218.     }
  219.     /**
  220.      * @return Collection|Comments[]
  221.      */
  222.     public function getComments(): Collection
  223.     {
  224.         return $this->comments;
  225.     }
  226.     public function addComment(Comments $comment): self
  227.     {
  228.         if (!$this->comments->contains($comment)) {
  229.             $this->comments[] = $comment;
  230.             $comment->setPublication($this);
  231.         }
  232.         return $this;
  233.     }
  234.     public function removeComment(Comments $comment): self
  235.     {
  236.         if ($this->comments->removeElement($comment)) {
  237.             // set the owning side to null (unless already changed)
  238.             if ($comment->getPublication() === $this) {
  239.                 $comment->setPublication(null);
  240.             }
  241.         }
  242.         return $this;
  243.     }
  244.     /**
  245.      * Returns the number of comments for the publication
  246.      * @Groups("publication:read")
  247.      */
  248.     public function getCommentsCount(): int
  249.     {
  250.         return $this->comments->count();
  251.     }
  252.     /**
  253.      * @Groups("publication:read")
  254.      */
  255.     public function getPostedAt(): ?\DateTimeInterface
  256.     {
  257.         return $this->postedAt;
  258.     }
  259.     public function setPostedAt(?\DateTimeInterface $postedAt): self
  260.     {
  261.         $this->postedAt $postedAt;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @Groups("publication:read")
  266.      */
  267.     public function getUpdatedAt(): ?\DateTimeInterface
  268.     {
  269.         return $this->updatedAt;
  270.     }
  271.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  272.     {
  273.         $this->updatedAt $updatedAt;
  274.         return $this;
  275.     }
  276.     public function getIsDeleted(): ?bool
  277.     {
  278.         return $this->is_deleted;
  279.     }
  280.     public function setIsDeleted(?bool $is_deleted): self
  281.     {
  282.         $this->is_deleted $is_deleted;
  283.         return $this;
  284.     }
  285.     /**
  286.      * @Groups("publication:read")
  287.      */
  288.     public function getInLive(): ?bool
  289.     {
  290.         return $this->inLive;
  291.     }
  292.     public function setInLIve(?bool $inLive): self
  293.     {
  294.         $this->inLive $inLive;
  295.         return $this;
  296.     }
  297.     /**
  298.      * @return Collection|PostLike[]
  299.      */
  300.     public function getLikes(): Collection
  301.     {
  302.         return $this->likes;
  303.     }
  304.     public function addLike(PostLike $like): self
  305.     {
  306.         if (!$this->likes->contains($like)) {
  307.             $this->likes[] = $like;
  308.             $like->setPublication($this);
  309.         }
  310.         return $this;
  311.     }
  312.     /**
  313.      * Returns the number of likes for the publication
  314.      * @Groups("publication:read")
  315.      */
  316.     public function getLikesCount(): int
  317.     {
  318.         return $this->likes->count();
  319.     }
  320.     /**
  321.      * Permet de savoir si une publication est likée par un utilisateur
  322.      * @param User $user
  323.      * @return boolean
  324.      */
  325.     public function isLikeByUser(User $user): bool
  326.     {
  327.         foreach ($this->likes as $like) {
  328.             if ($like->getUser() === $user) return true;
  329.         }
  330.         return false;
  331.     }
  332.     public function removeLike(PostLike $like): self
  333.     {
  334.         if ($this->likes->removeElement($like)) {
  335.             // set the owning side to null (unless already changed)
  336.             if ($like->getPublication() === $this) {
  337.                 $like->setPublication(null);
  338.             }
  339.         }
  340.         return $this;
  341.     }
  342.     /**
  343.      * Permet de savoir si une publication est likée par un presatataire
  344.      * @param Company $company
  345.      * @return boolean
  346.      */
  347.     public function isLikeByCompany(Company $company): bool
  348.     {
  349.         foreach ($this->likes as $like){
  350.             if ($like->getCompany() === $company) return true;
  351.         }
  352.         return false;
  353.     }
  354.     /**
  355.      * @return Collection|SharePost[]
  356.      */
  357.     public function getShare(): Collection
  358.     {
  359.         return $this->share;
  360.     }
  361.     public function addShare(SharePost $share): self
  362.     {
  363.         if (!$this->share->contains($share)) {
  364.             $this->share[] = $share;
  365.             $share->setPost($this);
  366.         }
  367.         return $this;
  368.     }
  369.     /**
  370.      * Returns the number of shares for the publication
  371.      * @Groups("publication:read")
  372.      */
  373.     public function getShareCount(): int
  374.     {
  375.         return $this->share->count();
  376.     }
  377.     public function removeShare(SharePost $share): self
  378.     {
  379.         if ($this->share->removeElement($share)) {
  380.             // set the owning side to null (unless already changed)
  381.             if ($share->getPost() === $this) {
  382.                 $share->setPost(null);
  383.             }
  384.         }
  385.         return $this;
  386.     }
  387.     public function getPostShared(): ?self
  388.     {
  389.         return $this->postShared;
  390.     }
  391.     public function setPostShared(?self $postShared): self
  392.     {
  393.         $this->postShared $postShared;
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection|self[]
  398.      */
  399.     public function getPublications(): Collection
  400.     {
  401.         return $this->publications;
  402.     }
  403.     public function addPublication(self $publication): self
  404.     {
  405.         if (!$this->publications->contains($publication)) {
  406.             $this->publications[] = $publication;
  407.             $publication->setPostShared($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removePublication(self $publication): self
  412.     {
  413.         if ($this->publications->removeElement($publication)) {
  414.             // set the owning side to null (unless already changed)
  415.             if ($publication->getPostShared() === $this) {
  416.                 $publication->setPostShared(null);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     /**
  422.      * @Groups("publication:read")
  423.      */
  424.     public function getUrlVideoLive(): ?string
  425.     {
  426.         return $this->urlVideoLive;
  427.     }
  428.     public function setUrlVideoLive(?string $urlVideoLive): self
  429.     {
  430.         $this->urlVideoLive $urlVideoLive;
  431.         return $this;
  432.     }
  433.     /**
  434.      * @Groups("publication:read")
  435.      */
  436.     public function getCompany(): ?Company
  437.     {
  438.         return $this->company;
  439.     }
  440.     public function setCompany(?Company $company): self
  441.     {
  442.         $this->company $company;
  443.         return $this;
  444.     }
  445.     public function getProductCompany(): ?Product
  446.     {
  447.         return $this->product_company;
  448.     }
  449.     public function setProductCompany(?Product $product_company): self
  450.     {
  451.         $this->product_company $product_company;
  452.         return $this;
  453.     }
  454.     /**
  455.      * @Groups("publication:read")
  456.      */
  457.     public function getCompanyPublier(): ?Company
  458.     {
  459.         return $this->company_publier;
  460.     }
  461.     public function setCompanyPublier(?Company $company_publier): self
  462.     {
  463.         $this->company_publier $company_publier;
  464.         return $this;
  465.     }
  466.     /**
  467.      * @Groups("publication:read")
  468.      */
  469.     public function getUrlThumbnailsVideo(): ?string
  470.     {
  471.         return $this->urlThumbnailsVideo;
  472.     }
  473.     public function setUrlThumbnailsVideo(?string $urlThumbnailsVideo): self
  474.     {
  475.         $this->urlThumbnailsVideo $urlThumbnailsVideo;
  476.         return $this;
  477.     }
  478.     /**
  479.      * @Groups("publication:read")
  480.      */
  481.     public function getIsArchived(): ?bool
  482.     {
  483.         return $this->isArchived;
  484.     }
  485.     public function setIsArchived(?bool $isArchived): self
  486.     {
  487.         $this->isArchived $isArchived;
  488.         return $this;
  489.     }
  490.     public function getArchivedAt(): ?\DateTimeInterface
  491.     {
  492.         return $this->archivedAt;
  493.     }
  494.     public function setArchivedAt(?\DateTimeInterface $archivedAt): self
  495.     {
  496.         $this->archivedAt $archivedAt;
  497.         return $this;
  498.     }
  499. }