src/Entity/ReseauSociaux/Publication.php line 20

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