src/Entity/CRM/SocialPost.php line 12

  1. <?php
  2. namespace App\Entity\CRM;
  3. use App\Repository\CRM\SocialPostRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassSocialPostRepository::class)]
  9. class SocialPost
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $title null;
  17.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  18.     private ?string $content null;
  19.     #[ORM\Column(length500nullabletrue)]
  20.     private ?string $image null;
  21.     #[ORM\Column(nullabletrue)]
  22.     private ?bool $accepted false;
  23.     #[ORM\Column(nullabletrue)]
  24.     private ?bool $isActive true;
  25.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  26.     private ?\DateTimeInterface $dateForPublish null;
  27.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  28.     private ?\DateTimeInterface $createdAt null;
  29.     #[ORM\ManyToOne]
  30.     #[ORM\JoinColumn(nullabletrue)]
  31.     private ?Admin $acceptedBy null;
  32.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  33.     private ?\DateTimeInterface $acceptedAt null;
  34.     #[ORM\Column(nullabletrueoptions: ['default' => false])]
  35.     private ?bool $addToWebsite false;
  36.     #[ORM\Column(nullabletrueoptions: ['default' => false])]
  37.     private ?bool $publishedOnWebsite false;
  38.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  39.     private ?\DateTimeInterface $websitePublishedAt null;
  40.     #[ORM\OneToMany(mappedBy'socialPost'targetEntitySocialPostPlatform::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  41.     private Collection $socialPostPlatforms;
  42.     public function __construct()
  43.     {
  44.         $this->socialPostPlatforms = new ArrayCollection();
  45.         $this->createdAt = new \DateTime();
  46.     }
  47.     public function __toString(): string
  48.     {
  49.         return $this->title ?? '';
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getTitle(): ?string
  56.     {
  57.         return $this->title;
  58.     }
  59.     public function setTitle(string $title): static
  60.     {
  61.         $this->title $title;
  62.         return $this;
  63.     }
  64.     public function getContent(): ?string
  65.     {
  66.         return $this->content;
  67.     }
  68.     public function setContent(?string $content): static
  69.     {
  70.         $this->content $content;
  71.         return $this;
  72.     }
  73.     public function getImage(): ?string
  74.     {
  75.         return $this->image;
  76.     }
  77.     public function setImage(?string $image): static
  78.     {
  79.         $this->image $image;
  80.         return $this;
  81.     }
  82.     public function isAccepted(): ?bool
  83.     {
  84.         return $this->accepted;
  85.     }
  86.     public function setAccepted(?bool $accepted): static
  87.     {
  88.         $this->accepted $accepted;
  89.         return $this;
  90.     }
  91.     public function isIsActive(): ?bool
  92.     {
  93.         return $this->isActive;
  94.     }
  95.     public function setIsActive(?bool $isActive): static
  96.     {
  97.         $this->isActive $isActive;
  98.         return $this;
  99.     }
  100.     public function getDateForPublish(): ?\DateTimeInterface
  101.     {
  102.         return $this->dateForPublish;
  103.     }
  104.     public function setDateForPublish(?\DateTimeInterface $dateForPublish): static
  105.     {
  106.         $this->dateForPublish $dateForPublish;
  107.         return $this;
  108.     }
  109.     public function getCreatedAt(): ?\DateTimeInterface
  110.     {
  111.         return $this->createdAt;
  112.     }
  113.     public function setCreatedAt(?\DateTimeInterface $createdAt): static
  114.     {
  115.         $this->createdAt $createdAt;
  116.         return $this;
  117.     }
  118.     public function getAcceptedBy(): ?Admin
  119.     {
  120.         return $this->acceptedBy;
  121.     }
  122.     public function setAcceptedBy(?Admin $acceptedBy): static
  123.     {
  124.         $this->acceptedBy $acceptedBy;
  125.         return $this;
  126.     }
  127.     public function getAcceptedAt(): ?\DateTimeInterface
  128.     {
  129.         return $this->acceptedAt;
  130.     }
  131.     public function setAcceptedAt(?\DateTimeInterface $acceptedAt): static
  132.     {
  133.         $this->acceptedAt $acceptedAt;
  134.         return $this;
  135.     }
  136.     public function isAddToWebsite(): ?bool
  137.     {
  138.         return $this->addToWebsite;
  139.     }
  140.     public function setAddToWebsite(?bool $addToWebsite): static
  141.     {
  142.         $this->addToWebsite $addToWebsite;
  143.         return $this;
  144.     }
  145.     public function isPublishedOnWebsite(): ?bool
  146.     {
  147.         return $this->publishedOnWebsite;
  148.     }
  149.     public function setPublishedOnWebsite(?bool $publishedOnWebsite): static
  150.     {
  151.         $this->publishedOnWebsite $publishedOnWebsite;
  152.         return $this;
  153.     }
  154.     public function getWebsitePublishedAt(): ?\DateTimeInterface
  155.     {
  156.         return $this->websitePublishedAt;
  157.     }
  158.     public function setWebsitePublishedAt(?\DateTimeInterface $websitePublishedAt): static
  159.     {
  160.         $this->websitePublishedAt $websitePublishedAt;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return Collection<int, SocialPostPlatform>
  165.      */
  166.     public function getSocialPostPlatforms(): Collection
  167.     {
  168.         return $this->socialPostPlatforms;
  169.     }
  170.     public function addSocialPostPlatform(SocialPostPlatform $socialPostPlatform): static
  171.     {
  172.         if (!$this->socialPostPlatforms->contains($socialPostPlatform)) {
  173.             $this->socialPostPlatforms->add($socialPostPlatform);
  174.             $socialPostPlatform->setSocialPost($this);
  175.         }
  176.         return $this;
  177.     }
  178.     public function removeSocialPostPlatform(SocialPostPlatform $socialPostPlatform): static
  179.     {
  180.         if ($this->socialPostPlatforms->removeElement($socialPostPlatform)) {
  181.             if ($socialPostPlatform->getSocialPost() === $this) {
  182.                 $socialPostPlatform->setSocialPost(null);
  183.             }
  184.         }
  185.         return $this;
  186.     }
  187.     public function isPublishedOnAll(): bool
  188.     {
  189.         if ($this->socialPostPlatforms->isEmpty() && !$this->addToWebsite) {
  190.             return false;
  191.         }
  192.         if ($this->addToWebsite && !$this->publishedOnWebsite) {
  193.             return false;
  194.         }
  195.         foreach ($this->socialPostPlatforms as $spp) {
  196.             if (!$spp->isPublished()) {
  197.                 return false;
  198.             }
  199.         }
  200.         return true;
  201.     }
  202. }