src/JanusHercules/IndeedCampaignManagement/Domain/Entity/CampaignDefinition.php line 18

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\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Exception;
  10. use JanusHercules\IndeedCampaignManagement\Domain\Enum\CampaignType;
  11. use ValueError;
  12. #[ORM\Entity]
  13. #[ORM\Table(name: 'icm_campaign_definitions')]
  14. class CampaignDefinition
  15. {
  16. /**
  17. * @throws Exception
  18. */
  19. public function __construct(
  20. string $name,
  21. DateTime $validFrom,
  22. DateTime $validUntil,
  23. int $poolSize,
  24. CampaignType $campaignType,
  25. ?string $forRecurrentJobId = null,
  26. ?string $forCustomerInternalId = null,
  27. ) {
  28. $this->poolSize = $poolSize;
  29. $this->campaignType = $campaignType;
  30. $this->name = $name;
  31. $this->createdAt = DateTimeUtility::createDateTimeUtc();
  32. $this->validFrom = $validFrom;
  33. $this->validUntil = $validUntil;
  34. $this->forRecurrentJobId = $forRecurrentJobId;
  35. $this->forCustomerInternalId = $forCustomerInternalId;
  36. if (($campaignType === CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN || $campaignType->isFlexMembershipType()) && is_null($forRecurrentJobId)) {
  37. throw new ValueError('For flex higher-priced membership and self-service traffic campaigns, a recurrent job id must be provided.');
  38. }
  39. if ($campaignType === CampaignType::CUSTOMER && is_null($forCustomerInternalId)) {
  40. throw new ValueError('For customer campaigns, a customer internal id must be provided.');
  41. }
  42. if (($campaignType === CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN || $campaignType->isFlexMembershipType()) && !is_null($forCustomerInternalId)) {
  43. throw new ValueError('For flex higher-priced membership and self-service traffic campaigns, a customer internal id must not be provided.');
  44. }
  45. if ($campaignType === CampaignType::CUSTOMER && !is_null($forRecurrentJobId)) {
  46. throw new ValueError('For customer campaigns, a recurrent job id must not be provided.');
  47. }
  48. if (!$campaignType->isFlexMembershipType() && $campaignType !== CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN && $campaignType !== CampaignType::CUSTOMER && (!is_null($forRecurrentJobId) || !is_null($forCustomerInternalId))) {
  49. throw new ValueError('For non-flex-higher-priced-membership and non-self-service traffic campaigns and non-customer campaigns, neither recurrent job id nor customer internal id must be provided.');
  50. }
  51. if (($campaignType === CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN || $campaignType->isFlexMembershipType()) && $poolSize !== 1) {
  52. throw new ValueError('For self-service traffic campaigns, the pool size must be 1.');
  53. }
  54. }
  55. #[ORM\Id]
  56. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  57. #[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
  58. #[ORM\Column(
  59. type : Types::GUID,
  60. unique: true
  61. )]
  62. private ?string $id = null;
  63. public function getId(): ?string
  64. {
  65. return $this->id;
  66. }
  67. #[ORM\Column(
  68. type : Types::STRING,
  69. enumType: CampaignType::class
  70. )]
  71. private CampaignType $campaignType;
  72. public function getCampaignType(): CampaignType
  73. {
  74. return $this->campaignType;
  75. }
  76. #[ORM\Column(
  77. type : Types::STRING,
  78. nullable: false,
  79. )]
  80. private string $name;
  81. public function getName(): string
  82. {
  83. return $this->name;
  84. }
  85. #[ORM\Column(
  86. type : Types::DATETIME_MUTABLE,
  87. nullable: false
  88. )]
  89. private DateTime $createdAt;
  90. public function getCreatedAt(): DateTime
  91. {
  92. return $this->createdAt;
  93. }
  94. #[ORM\Column(
  95. type : Types::DATETIME_MUTABLE,
  96. nullable: true
  97. )]
  98. private DateTime $validFrom;
  99. public function getValidFrom(): DateTime
  100. {
  101. return $this->validFrom;
  102. }
  103. public function setValidFrom(DateTime $validFrom): void
  104. {
  105. $this->validFrom = $validFrom;
  106. }
  107. #[ORM\Column(
  108. type : Types::DATETIME_MUTABLE,
  109. nullable: true
  110. )]
  111. private DateTime $validUntil;
  112. public function getValidUntil(): DateTime
  113. {
  114. return $this->validUntil;
  115. }
  116. public function setValidUntil(DateTime $validUntil): void
  117. {
  118. $this->validUntil = $validUntil;
  119. }
  120. #[ORM\Column(
  121. type : Types::INTEGER,
  122. nullable: false,
  123. )]
  124. private int $poolSize;
  125. public function getPoolSize(): int
  126. {
  127. return $this->poolSize;
  128. }
  129. public function setPoolSize(int $poolSize): void
  130. {
  131. $this->poolSize = $poolSize;
  132. }
  133. #[ORM\Column(
  134. type : Types::STRING,
  135. nullable: true
  136. )]
  137. private ?string $forRecurrentJobId = null;
  138. public function getForRecurrentJobId(): ?string
  139. {
  140. return $this->forRecurrentJobId;
  141. }
  142. #[ORM\Column(
  143. type : Types::STRING,
  144. nullable: true
  145. )]
  146. private ?string $forCustomerInternalId = null;
  147. public function getForCustomerInternalId(): ?string
  148. {
  149. return $this->forCustomerInternalId;
  150. }
  151. }