src/JanusHercules/IndeedCampaignManagement/Domain/Entity/CampaignItem.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace JanusHercules\IndeedCampaignManagement\Domain\Entity;
  4. use App\Utility\DatabaseIdGenerator;
  5. use App\Utility\DateTimeUtility;
  6. use DateTime;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Exception;
  12. use JanusHercules\IndeedCampaignManagement\Domain\Enum\NotPublishableReason;
  13. use JanusHercules\IndeedCampaignManagement\Domain\Enum\RecurrentJobsSource;
  14. #[ORM\Entity]
  15. #[ORM\Table(name: 'icm_campaign_items')]
  16. #[ORM\UniqueConstraint(name: 'UNIQ_campaign_definition_recurrent_job', columns: ['icm_campaign_definitions_id', 'recurrent_job_id'])]
  17. class CampaignItem
  18. {
  19. /**
  20. * @throws Exception
  21. */
  22. public function __construct(
  23. string $recurrentJobId,
  24. CampaignDefinition $campaignDefinition,
  25. RecurrentJobsSource $recurrentJobsSource,
  26. ) {
  27. $this->createdAt = DateTimeUtility::createDateTimeUtc();
  28. $this->updatedAt = DateTimeUtility::createDateTimeUtc();
  29. $this->recurrentJobId = $recurrentJobId;
  30. $this->campaignDefinition = $campaignDefinition;
  31. $this->recurrentJobsSource = $recurrentJobsSource;
  32. $this->isCurrentlyPublished = false;
  33. $this->feedItemGenerationResults = new ArrayCollection();
  34. }
  35. #[ORM\Id]
  36. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  37. #[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
  38. #[ORM\Column(
  39. type : Types::GUID,
  40. unique: true
  41. )]
  42. private ?string $id = null;
  43. public function getId(): ?string
  44. {
  45. return $this->id;
  46. }
  47. #[ORM\Column(
  48. type: Types::GUID
  49. )]
  50. private string $recurrentJobId;
  51. public function getRecurrentJobId(): string
  52. {
  53. return $this->recurrentJobId;
  54. }
  55. #[ORM\ManyToOne(targetEntity: CampaignDefinition::class)]
  56. #[ORM\JoinColumn(
  57. name : 'icm_campaign_definitions_id',
  58. referencedColumnName: 'id',
  59. nullable : false,
  60. onDelete : 'CASCADE'
  61. )]
  62. private CampaignDefinition $campaignDefinition;
  63. public function getCampaignDefinition(): CampaignDefinition
  64. {
  65. return $this->campaignDefinition;
  66. }
  67. #[ORM\Column(
  68. type : Types::STRING,
  69. enumType: RecurrentJobsSource::class
  70. )]
  71. private RecurrentJobsSource $recurrentJobsSource;
  72. public function getRecurrentJobsSource(): RecurrentJobsSource
  73. {
  74. return $this->recurrentJobsSource;
  75. }
  76. public function setRecurrentJobsSource(
  77. RecurrentJobsSource $recurrentJobsSource
  78. ): void {
  79. $this->recurrentJobsSource = $recurrentJobsSource;
  80. }
  81. #[ORM\Column(
  82. type : Types::DATETIME_MUTABLE,
  83. nullable: false
  84. )]
  85. private DateTime $createdAt;
  86. public function getCreatedAt(): DateTime
  87. {
  88. return $this->createdAt;
  89. }
  90. #[ORM\Column(
  91. type : Types::DATETIME_MUTABLE,
  92. nullable: false
  93. )]
  94. private DateTime $updatedAt;
  95. public function getUpdatedAt(): DateTime
  96. {
  97. return $this->updatedAt;
  98. }
  99. #[ORM\Column(
  100. type : Types::DATETIME_MUTABLE,
  101. nullable: true
  102. )]
  103. private ?DateTime $firstPublishedAt = null;
  104. public function getFirstPublishedAt(): ?DateTime
  105. {
  106. return $this->firstPublishedAt;
  107. }
  108. public function setFirstPublishedAt(?DateTime $firstPublishedAt): void
  109. {
  110. $this->firstPublishedAt = $firstPublishedAt;
  111. }
  112. #[ORM\Column(
  113. type : Types::DATETIME_MUTABLE,
  114. nullable: true
  115. )]
  116. private ?DateTime $lastPublishedAt = null;
  117. public function getLastPublishedAt(): ?DateTime
  118. {
  119. return $this->lastPublishedAt;
  120. }
  121. public function setLastPublishedAt(?DateTime $lastPublishedAt): void
  122. {
  123. $this->lastPublishedAt = $lastPublishedAt;
  124. }
  125. #[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
  126. private bool $isCurrentlyPublished = false;
  127. public function isCurrentlyPublished(): bool
  128. {
  129. return $this->isCurrentlyPublished;
  130. }
  131. public function setIsCurrentlyPublished(bool $isCurrentlyPublished): void
  132. {
  133. $this->isCurrentlyPublished = $isCurrentlyPublished;
  134. }
  135. #[ORM\Column(
  136. type : Types::BOOLEAN,
  137. nullable: false,
  138. options : ['default' => false]
  139. )]
  140. private bool $manuallyDoNotPublish = false;
  141. public function isManuallyDoNotPublish(): bool
  142. {
  143. return $this->manuallyDoNotPublish;
  144. }
  145. public function setManuallyDoNotPublish(bool $manuallyDoNotPublish): void
  146. {
  147. $this->manuallyDoNotPublish = $manuallyDoNotPublish;
  148. }
  149. #[ORM\Column(type: Types::STRING, enumType: NotPublishableReason::class, nullable: true)]
  150. private ?NotPublishableReason $notPublishableReason = null;
  151. public function getNotPublishableReason(): ?NotPublishableReason
  152. {
  153. return $this->notPublishableReason;
  154. }
  155. public function setNotPublishableReason(?NotPublishableReason $notPublishableReason): void
  156. {
  157. $this->notPublishableReason = $notPublishableReason;
  158. }
  159. #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  160. private ?DateTime $lastNotPublishedAt = null;
  161. public function getLastNotPublishedAt(): ?DateTime
  162. {
  163. return $this->lastNotPublishedAt;
  164. }
  165. public function setLastNotPublishedAt(?DateTime $lastNotPublishedAt): void
  166. {
  167. $this->lastNotPublishedAt = $lastNotPublishedAt;
  168. }
  169. #[ORM\ManyToOne(targetEntity: CampaignItem::class)]
  170. #[ORM\JoinColumn(
  171. name : 'moved_to_campaign_item_id',
  172. referencedColumnName: 'id',
  173. nullable : true,
  174. onDelete : 'SET NULL'
  175. )]
  176. private ?CampaignItem $movedToCampaignItem = null;
  177. public function getMovedToCampaignItem(): ?CampaignItem
  178. {
  179. return $this->movedToCampaignItem;
  180. }
  181. public function setMovedToCampaignItem(?CampaignItem $movedToCampaignItem): void
  182. {
  183. $this->movedToCampaignItem = $movedToCampaignItem;
  184. }
  185. #[ORM\ManyToOne(
  186. targetEntity: CampaignContentSnapshot::class,
  187. cascade : ['persist']
  188. )]
  189. #[ORM\JoinColumn(
  190. name : 'icm_campaign_content_snapshots_id',
  191. referencedColumnName: 'id',
  192. nullable : true,
  193. onDelete : 'SET NULL'
  194. )]
  195. private ?CampaignContentSnapshot $publishedCampaignContentSnapshot = null;
  196. public function getPublishedCampaignContentSnapshot(): ?CampaignContentSnapshot
  197. {
  198. return $this->publishedCampaignContentSnapshot;
  199. }
  200. public function setPublishedCampaignContentSnapshot(?CampaignContentSnapshot $publishedCampaignContentSnapshot): void
  201. {
  202. $this->publishedCampaignContentSnapshot = $publishedCampaignContentSnapshot;
  203. }
  204. /**
  205. * @var Collection<int, FeedItemGenerationResult>
  206. */
  207. #[ORM\OneToMany(mappedBy: 'campaignItem', targetEntity: FeedItemGenerationResult::class)]
  208. private Collection $feedItemGenerationResults;
  209. /**
  210. * @return Collection<int, FeedItemGenerationResult>
  211. */
  212. public function getFeedItemGenerationResults(): Collection
  213. {
  214. return $this->feedItemGenerationResults;
  215. }
  216. public function addFeedItemGenerationResult(FeedItemGenerationResult $feedItemGenerationResult): void
  217. {
  218. if (!$this->feedItemGenerationResults->contains($feedItemGenerationResult)) {
  219. $this->feedItemGenerationResults[] = $feedItemGenerationResult;
  220. $feedItemGenerationResult->setCampaignItem($this);
  221. }
  222. }
  223. }