<?php
namespace Sq\Entity\Schema\ORM;
use Carbon\Carbon;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* PostCategory.
*/
#[ORM\Entity(repositoryClass: \Sq\Service\Repository\ORM\CategoryRepository::class)]
#[ORM\Table(name: 'queue_post_cat')]
#[ORM\Index(name: 'qpc_seasonally_paused', columns: ['qpc_seasonally_paused'])]
#[ORM\Index(name: 'qpc_m_id', columns: ['qpc_m_id'])]
class PostCategory implements BelongsToWorkspaceInterface, OnboardingContentInterface
{
/**
* @var int
*/
#[ORM\Column(name: 'qpc_id', type: 'integer', nullable: false, options: ['unsigned' => true])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var Member|null
*/
#[ORM\ManyToOne(targetEntity: Member::class, inversedBy: 'categories')]
#[ORM\JoinColumn(name: 'qpc_m_id', referencedColumnName: 'm_id', nullable: true)]
private $member;
/**
* @var bool|null
*/
#[ORM\Column(name: 'qpc_seasonally_paused', type: 'boolean', nullable: true)]
private $seasonallyPaused = false;
/**
* @var bool|null
*/
#[ORM\Column(name: 'qpc_archived', type: 'boolean', nullable: true)]
private $archived = false;
/**
* @var \DateTimeInterface|null
*/
#[ORM\Column(name: 'qpc_date_archived', type: 'datetime', nullable: true)]
private $dateArchived;
/**
* @var bool|null
*/
#[ORM\Column(name: 'qpc_init_state', type: 'boolean', nullable: true)]
private $initState = false;
/**
* @var int|null
*/
#[ORM\Column(name: 'qpc_post_cat', type: 'smallint', nullable: true, options: ['default' => 1])]
private $postCat = 1;
/**
* @var string|null
*/
#[ORM\Column(name: 'qpc_name', type: 'string', length: 191, nullable: true)]
private $name;
/**
* @var string
*/
#[ORM\Column(name: 'qpc_colour', type: 'string', length: 7, nullable: false)]
private $colour;
/**
* @var \DateTimeInterface|null
*/
#[ORM\Column(name: 'qpc_start_date', type: 'date', nullable: true)]
private $startDate;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'qpc_end_date', type: 'date', nullable: true)]
private $endDate;
/**
*
* @var Workspace|null
*/
#[ORM\ManyToOne(targetEntity: Workspace::class, inversedBy: 'postCategories')]
#[ORM\JoinColumn(name: 'qpc_ws_id', referencedColumnName: 'ws_id', nullable: true)]
private $workspace;
/**
*
* @var Collection<SocialProfile>
*/
#[ORM\ManyToMany(targetEntity: SocialNetwork::class, cascade: ['persist'])]
#[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')])]
private $defaultSocialProfiles;
#[ORM\OneToMany(targetEntity: QueueSchedule::class, mappedBy: 'category', cascade: ['persist', 'remove'])]
private Collection $timeslots;
#[ORM\OneToMany(targetEntity: QueueMetadata::class, mappedBy: 'category', cascade: ['remove'], fetch: 'EXTRA_LAZY')]
protected $queueMetadatas;
/**
* @var bool
*/
#[ORM\Column(name: 'qpc_onboarding_content', type: 'boolean', nullable: false)]
protected $onboardingContent = false;
#[ORM\Column(name: 'qpc_archived_attached_post_count', type: 'integer', nullable: true)]
protected $archivedAttachedPostCount;
public function __construct(
string $name,
string $colourHex,
?Workspace $workspace = null,
bool $isOnboardingContent = false
) {
$this->name = $name;
$this->colour = $colourHex;
$this->workspace = $workspace;
$this->onboardingContent = $isOnboardingContent;
$this->defaultSocialProfiles = new ArrayCollection();
$this->timeslots = new ArrayCollection();
$workspace?->addCategory($this);
}
public function getId(): ?int
{
return $this->id;
}
public function getMember(): ?Member
{
return $this->member;
}
public function setMember(?Member $member): self
{
$this->member = $member;
return $this;
}
public function isArchived(): bool
{
return (bool) $this->archived;
}
public function setArchived(?bool $archived): self
{
$this->archived = $archived;
return $this;
}
public function getArchivedDate(): ?\DateTimeInterface
{
return $this->dateArchived;
}
public function setArchivedDate(?\DateTimeInterface $dateArchived): self
{
$this->dateArchived = $dateArchived;
return $this;
}
public function getInitState(): ?bool
{
return $this->initState;
}
public function setInitState(?bool $initState): self
{
$this->initState = $initState;
return $this;
}
public function getPostCat(): ?int
{
return $this->postCat;
}
public function setPostCat(?int $postCat): self
{
$this->postCat = $postCat;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = trim($name);
return $this;
}
public function getColour(): ?string
{
return $this->colour;
}
public function setColour(string $colour): self
{
$this->colour = $colour;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function isSeasonal(): bool
{
return $this->startDate !== null && $this->endDate !== null;
}
public function isSeasonallyPaused(): bool
{
return $this->seasonallyPaused ?? false;
}
public function calculateSeasonallyPaused(): self
{
$now = Carbon::now()
->setTimezone($this->workspace?->getTimezone() ?: $this->member->getTimezone())
->shiftTimezone('UTC');
$this->seasonallyPaused = $this->startDate instanceof \DateTimeInterface
&& $this->endDate instanceof \DateTimeInterface
&& ($now->endOfDay() < $this->startDate || $now->startOfDay() > $this->endDate);
return $this;
}
public function setSeasonalDates(?\DateTimeInterface $startDate, ?\DateTimeInterface $endDate): self
{
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->calculateSeasonallyPaused();
return $this;
}
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
public function getWorkspace(): Workspace
{
return $this->workspace;
}
public function setWorkspace(?Workspace $workspace): self
{
$this->workspace?->removeCategory($this);
$this->workspace = $workspace;
$this->workspace?->addCategory($this);
return $this;
}
public function getArchivedAttachedPostCount(): ?int
{
return $this->archivedAttachedPostCount;
}
public function setArchivedAttachedPostCount(?int $archivedAttachedPostCount): self
{
$this->archivedAttachedPostCount = $archivedAttachedPostCount;
return $this;
}
public function isLegacyWithoutWorkspace(): bool
{
return $this->workspace === null;
}
public function getDefaultSocialProfiles(): Collection
{
return $this->defaultSocialProfiles->filter(function (SocialProfile $profile): bool
{
return !$profile->isDeleted();
});
}
public function addDefaultSocialProfile(SocialProfile $socialProfile): self
{
if (!$this->defaultSocialProfiles->contains($socialProfile))
{
$this->defaultSocialProfiles->add($socialProfile);
}
return $this;
}
public function removeDefaultSocialProfile(SocialProfile $socialProfile): self
{
if ($this->defaultSocialProfiles->contains($socialProfile))
{
$this->defaultSocialProfiles->removeElement($socialProfile);
}
return $this;
}
public function isOnboardingContent(): bool
{
return $this->onboardingContent;
}
}