123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473 |
- <?php
- namespace App\Entity;
- use ApiPlatform\Core\Annotation\ApiProperty;
- use ApiPlatform\Core\Annotation\ApiResource;
- use Symfony\Component\Serializer\Annotation\Groups;
- use App\Serializer\ItemSerializedName;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\Validator\Context\ExecutionContextInterface;
- /**
- * @ApiResource(
- * itemOperations={"get"},
- * collectionOperations={"get" = {
- * "normalization_context" = {
- * "groups" = {"event:collection:read"},
- * },
- * }, "post" = {
- * "denormalization_context" = {
- * "groups" = {"event:collection:write"},
- * },
- * }}
- * )
- */
- class WebflowCollectionEvent extends AbstractWebflowCollectionItem {
- /**
- * @ApiProperty(identifier=true)
- * @Groups({
- * "event:collection:read",
- * })
- * @ItemSerializedName("_id")
- */
- protected $id;
- /**
- * @Groups({
- * "event:collection:read",
- * })
- * @ItemSerializedName("_cid")
- */
- protected static $cid = '5ebbafce7b593028a5f8f29a';
- /**
- * @Groups({
- * "event:collection:write",
- * })
- * @ItemSerializedName("@ignore")
- * @Assert\NotNull
- */
- private $captcha;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write"
- * })
- * @ItemSerializedName("name")
- * @Assert\NotNull
- */
- private $title;
- /*
- * @Groups({
- * "event:collection:read",
- * })
- */
- private $slug;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("kjop-billett-link")
- * @Assert\Url(
- * message = "Url '{{ value }}' er ugyldig. Husk begynne med http://"
- * )
- * @Assert\NotNull
- */
- private $bookingUrl;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("link-til-nettside")
- * @Assert\Url(
- * message = "Url '{{ value }}' er ugyldig. Husk begynne med http://"
- * )
- * @Assert\NotNull
- */
- private $websiteUrl;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("kapasitet-tekst")
- * @Assert\NotNull(
- * message= "Vennligst oppgi kapasitet"
- * )
- */
- private $capacity;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("sted-2")
- * @Assert\NotNull(
- * message= "Vennligst oppgi lokalisjon for eventet"
- * )
- */
- private $place;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("organisasjonsnr")
- * @Assert\Length(
- * min = 9,
- * max = 9,
- * allowEmptyString = false,
- * )
- * @Assert\NotNull
- */
- private $organizationNumber;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("arrangor")
- * @Assert\NotNull(
- * message= "Vennligst oppgi arrangør"
- * )
- */
- private $organizer;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("kontaktperson")
- * @Assert\NotNull(
- * message= "Vennligst angi kontaktperson"
- * )
- */
- private $contactPerson;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("e-post")
- * @Assert\Email(
- * message = "Epostadresse '{{ value }}' er ugyldig",
- * )
- * @Assert\NotNull
- */
- private $contactEmail;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("telefonnummer")
- * @Assert\NotNull(
- * message= "Vennligst angi en kontakt-telefon"
- * )
- */
- private $contactPhone;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @Assert\NotNull
- */
- private $description;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @Assert\Url(
- * message = "Url '{{ value }}' er ugyldig. Husk begynne med http://"
- * )
- * @Assert\NotNull
- */
- private $image;
- /**
- * @ItemSerializedName("bilde")
- */
- private $bilde;
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("opptrer")
- * @Assert\Count(
- * min = 1,
- * minMessage = "Eventet må opptre minst {{ limit }} ganger"
- * )
- * @Assert\NotNull
- */
- private $happensOn = [];
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("kategorier")
- * @Assert\Count(
- * min = 1,
- * minMessage = "Eventet må ha minst {{ limit }} kategori"
- * )
- * @Assert\NotNull
- */
- private $categories = [];
- /**
- * @Groups({
- * "event:collection:read",
- * "event:collection:write",
- * })
- * @ItemSerializedName("malgruppe-r")
- * @Assert\Count(
- * min = 1,
- * minMessage = "Eventet må ha minst {{ limit }} målgruppe"
- * )
- * @Assert\NotNull
- */
- private $audiences = [];
- private $featured = false;
- public static function cid(): string {
- return self::$cid;
- }
- public function setCaptcha(string $c): self {
- $this->captcha = $c;
- return $this;
- }
- public function getCaptcha(): ?string {
- return $this->captcha;
- }
-
- public function getTitle(): ?string {
- return $this->title;
- }
- public function setTitle(string $n): self {
- $this->title = $n;
- return $this;
- }
- public function getSlug(): ?string {
- return $this->slug;
- }
- protected function setSlug(string $s): self {
- $this->slug = $s;
- return $this;
- }
- public function getContactEmail(): ?string {
- return $this->contactEmail;
- }
- public function setContactEmail(string $e): self {
- $this->contactEmail = $e;
- return $this;
- }
- public function getContactPhone(): ?string {
- return $this->contactPhone;
- }
- public function setContactPhone(string $s): self {
- $this->contactPhone = $s;
- return $this;
- }
- public function getBookingUrl(): ?string {
- return $this->bookingUrl;
- }
- public function setBookingUrl($s): self {
- $this->bookingUrl = $s;
- return $this;
- }
- public function getWebsiteUrl(): ?string {
- return $this->websiteUrl;
- }
- public function setWebsiteUrl(string $s): self {
- $this->websiteUrl = $s;
- return $this;
- }
- public function getCapacity(): ?string {
- return $this->capacity;
- }
- public function setCapacity(string $i): self {
- $this->capacity= $i;
- return $this;
- }
- public function getPlace(): ?string {
- return $this->place;
- }
- public function setPlace(string $s): self {
- $this->place = $s;
- return $this;
- }
- public function getContactPerson(): ?string {
- return $this->contactPerson;
- }
- public function setContactPerson(string $s): self {
- $this->contactPerson = $s;
- return $this;
- }
- public function getOrganizationNumber(): ?string {
- return $this->organizationNumber;
- }
- public function setOrganizationNumber(string $s): self {
- $this->organizationNumber = $s;
- return $this;
- }
- public function getOrganizer(): ?string {
- return $this->organizer;
- }
- public function setOrganizer(string $s): self {
- $this->organizer = $s;
- return $this;
- }
- public function getDescription(): ?string {
- return $this->description;
- }
- public function setDescription(string $s): self {
- $this->description = sprintf('<p>%s</p>', preg_replace('/[\\n]+/', '</p><p>', strip_tags($s)));
- return $this;
- }
- public function getImage() {
- return $this->image;
- }
- public function setImage($a): self {
- $this->image = $a;
- if (is_string($this->image))
- $this->bilde;
- return $this;
- }
- public function getBilde() {
- return $this->image;
- }
- public function getCategories(): ?array {
- $this->categories = array_map(function ($category) {
- return $category;
- }, $this->categories);
- return $this->categories;
- }
- public function setCategories(array $a): self {
- return $this->setKategorier($a);
- }
- protected function setKategorier(array $a): self {
- $this->categories = $a;
- return $this;
- }
- public function getAudiences(): ?array {
- $this->audiences = array_map(function ($audience) {
- return $audience;
- }, $this->audiences);
- return $this->audiences;
- }
- public function setAudiences(array $a): self {
- $this->audiences = $a;
- return $this;
- }
- public function getHappensOn(): ?array {
- return $this->happensOn;
- }
- public function setHappensOn(array $a): self {
- $this->happensOn = $a;
- return $this;
- }
- public function getFeatured(): ?bool {
- return $this->featured;
- }
- protected function setFeatured(bool $f): self {
- $this->featured = $f;
- return $this;
- }
- /**
- * @Assert\Callback
- */
- public function validate(ExecutionContextInterface $context, $payload) {
-
- $happens = $this->getHappensOn();
- $violation = false;
- foreach ($happens as $key => $value) {
- $duration = floatval($value['duration'] ?? 0.0);
- if ($duration < 0.25 || $duration > 24.0) {
- $context->buildViolation("Varighet må være angitt og mellom 0.25 og 24")->addViolation();
- $violation = true;
- }
- $date = new \DateTime($value['date'] ?? "2005-05-05 05:05:05");
- $fStart = new \DateTime('2020-06-25 00:00:01');
- $fEnd = new \DateTime('2020-08-09 23:59:00');
- if ($date < $fStart || $date > $fEnd) {
- $context->buildViolation("Eventet må skje mellom 25/6 - 09/8, år 2020.")->addViolation();
- $violation = true;
- }
- if ($violation)
- break;
- }
- }
- }
|