src/App/Entity/ExternalPartner/ExternalJoboffer.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ExternalPartner;
  3. use App\Entity\RecurrentJob;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use InvalidArgumentException;
  7. /**
  8. * @ORM\Entity
  9. *
  10. * @ORM\Table(
  11. * name="external_joboffers",
  12. * uniqueConstraints={
  13. *
  14. * @ORM\UniqueConstraint(name="external_partners_id_external_id_unique_idx", columns={"external_partners_id", "external_id"})
  15. * }
  16. * )
  17. */
  18. class ExternalJoboffer
  19. {
  20. public const EMPLOYMENT_TYPE_PART_TIME = RecurrentJob::EMPLOYMENT_TYPE_PART_TIME;
  21. public const EMPLOYMENT_TYPE_FULL_TIME = RecurrentJob::EMPLOYMENT_TYPE_FULL_TIME;
  22. public function __construct(
  23. ExternalPartner $externalPartner,
  24. string $externalId,
  25. string $url,
  26. ?string $logoUrl,
  27. string $businessName,
  28. string $title,
  29. string $description,
  30. string $zipcode,
  31. string $city,
  32. array $employmentTypes,
  33. ?float $cpc,
  34. DateTime $createdAt
  35. ) {
  36. $this->externalPartner = $externalPartner;
  37. $this->externalId = mb_substr($externalId, 0, 255);
  38. $this->setUrl($url);
  39. $this->setLogoUrl($logoUrl);
  40. $this->setBusinessName($businessName);
  41. $this->setTitle($title);
  42. $this->setDescription($description);
  43. $this->setZipcode($zipcode);
  44. $this->setCity($city);
  45. $this->setEmploymentTypes($employmentTypes);
  46. $this->setCpc($cpc);
  47. $this->setCreatedAt($createdAt);
  48. }
  49. /**
  50. * @ORM\GeneratedValue(strategy="CUSTOM")
  51. *
  52. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  53. *
  54. * @ORM\Column(name="id", type="guid")
  55. *
  56. * @ORM\Id
  57. */
  58. private ?string $id = null;
  59. public function getId(): ?string
  60. {
  61. return $this->id;
  62. }
  63. /**
  64. * @ORM\Column(name="external_id", type="text", length=255)
  65. */
  66. private string $externalId;
  67. public function getExternalId(): string
  68. {
  69. return $this->externalId;
  70. }
  71. /**
  72. * @ORM\ManyToOne(targetEntity="App\Entity\ExternalPartner\ExternalPartner", cascade={"persist"})
  73. *
  74. * @ORM\JoinColumn(name="external_partners_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  75. */
  76. private ExternalPartner $externalPartner;
  77. public function getExternalPartner(): ExternalPartner
  78. {
  79. return $this->externalPartner;
  80. }
  81. public function getExternalPartnerId(): string
  82. {
  83. return $this->externalPartner->getId();
  84. }
  85. /**
  86. * @ORM\Column(name="url", type="text", length=8192, nullable=false)
  87. */
  88. private string $url;
  89. public function getUrl(): string
  90. {
  91. return $this->url;
  92. }
  93. public function setUrl(string $url): void
  94. {
  95. $this->url = mb_substr($url, 0, 8192);
  96. }
  97. /**
  98. * @ORM\Column(name="logo_url", type="text", length=8192, nullable=true)
  99. */
  100. private ?string $logoUrl = null;
  101. public function getLogoUrl(): ?string
  102. {
  103. return $this->logoUrl;
  104. }
  105. public function setLogoUrl(?string $url): void
  106. {
  107. if (is_null($url)) {
  108. $this->logoUrl = $url;
  109. } else {
  110. $this->logoUrl = mb_substr($url, 0, 8192);
  111. }
  112. }
  113. /**
  114. * @ORM\Column(name="business_name", type="text", length=8192, nullable=false)
  115. */
  116. private string $businessName;
  117. public function getBusinessName(): string
  118. {
  119. return mb_ereg_replace('&amp;', '&', $this->businessName);
  120. }
  121. public function setBusinessName(string $businessName): void
  122. {
  123. $this->businessName = mb_substr($businessName, 0, 8192);
  124. }
  125. /**
  126. * @ORM\Column(name="title", type="text", length=8192, nullable=false)
  127. */
  128. private string $title;
  129. public function getTitle(): string
  130. {
  131. return mb_ereg_replace('&amp;', '&', $this->title);
  132. }
  133. public function setTitle(string $title): void
  134. {
  135. $this->title = mb_substr($title, 0, 8192);
  136. }
  137. /**
  138. * @ORM\Column(name="description", type="text", length=16384, nullable=false)
  139. */
  140. private string $description;
  141. public function getDescription(): string
  142. {
  143. return mb_ereg_replace('&amp;', '&', $this->description);
  144. }
  145. public function getDescriptionPlainText(): string
  146. {
  147. $description = $this->getDescription();
  148. $description = mb_eregi_replace('&lt;', '<', $description);
  149. $description = mb_eregi_replace('&gt;', '>', $description);
  150. $description = mb_eregi_replace('</', ' </', $description);
  151. $description = strip_tags($description);
  152. return $description;
  153. }
  154. public function setDescription(string $description): void
  155. {
  156. $this->description = mb_substr($description, 0, 16384);
  157. }
  158. /**
  159. * @ORM\Column(name="zipcode", type="text", length=5, nullable=false)
  160. */
  161. private string $zipcode;
  162. public function getZipcode(): string
  163. {
  164. return $this->zipcode;
  165. }
  166. public function setZipcode(string $zipcode): void
  167. {
  168. $trimmedZipcode = trim($zipcode);
  169. if (mb_strlen($trimmedZipcode) !== 5 || !is_numeric($trimmedZipcode)) {
  170. throw new InvalidArgumentException("zipcode must be a string with 5 digits, but got '$zipcode'");
  171. }
  172. $zipcode = $trimmedZipcode;
  173. $this->zipcode = $zipcode;
  174. }
  175. /**
  176. * @ORM\Column(name="city", type="text", length=255, nullable=false)
  177. */
  178. private string $city;
  179. public function getCity(): string
  180. {
  181. return $this->city;
  182. }
  183. public function setCity(string $city): void
  184. {
  185. $this->city = mb_substr($city, 0, 255);
  186. }
  187. /**
  188. * @var int[]
  189. *
  190. * @ORM\Column(name="employment_types", type="array", nullable=false)
  191. */
  192. private array $employmentTypes;
  193. /**
  194. * @param int[] $employmentTypes
  195. *
  196. * @throws InvalidArgumentException
  197. */
  198. public function setEmploymentTypes(array $employmentTypes)
  199. {
  200. $seen = [];
  201. foreach ($employmentTypes as $employmentType) {
  202. if (!is_int($employmentType) || $employmentType < self::EMPLOYMENT_TYPE_PART_TIME || $employmentType > self::EMPLOYMENT_TYPE_FULL_TIME) {
  203. throw new InvalidArgumentException('Invalid value ' . $employmentType . ' for employmentType.');
  204. }
  205. if (in_array($employmentType, $seen)) {
  206. throw new InvalidArgumentException('Duplicate value ' . $employmentType . ' for employmentType.');
  207. }
  208. $seen[] = $employmentType;
  209. }
  210. $this->employmentTypes = $employmentTypes;
  211. }
  212. /** @return int[] */
  213. public function getEmploymentTypes(): array
  214. {
  215. return $this->employmentTypes;
  216. }
  217. /**
  218. * @ORM\Column(name="cpc", type="float", nullable=true, options={"unsigned": true})
  219. */
  220. private ?float $cpc;
  221. public function setCpc(?float $cpc): void
  222. {
  223. $this->cpc = $cpc;
  224. }
  225. public function getCpc(): ?float
  226. {
  227. return $this->cpc;
  228. }
  229. /**
  230. * @ORM\Column(name="created_at", type="datetime", nullable=true)
  231. */
  232. private ?DateTime $createdAt;
  233. public function setCreatedAt(?DateTime $createdAt): void
  234. {
  235. $this->createdAt = $createdAt;
  236. }
  237. public function getCreatedAt(): ?DateTime
  238. {
  239. return $this->createdAt;
  240. }
  241. }