WebflowCollectionEvent.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. use App\Serializer\ItemSerializedName;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  9. /**
  10. * @ApiResource(
  11. * itemOperations={"get"},
  12. * collectionOperations={"get" = {
  13. * "normalization_context" = {
  14. * "groups" = {"event:collection:read"},
  15. * },
  16. * }, "post" = {
  17. * "denormalization_context" = {
  18. * "groups" = {"event:collection:write"},
  19. * },
  20. * }}
  21. * )
  22. */
  23. class WebflowCollectionEvent extends AbstractWebflowCollectionItem {
  24. /**
  25. * @ApiProperty(identifier=true)
  26. * @Groups({
  27. * "event:collection:read",
  28. * })
  29. * @ItemSerializedName("_id")
  30. */
  31. protected $id;
  32. /**
  33. * @Groups({
  34. * "event:collection:read",
  35. * })
  36. * @ItemSerializedName("_cid")
  37. */
  38. protected static $cid = '5ebbafce7b593028a5f8f29a';
  39. /**
  40. * @Groups({
  41. * "event:collection:write",
  42. * })
  43. * @ItemSerializedName("@ignore")
  44. * @Assert\NotNull
  45. */
  46. private $captcha;
  47. /**
  48. * @Groups({
  49. * "event:collection:read",
  50. * "event:collection:write"
  51. * })
  52. * @ItemSerializedName("name")
  53. * @Assert\NotNull
  54. */
  55. private $title;
  56. /*
  57. * @Groups({
  58. * "event:collection:read",
  59. * })
  60. */
  61. private $slug;
  62. /**
  63. * @Groups({
  64. * "event:collection:read",
  65. * "event:collection:write",
  66. * })
  67. * @ItemSerializedName("kjop-billett-link")
  68. * @Assert\Url(
  69. * message = "Url '{{ value }}' er ugyldig. Husk begynne med http://"
  70. * )
  71. * @Assert\NotNull
  72. */
  73. private $bookingUrl;
  74. /**
  75. * @Groups({
  76. * "event:collection:read",
  77. * "event:collection:write",
  78. * })
  79. * @ItemSerializedName("link-til-nettside")
  80. * @Assert\Url(
  81. * message = "Url '{{ value }}' er ugyldig. Husk begynne med http://"
  82. * )
  83. * @Assert\NotNull
  84. */
  85. private $websiteUrl;
  86. /**
  87. * @Groups({
  88. * "event:collection:read",
  89. * "event:collection:write",
  90. * })
  91. * @ItemSerializedName("kapasitet-tekst")
  92. * @Assert\NotNull(
  93. * message= "Vennligst oppgi kapasitet"
  94. * )
  95. */
  96. private $capacity;
  97. /**
  98. * @Groups({
  99. * "event:collection:read",
  100. * "event:collection:write",
  101. * })
  102. * @ItemSerializedName("sted-2")
  103. * @Assert\NotNull(
  104. * message= "Vennligst oppgi lokalisjon for eventet"
  105. * )
  106. */
  107. private $place;
  108. /**
  109. * @Groups({
  110. * "event:collection:read",
  111. * "event:collection:write",
  112. * })
  113. * @ItemSerializedName("organisasjonsnr")
  114. * @Assert\Length(
  115. * min = 9,
  116. * max = 9,
  117. * allowEmptyString = false,
  118. * )
  119. * @Assert\NotNull
  120. */
  121. private $organizationNumber;
  122. /**
  123. * @Groups({
  124. * "event:collection:read",
  125. * "event:collection:write",
  126. * })
  127. * @ItemSerializedName("arrangor")
  128. * @Assert\NotNull(
  129. * message= "Vennligst oppgi arrangør"
  130. * )
  131. */
  132. private $organizer;
  133. /**
  134. * @Groups({
  135. * "event:collection:read",
  136. * "event:collection:write",
  137. * })
  138. * @ItemSerializedName("kontaktperson")
  139. * @Assert\NotNull(
  140. * message= "Vennligst angi kontaktperson"
  141. * )
  142. */
  143. private $contactPerson;
  144. /**
  145. * @Groups({
  146. * "event:collection:read",
  147. * "event:collection:write",
  148. * })
  149. * @ItemSerializedName("e-post")
  150. * @Assert\Email(
  151. * message = "Epostadresse '{{ value }}' er ugyldig",
  152. * )
  153. * @Assert\NotNull
  154. */
  155. private $contactEmail;
  156. /**
  157. * @Groups({
  158. * "event:collection:read",
  159. * "event:collection:write",
  160. * })
  161. * @ItemSerializedName("telefonnummer")
  162. * @Assert\NotNull(
  163. * message= "Vennligst angi en kontakt-telefon"
  164. * )
  165. */
  166. private $contactPhone;
  167. /**
  168. * @Groups({
  169. * "event:collection:read",
  170. * "event:collection:write",
  171. * })
  172. * @Assert\NotNull
  173. */
  174. private $description;
  175. /**
  176. * @Groups({
  177. * "event:collection:read",
  178. * "event:collection:write",
  179. * })
  180. * @Assert\Url(
  181. * message = "Url '{{ value }}' er ugyldig. Husk begynne med http://"
  182. * )
  183. * @Assert\NotNull
  184. */
  185. private $image;
  186. /**
  187. * @ItemSerializedName("bilde")
  188. */
  189. private $bilde;
  190. /**
  191. * @Groups({
  192. * "event:collection:read",
  193. * "event:collection:write",
  194. * })
  195. * @ItemSerializedName("opptrer")
  196. * @Assert\Count(
  197. * min = 1,
  198. * minMessage = "Eventet må opptre minst {{ limit }} ganger"
  199. * )
  200. * @Assert\NotNull
  201. */
  202. private $happensOn = [];
  203. /**
  204. * @Groups({
  205. * "event:collection:read",
  206. * "event:collection:write",
  207. * })
  208. * @ItemSerializedName("kategorier")
  209. * @Assert\Count(
  210. * min = 1,
  211. * minMessage = "Eventet må ha minst {{ limit }} kategori"
  212. * )
  213. * @Assert\NotNull
  214. */
  215. private $categories = [];
  216. /**
  217. * @Groups({
  218. * "event:collection:read",
  219. * "event:collection:write",
  220. * })
  221. * @ItemSerializedName("malgruppe-r")
  222. * @Assert\Count(
  223. * min = 1,
  224. * minMessage = "Eventet må ha minst {{ limit }} målgruppe"
  225. * )
  226. * @Assert\NotNull
  227. */
  228. private $audiences = [];
  229. private $featured = false;
  230. public static function cid(): string {
  231. return self::$cid;
  232. }
  233. public function setCaptcha(string $c): self {
  234. $this->captcha = $c;
  235. return $this;
  236. }
  237. public function getCaptcha(): ?string {
  238. return $this->captcha;
  239. }
  240. public function getTitle(): ?string {
  241. return $this->title;
  242. }
  243. public function setTitle(string $n): self {
  244. $this->title = $n;
  245. return $this;
  246. }
  247. public function getSlug(): ?string {
  248. return $this->slug;
  249. }
  250. protected function setSlug(string $s): self {
  251. $this->slug = $s;
  252. return $this;
  253. }
  254. public function getContactEmail(): ?string {
  255. return $this->contactEmail;
  256. }
  257. public function setContactEmail(string $e): self {
  258. $this->contactEmail = $e;
  259. return $this;
  260. }
  261. public function getContactPhone(): ?string {
  262. return $this->contactPhone;
  263. }
  264. public function setContactPhone(string $s): self {
  265. $this->contactPhone = $s;
  266. return $this;
  267. }
  268. public function getBookingUrl(): ?string {
  269. return $this->bookingUrl;
  270. }
  271. public function setBookingUrl($s): self {
  272. $this->bookingUrl = $s;
  273. return $this;
  274. }
  275. public function getWebsiteUrl(): ?string {
  276. return $this->websiteUrl;
  277. }
  278. public function setWebsiteUrl(string $s): self {
  279. $this->websiteUrl = $s;
  280. return $this;
  281. }
  282. public function getCapacity(): ?string {
  283. return $this->capacity;
  284. }
  285. public function setCapacity(string $i): self {
  286. $this->capacity= $i;
  287. return $this;
  288. }
  289. public function getPlace(): ?string {
  290. return $this->place;
  291. }
  292. public function setPlace(string $s): self {
  293. $this->place = $s;
  294. return $this;
  295. }
  296. public function getContactPerson(): ?string {
  297. return $this->contactPerson;
  298. }
  299. public function setContactPerson(string $s): self {
  300. $this->contactPerson = $s;
  301. return $this;
  302. }
  303. public function getOrganizationNumber(): ?string {
  304. return $this->organizationNumber;
  305. }
  306. public function setOrganizationNumber(string $s): self {
  307. $this->organizationNumber = $s;
  308. return $this;
  309. }
  310. public function getOrganizer(): ?string {
  311. return $this->organizer;
  312. }
  313. public function setOrganizer(string $s): self {
  314. $this->organizer = $s;
  315. return $this;
  316. }
  317. public function getDescription(): ?string {
  318. return $this->description;
  319. }
  320. public function setDescription(string $s): self {
  321. $this->description = sprintf('<p>%s</p>', preg_replace('/[\\n]+/', '</p><p>', strip_tags($s)));
  322. return $this;
  323. }
  324. public function getImage() {
  325. return $this->image;
  326. }
  327. public function setImage($a): self {
  328. $this->image = $a;
  329. if (is_string($this->image))
  330. $this->bilde;
  331. return $this;
  332. }
  333. public function getBilde() {
  334. return $this->image;
  335. }
  336. public function getCategories(): ?array {
  337. $this->categories = array_map(function ($category) {
  338. return $category;
  339. }, $this->categories);
  340. return $this->categories;
  341. }
  342. public function setCategories(array $a): self {
  343. return $this->setKategorier($a);
  344. }
  345. protected function setKategorier(array $a): self {
  346. $this->categories = $a;
  347. return $this;
  348. }
  349. public function getAudiences(): ?array {
  350. $this->audiences = array_map(function ($audience) {
  351. return $audience;
  352. }, $this->audiences);
  353. return $this->audiences;
  354. }
  355. public function setAudiences(array $a): self {
  356. $this->audiences = $a;
  357. return $this;
  358. }
  359. public function getHappensOn(): ?array {
  360. return $this->happensOn;
  361. }
  362. public function setHappensOn(array $a): self {
  363. $this->happensOn = $a;
  364. return $this;
  365. }
  366. public function getFeatured(): ?bool {
  367. return $this->featured;
  368. }
  369. protected function setFeatured(bool $f): self {
  370. $this->featured = $f;
  371. return $this;
  372. }
  373. /**
  374. * @Assert\Callback
  375. */
  376. public function validate(ExecutionContextInterface $context, $payload) {
  377. $happens = $this->getHappensOn();
  378. $violation = false;
  379. foreach ($happens as $key => $value) {
  380. $duration = floatval($value['duration'] ?? 0.0);
  381. if ($duration < 0.25 || $duration > 24.0) {
  382. $context->buildViolation("Varighet må være angitt og mellom 0.25 og 24")->addViolation();
  383. $violation = true;
  384. }
  385. $date = new \DateTime($value['date'] ?? "2005-05-05 05:05:05");
  386. $fStart = new \DateTime('2020-06-25 00:00:01');
  387. $fEnd = new \DateTime('2020-08-09 23:59:00');
  388. if ($date < $fStart || $date > $fEnd) {
  389. $context->buildViolation("Eventet må skje mellom 25/6 - 09/8, år 2020.")->addViolation();
  390. $violation = true;
  391. }
  392. if ($violation)
  393. break;
  394. }
  395. }
  396. }