<?php
declare(strict_types=1);
namespace JanusHercules\IndeedCampaignManagement\Domain\Entity;
use App\Utility\DatabaseIdGenerator;
use App\Utility\DateTimeUtility;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use JanusHercules\IndeedCampaignManagement\Domain\Enum\NotPublishableReason;
use JanusHercules\IndeedCampaignManagement\Domain\Enum\RecurrentJobsSource;
#[ORM\Entity]
#[ORM\Table(name: 'icm_campaign_items')]
#[ORM\UniqueConstraint(name: 'UNIQ_campaign_definition_recurrent_job', columns: ['icm_campaign_definitions_id', 'recurrent_job_id'])]
class CampaignItem
{
/**
* @throws Exception
*/
public function __construct(
string $recurrentJobId,
CampaignDefinition $campaignDefinition,
RecurrentJobsSource $recurrentJobsSource,
) {
$this->createdAt = DateTimeUtility::createDateTimeUtc();
$this->updatedAt = DateTimeUtility::createDateTimeUtc();
$this->recurrentJobId = $recurrentJobId;
$this->campaignDefinition = $campaignDefinition;
$this->recurrentJobsSource = $recurrentJobsSource;
$this->isCurrentlyPublished = false;
$this->feedItemGenerationResults = new ArrayCollection();
}
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[ORM\Column(
type : Types::GUID,
unique: true
)]
private ?string $id = null;
public function getId(): ?string
{
return $this->id;
}
#[ORM\Column(
type: Types::GUID
)]
private string $recurrentJobId;
public function getRecurrentJobId(): string
{
return $this->recurrentJobId;
}
#[ORM\ManyToOne(targetEntity: CampaignDefinition::class)]
#[ORM\JoinColumn(
name : 'icm_campaign_definitions_id',
referencedColumnName: 'id',
nullable : false,
onDelete : 'CASCADE'
)]
private CampaignDefinition $campaignDefinition;
public function getCampaignDefinition(): CampaignDefinition
{
return $this->campaignDefinition;
}
#[ORM\Column(
type : Types::STRING,
enumType: RecurrentJobsSource::class
)]
private RecurrentJobsSource $recurrentJobsSource;
public function getRecurrentJobsSource(): RecurrentJobsSource
{
return $this->recurrentJobsSource;
}
public function setRecurrentJobsSource(
RecurrentJobsSource $recurrentJobsSource
): void {
$this->recurrentJobsSource = $recurrentJobsSource;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $updatedAt;
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $firstPublishedAt = null;
public function getFirstPublishedAt(): ?DateTime
{
return $this->firstPublishedAt;
}
public function setFirstPublishedAt(?DateTime $firstPublishedAt): void
{
$this->firstPublishedAt = $firstPublishedAt;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $lastPublishedAt = null;
public function getLastPublishedAt(): ?DateTime
{
return $this->lastPublishedAt;
}
public function setLastPublishedAt(?DateTime $lastPublishedAt): void
{
$this->lastPublishedAt = $lastPublishedAt;
}
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $isCurrentlyPublished = false;
public function isCurrentlyPublished(): bool
{
return $this->isCurrentlyPublished;
}
public function setIsCurrentlyPublished(bool $isCurrentlyPublished): void
{
$this->isCurrentlyPublished = $isCurrentlyPublished;
}
#[ORM\Column(
type : Types::BOOLEAN,
nullable: false,
options : ['default' => false]
)]
private bool $manuallyDoNotPublish = false;
public function isManuallyDoNotPublish(): bool
{
return $this->manuallyDoNotPublish;
}
public function setManuallyDoNotPublish(bool $manuallyDoNotPublish): void
{
$this->manuallyDoNotPublish = $manuallyDoNotPublish;
}
#[ORM\Column(type: Types::STRING, enumType: NotPublishableReason::class, nullable: true)]
private ?NotPublishableReason $notPublishableReason = null;
public function getNotPublishableReason(): ?NotPublishableReason
{
return $this->notPublishableReason;
}
public function setNotPublishableReason(?NotPublishableReason $notPublishableReason): void
{
$this->notPublishableReason = $notPublishableReason;
}
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTime $lastNotPublishedAt = null;
public function getLastNotPublishedAt(): ?DateTime
{
return $this->lastNotPublishedAt;
}
public function setLastNotPublishedAt(?DateTime $lastNotPublishedAt): void
{
$this->lastNotPublishedAt = $lastNotPublishedAt;
}
#[ORM\ManyToOne(targetEntity: CampaignItem::class)]
#[ORM\JoinColumn(
name : 'moved_to_campaign_item_id',
referencedColumnName: 'id',
nullable : true,
onDelete : 'SET NULL'
)]
private ?CampaignItem $movedToCampaignItem = null;
public function getMovedToCampaignItem(): ?CampaignItem
{
return $this->movedToCampaignItem;
}
public function setMovedToCampaignItem(?CampaignItem $movedToCampaignItem): void
{
$this->movedToCampaignItem = $movedToCampaignItem;
}
#[ORM\ManyToOne(
targetEntity: CampaignContentSnapshot::class,
cascade : ['persist']
)]
#[ORM\JoinColumn(
name : 'icm_campaign_content_snapshots_id',
referencedColumnName: 'id',
nullable : true,
onDelete : 'SET NULL'
)]
private ?CampaignContentSnapshot $publishedCampaignContentSnapshot = null;
public function getPublishedCampaignContentSnapshot(): ?CampaignContentSnapshot
{
return $this->publishedCampaignContentSnapshot;
}
public function setPublishedCampaignContentSnapshot(?CampaignContentSnapshot $publishedCampaignContentSnapshot): void
{
$this->publishedCampaignContentSnapshot = $publishedCampaignContentSnapshot;
}
/**
* @var Collection<int, FeedItemGenerationResult>
*/
#[ORM\OneToMany(mappedBy: 'campaignItem', targetEntity: FeedItemGenerationResult::class)]
private Collection $feedItemGenerationResults;
/**
* @return Collection<int, FeedItemGenerationResult>
*/
public function getFeedItemGenerationResults(): Collection
{
return $this->feedItemGenerationResults;
}
public function addFeedItemGenerationResult(FeedItemGenerationResult $feedItemGenerationResult): void
{
if (!$this->feedItemGenerationResults->contains($feedItemGenerationResult)) {
$this->feedItemGenerationResults[] = $feedItemGenerationResult;
$feedItemGenerationResult->setCampaignItem($this);
}
}
}