app/Entity/Schema/ORM/PostCategory.php line 17

Open in your IDE?
  1. <?php
  2. namespace Sq\Entity\Schema\ORM;
  3. use Carbon\Carbon;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * PostCategory.
  9.  */
  10. #[ORM\Entity(repositoryClass\Sq\Service\Repository\ORM\CategoryRepository::class)]
  11. #[ORM\Table(name'queue_post_cat')]
  12. #[ORM\Index(name'qpc_seasonally_paused'columns: ['qpc_seasonally_paused'])]
  13. #[ORM\Index(name'qpc_m_id'columns: ['qpc_m_id'])]
  14. class PostCategory implements BelongsToWorkspaceInterfaceOnboardingContentInterface
  15. {
  16.     /**
  17.      * @var int
  18.      */
  19.     #[ORM\Column(name'qpc_id'type'integer'nullablefalseoptions: ['unsigned' => true])]
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  22.     private $id;
  23.     /**
  24.      * @var Member|null
  25.      */
  26.     #[ORM\ManyToOne(targetEntityMember::class, inversedBy'categories')]
  27.     #[ORM\JoinColumn(name'qpc_m_id'referencedColumnName'm_id'nullabletrue)]
  28.     private $member;
  29.     /**
  30.      * @var bool|null
  31.      */
  32.     #[ORM\Column(name'qpc_seasonally_paused'type'boolean'nullabletrue)]
  33.     private $seasonallyPaused false;
  34.     /**
  35.      * @var bool|null
  36.      */
  37.     #[ORM\Column(name'qpc_archived'type'boolean'nullabletrue)]
  38.     private $archived false;
  39.     /**
  40.      * @var \DateTimeInterface|null
  41.      */
  42.     #[ORM\Column(name'qpc_date_archived'type'datetime'nullabletrue)]
  43.     private $dateArchived;
  44.     /**
  45.      * @var bool|null
  46.      */
  47.     #[ORM\Column(name'qpc_init_state'type'boolean'nullabletrue)]
  48.     private $initState false;
  49.     /**
  50.      * @var int|null
  51.      */
  52.     #[ORM\Column(name'qpc_post_cat'type'smallint'nullabletrueoptions: ['default' => 1])]
  53.     private $postCat 1;
  54.     /**
  55.      * @var string|null
  56.      */
  57.     #[ORM\Column(name'qpc_name'type'string'length191nullabletrue)]
  58.     private $name;
  59.     /**
  60.      * @var string
  61.      */
  62.     #[ORM\Column(name'qpc_colour'type'string'length7nullablefalse)]
  63.     private $colour;
  64.     /**
  65.      * @var \DateTimeInterface|null
  66.      */
  67.     #[ORM\Column(name'qpc_start_date'type'date'nullabletrue)]
  68.     private $startDate;
  69.     /**
  70.      * @var \DateTime|null
  71.      */
  72.     #[ORM\Column(name'qpc_end_date'type'date'nullabletrue)]
  73.     private $endDate;
  74.     /**
  75.      *
  76.      * @var Workspace|null
  77.      */
  78.     #[ORM\ManyToOne(targetEntityWorkspace::class, inversedBy'postCategories')]
  79.     #[ORM\JoinColumn(name'qpc_ws_id'referencedColumnName'ws_id'nullabletrue)]
  80.     private $workspace;
  81.     /**
  82.      *
  83.      * @var Collection<SocialProfile>
  84.      */
  85.     #[ORM\ManyToMany(targetEntitySocialNetwork::class, cascade: ['persist'])]
  86.     #[ORM\JoinTable(name'queue_post_cat_default_profiles'joinColumns: [new ORM\JoinColumn(name'qpcdp_qpc_id'referencedColumnName'qpc_id')], inverseJoinColumns: [new ORM\JoinColumn(name'qpcdp_sn_id'referencedColumnName'sn_id')])]
  87.     private $defaultSocialProfiles;
  88.     #[ORM\OneToMany(targetEntityQueueSchedule::class, mappedBy'category'cascade: ['persist''remove'])]
  89.     private Collection $timeslots;
  90.     #[ORM\OneToMany(targetEntityQueueMetadata::class, mappedBy'category'cascade: ['remove'], fetch'EXTRA_LAZY')]
  91.     protected $queueMetadatas;
  92.     /**
  93.      * @var bool
  94.      */
  95.     #[ORM\Column(name'qpc_onboarding_content'type'boolean'nullablefalse)]
  96.     protected $onboardingContent false;
  97.     #[ORM\Column(name'qpc_archived_attached_post_count'type'integer'nullabletrue)]
  98.     protected $archivedAttachedPostCount;
  99.     public function __construct(
  100.         string $name,
  101.         string $colourHex,
  102.         ?Workspace $workspace null,
  103.         bool $isOnboardingContent false
  104.     ) {
  105.         $this->name $name;
  106.         $this->colour $colourHex;
  107.         $this->workspace $workspace;
  108.         $this->onboardingContent $isOnboardingContent;
  109.         $this->defaultSocialProfiles = new ArrayCollection();
  110.         $this->timeslots = new ArrayCollection();
  111.         $workspace?->addCategory($this);
  112.     }
  113.     public function getId(): ?int
  114.     {
  115.         return $this->id;
  116.     }
  117.     public function getMember(): ?Member
  118.     {
  119.         return $this->member;
  120.     }
  121.     public function setMember(?Member $member): self
  122.     {
  123.         $this->member $member;
  124.         return $this;
  125.     }
  126.     public function isArchived(): bool
  127.     {
  128.         return (bool) $this->archived;
  129.     }
  130.     public function setArchived(?bool $archived): self
  131.     {
  132.         $this->archived $archived;
  133.         return $this;
  134.     }
  135.     public function getArchivedDate(): ?\DateTimeInterface
  136.     {
  137.         return $this->dateArchived;
  138.     }
  139.     public function setArchivedDate(?\DateTimeInterface $dateArchived): self
  140.     {
  141.         $this->dateArchived $dateArchived;
  142.         return $this;
  143.     }
  144.     public function getInitState(): ?bool
  145.     {
  146.         return $this->initState;
  147.     }
  148.     public function setInitState(?bool $initState): self
  149.     {
  150.         $this->initState $initState;
  151.         return $this;
  152.     }
  153.     public function getPostCat(): ?int
  154.     {
  155.         return $this->postCat;
  156.     }
  157.     public function setPostCat(?int $postCat): self
  158.     {
  159.         $this->postCat $postCat;
  160.         return $this;
  161.     }
  162.     public function getName(): string
  163.     {
  164.         return $this->name;
  165.     }
  166.     public function setName(string $name): self
  167.     {
  168.         $this->name trim($name);
  169.         return $this;
  170.     }
  171.     public function getColour(): ?string
  172.     {
  173.         return $this->colour;
  174.     }
  175.     public function setColour(string $colour): self
  176.     {
  177.         $this->colour $colour;
  178.         return $this;
  179.     }
  180.     public function getStartDate(): ?\DateTimeInterface
  181.     {
  182.         return $this->startDate;
  183.     }
  184.     public function isSeasonal(): bool
  185.     {
  186.         return $this->startDate !== null && $this->endDate !== null;
  187.     }
  188.     public function isSeasonallyPaused(): bool
  189.     {
  190.         return $this->seasonallyPaused ?? false;
  191.     }
  192.     public function calculateSeasonallyPaused(): self
  193.     {
  194.         $now Carbon::now()
  195.             ->setTimezone($this->workspace?->getTimezone() ?: $this->member->getTimezone())
  196.             ->shiftTimezone('UTC');
  197.         $this->seasonallyPaused $this->startDate instanceof \DateTimeInterface
  198.             && $this->endDate instanceof \DateTimeInterface
  199.             && ($now->endOfDay() < $this->startDate || $now->startOfDay() > $this->endDate);
  200.         return $this;
  201.     }
  202.     public function setSeasonalDates(?\DateTimeInterface $startDate, ?\DateTimeInterface $endDate): self
  203.     {
  204.         $this->startDate $startDate;
  205.         $this->endDate $endDate;
  206.         $this->calculateSeasonallyPaused();
  207.         return $this;
  208.     }
  209.     public function getEndDate(): ?\DateTimeInterface
  210.     {
  211.         return $this->endDate;
  212.     }
  213.     public function getWorkspace(): Workspace
  214.     {
  215.         return $this->workspace;
  216.     }
  217.     public function setWorkspace(?Workspace $workspace): self
  218.     {
  219.         $this->workspace?->removeCategory($this);
  220.         $this->workspace $workspace;
  221.         $this->workspace?->addCategory($this);
  222.         return $this;
  223.     }
  224.     public function getArchivedAttachedPostCount(): ?int
  225.     {
  226.         return $this->archivedAttachedPostCount;
  227.     }
  228.     public function setArchivedAttachedPostCount(?int $archivedAttachedPostCount): self
  229.     {
  230.         $this->archivedAttachedPostCount $archivedAttachedPostCount;
  231.         return $this;
  232.     }
  233.     public function isLegacyWithoutWorkspace(): bool
  234.     {
  235.         return $this->workspace === null;
  236.     }
  237.     public function getDefaultSocialProfiles(): Collection
  238.     {
  239.         return $this->defaultSocialProfiles->filter(function (SocialProfile $profile): bool
  240.         {
  241.             return !$profile->isDeleted();
  242.         });
  243.     }
  244.     public function addDefaultSocialProfile(SocialProfile $socialProfile): self
  245.     {
  246.         if (!$this->defaultSocialProfiles->contains($socialProfile))
  247.         {
  248.             $this->defaultSocialProfiles->add($socialProfile);
  249.         }
  250.         return $this;
  251.     }
  252.     public function removeDefaultSocialProfile(SocialProfile $socialProfile): self
  253.     {
  254.         if ($this->defaultSocialProfiles->contains($socialProfile))
  255.         {
  256.             $this->defaultSocialProfiles->removeElement($socialProfile);
  257.         }
  258.         return $this;
  259.     }
  260.     public function isOnboardingContent(): bool
  261.     {
  262.         return $this->onboardingContent;
  263.     }
  264. }