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.      * @ORM\JoinColumn(name="company_publier_id", referencedColumnName="id", nullable=true)
  116.      * @Groups({"post:read", "publication:read"})
  117.      */
  118.     private $company_publier;
  119.     /**
  120.      * @ORM\Column(type="string", length=100, nullable=true)
  121.      * @Groups({"post:read", "publication:read"})
  122.      */
  123.     private $urlThumbnailsVideo;
  124.     /**
  125.      * @ORM\Column(type="boolean", nullable=true)
  126.      */
  127.     private $isArchived;
  128.     /**
  129.      * @ORM\Column(type="datetime", nullable=true)
  130.      */
  131.     private $archivedAt;
  132.     public function __construct()
  133.     {
  134.         $this->postphotos = new ArrayCollection();
  135.         $this->comments = new ArrayCollection();
  136.         $this->likes = new ArrayCollection();
  137.         $this->share = new ArrayCollection();
  138.         $this->publications = new ArrayCollection();
  139.     }
  140.     /**
  141.      * @Groups("publication:read")
  142.      */
  143.     public function getId(): ?int
  144.     {
  145.         return $this->id;
  146.     }
  147.     /**
  148.      * @Groups("publication:read")
  149.      */
  150.     public function getText(): ?string
  151.     {
  152.         return $this->text;
  153.     }
  154.     public function setText(?string $text): self
  155.     {
  156.         $this->text $text;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @Groups("publication:read")
  161.      */
  162.     public function getPhoto(): ?array
  163.     {
  164.         return $this->photo;
  165.     }
  166.     public function setPhoto(?array $photo): self
  167.     {
  168.         $this->photo $photo;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @Groups("publication:read")
  173.      */
  174.     public function getEspace(): ?Espace
  175.     {
  176.         return $this->espace;
  177.     }
  178.     public function setEspace(?Espace $espace): self
  179.     {
  180.         $this->espace $espace;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection|Postphoto[]
  185.      */
  186.     public function getPostphotos(): Collection
  187.     {
  188.         return $this->postphotos;
  189.     }
  190.     public function addPostphoto(Postphoto $postphoto): self
  191.     {
  192.         if (!$this->postphotos->contains($postphoto)) {
  193.             $this->postphotos[] = $postphoto;
  194.             $postphoto->setPublication($this);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removePostphoto(Postphoto $postphoto): self
  199.     {
  200.         if ($this->postphotos->removeElement($postphoto)) {
  201.             // set the owning side to null (unless already changed)
  202.             if ($postphoto->getPublication() === $this) {
  203.                 $postphoto->setPublication(null);
  204.             }
  205.         }
  206.         return $this;
  207.     }
  208.     /**
  209.      * @Groups("publication:read")
  210.      */
  211.     public function getClient(): ?User
  212.     {
  213.         return $this->client;
  214.     }
  215.     public function setClient(?User $client): self
  216.     {
  217.         $this->client $client;
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return Collection|Comments[]
  222.      */
  223.     public function getComments(): Collection
  224.     {
  225.         return $this->comments;
  226.     }
  227.     public function addComment(Comments $comment): self
  228.     {
  229.         if (!$this->comments->contains($comment)) {
  230.             $this->comments[] = $comment;
  231.             $comment->setPublication($this);
  232.         }
  233.         return $this;
  234.     }
  235.     public function removeComment(Comments $comment): self
  236.     {
  237.         if ($this->comments->removeElement($comment)) {
  238.             // set the owning side to null (unless already changed)
  239.             if ($comment->getPublication() === $this) {
  240.                 $comment->setPublication(null);
  241.             }
  242.         }
  243.         return $this;
  244.     }
  245.     /**
  246.      * Returns the number of comments for the publication
  247.      * @Groups("publication:read")
  248.      */
  249.     public function getCommentsCount(): int
  250.     {
  251.         return $this->comments->count();
  252.     }
  253.     /**
  254.      * @Groups("publication:read")
  255.      */
  256.     public function getPostedAt(): ?\DateTimeInterface
  257.     {
  258.         return $this->postedAt;
  259.     }
  260.     public function setPostedAt(?\DateTimeInterface $postedAt): self
  261.     {
  262.         $this->postedAt $postedAt;
  263.         return $this;
  264.     }
  265.     /**
  266.      * @Groups("publication:read")
  267.      */
  268.     public function getUpdatedAt(): ?\DateTimeInterface
  269.     {
  270.         return $this->updatedAt;
  271.     }
  272.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  273.     {
  274.         $this->updatedAt $updatedAt;
  275.         return $this;
  276.     }
  277.     public function getIsDeleted(): ?bool
  278.     {
  279.         return $this->is_deleted;
  280.     }
  281.     public function setIsDeleted(?bool $is_deleted): self
  282.     {
  283.         $this->is_deleted $is_deleted;
  284.         return $this;
  285.     }
  286.     /**
  287.      * @Groups("publication:read")
  288.      */
  289.     public function getInLive(): ?bool
  290.     {
  291.         return $this->inLive;
  292.     }
  293.     public function setInLIve(?bool $inLive): self
  294.     {
  295.         $this->inLive $inLive;
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection|PostLike[]
  300.      */
  301.     public function getLikes(): Collection
  302.     {
  303.         return $this->likes;
  304.     }
  305.     public function addLike(PostLike $like): self
  306.     {
  307.         if (!$this->likes->contains($like)) {
  308.             $this->likes[] = $like;
  309.             $like->setPublication($this);
  310.         }
  311.         return $this;
  312.     }
  313.     /**
  314.      * Returns the number of likes for the publication
  315.      * @Groups("publication:read")
  316.      */
  317.     public function getLikesCount(): int
  318.     {
  319.         return $this->likes->count();
  320.     }
  321.     /**
  322.      * Permet de savoir si une publication est likée par un utilisateur
  323.      * @param User $user
  324.      * @return boolean
  325.      */
  326.     public function isLikeByUser(User $user): bool
  327.     {
  328.         foreach ($this->likes as $like) {
  329.             if ($like->getUser() === $user) return true;
  330.         }
  331.         return false;
  332.     }
  333.     public function removeLike(PostLike $like): self
  334.     {
  335.         if ($this->likes->removeElement($like)) {
  336.             // set the owning side to null (unless already changed)
  337.             if ($like->getPublication() === $this) {
  338.                 $like->setPublication(null);
  339.             }
  340.         }
  341.         return $this;
  342.     }
  343.     /**
  344.      * Permet de savoir si une publication est likée par un presatataire
  345.      * @param Company $company
  346.      * @return boolean
  347.      */
  348.     public function isLikeByCompany(Company $company): bool
  349.     {
  350.         foreach ($this->likes as $like){
  351.             if ($like->getCompany() === $company) return true;
  352.         }
  353.         return false;
  354.     }
  355.     /**
  356.      * @return Collection|SharePost[]
  357.      */
  358.     public function getShare(): Collection
  359.     {
  360.         return $this->share;
  361.     }
  362.     public function addShare(SharePost $share): self
  363.     {
  364.         if (!$this->share->contains($share)) {
  365.             $this->share[] = $share;
  366.             $share->setPost($this);
  367.         }
  368.         return $this;
  369.     }
  370.     /**
  371.      * Returns the number of shares for the publication
  372.      * @Groups("publication:read")
  373.      */
  374.     public function getShareCount(): int
  375.     {
  376.         return $this->share->count();
  377.     }
  378.     public function removeShare(SharePost $share): self
  379.     {
  380.         if ($this->share->removeElement($share)) {
  381.             // set the owning side to null (unless already changed)
  382.             if ($share->getPost() === $this) {
  383.                 $share->setPost(null);
  384.             }
  385.         }
  386.         return $this;
  387.     }
  388.     public function getPostShared(): ?self
  389.     {
  390.         return $this->postShared;
  391.     }
  392.     public function setPostShared(?self $postShared): self
  393.     {
  394.         $this->postShared $postShared;
  395.         return $this;
  396.     }
  397.     /**
  398.      * @return Collection|self[]
  399.      */
  400.     public function getPublications(): Collection
  401.     {
  402.         return $this->publications;
  403.     }
  404.     public function addPublication(self $publication): self
  405.     {
  406.         if (!$this->publications->contains($publication)) {
  407.             $this->publications[] = $publication;
  408.             $publication->setPostShared($this);
  409.         }
  410.         return $this;
  411.     }
  412.     public function removePublication(self $publication): self
  413.     {
  414.         if ($this->publications->removeElement($publication)) {
  415.             // set the owning side to null (unless already changed)
  416.             if ($publication->getPostShared() === $this) {
  417.                 $publication->setPostShared(null);
  418.             }
  419.         }
  420.         return $this;
  421.     }
  422.     /**
  423.      * @Groups("publication:read")
  424.      */
  425.     public function getUrlVideoLive(): ?string
  426.     {
  427.         return $this->urlVideoLive;
  428.     }
  429.     public function setUrlVideoLive(?string $urlVideoLive): self
  430.     {
  431.         $this->urlVideoLive $urlVideoLive;
  432.         return $this;
  433.     }
  434.     /**
  435.      * @Groups("publication:read")
  436.      */
  437.     public function getCompany(): ?Company
  438.     {
  439.         return $this->company;
  440.     }
  441.     public function setCompany(?Company $company): self
  442.     {
  443.         $this->company $company;
  444.         return $this;
  445.     }
  446.     /**
  447.      * @Groups("publication:read")
  448.      */
  449.     public function getProductCompany(): ?Product
  450.     {
  451.         return $this->product_company;
  452.     }
  453.     public function setProductCompany(?Product $product_company): self
  454.     {
  455.         $this->product_company $product_company;
  456.         return $this;
  457.     }
  458.     /**
  459.      * @Groups("publication:read")
  460.      */
  461.     public function getCompanyPublier(): ?Company
  462.     {
  463.         return $this->company_publier;
  464.     }
  465.     public function setCompanyPublier(?Company $company_publier): self
  466.     {
  467.         $this->company_publier $company_publier;
  468.         return $this;
  469.     }
  470.     /**
  471.      * @Groups("publication:read")
  472.      */
  473.     public function getUrlThumbnailsVideo(): ?string
  474.     {
  475.         return $this->urlThumbnailsVideo;
  476.     }
  477.     public function setUrlThumbnailsVideo(?string $urlThumbnailsVideo): self
  478.     {
  479.         $this->urlThumbnailsVideo $urlThumbnailsVideo;
  480.         return $this;
  481.     }
  482.     /**
  483.      * @Groups("publication:read")
  484.      */
  485.     public function getIsArchived(): ?bool
  486.     {
  487.         return $this->isArchived;
  488.     }
  489.     public function setIsArchived(?bool $isArchived): self
  490.     {
  491.         $this->isArchived $isArchived;
  492.         return $this;
  493.     }
  494.     public function getArchivedAt(): ?\DateTimeInterface
  495.     {
  496.         return $this->archivedAt;
  497.     }
  498.     public function setArchivedAt(?\DateTimeInterface $archivedAt): self
  499.     {
  500.         $this->archivedAt $archivedAt;
  501.         return $this;
  502.     }
  503. }