From 00b3f6841d29c287f7a88613de648dad15ece7e7 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 9 Feb 2019 10:57:13 +0100 Subject: [PATCH 01/41] Composer: added ext-dom dependency --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index afd365a..4bd8f2e 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "minimum-stability": "stable", "require": { "php": ">=5.6", + "ext-dom": "*", "guzzlehttp/guzzle": "^6.3" }, "require-dev": { From 55d942da1849158a42b4cf315e41688d53d984df Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 9 Feb 2019 11:01:45 +0100 Subject: [PATCH 02/41] Change TRUE/FALSE/NULL to true/false/null, split DTOs into subdirectories, changed construct calls to static from() methods --- src/Client.php | 18 +- src/Request/EventParameters.php | 6 +- src/Request/OrganizationalUnitParameters.php | 2 +- src/Response/{ => Event}/Event.php | 227 +++++++++--------- src/Response/Event/Organizer.php | 151 ++++++++++++ .../OrganizerOrganizationalUnit.php | 16 +- src/Response/{ => Event}/Place.php | 34 ++- src/Response/{ => Event}/Program.php | 16 +- .../{ => Event}/RegistrationQuestion.php | 13 +- .../OrganizationalUnit.php | 56 ++--- src/Response/Organizer.php | 116 --------- 11 files changed, 367 insertions(+), 288 deletions(-) rename src/Response/{ => Event}/Event.php (55%) create mode 100644 src/Response/Event/Organizer.php rename src/Response/{ => Event}/OrganizerOrganizationalUnit.php (63%) rename src/Response/{ => Event}/Place.php (59%) rename src/Response/{ => Event}/Program.php (81%) rename src/Response/{ => Event}/RegistrationQuestion.php (52%) rename src/Response/{ => OrganizationalUnit}/OrganizationalUnit.php (75%) delete mode 100644 src/Response/Organizer.php diff --git a/src/Client.php b/src/Client.php index 7cc5c11..78cf29a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,8 +10,8 @@ use HnutiBrontosaurus\BisApiClient\Request\EventParameters; use HnutiBrontosaurus\BisApiClient\Request\OrganizationalUnitParameters; use HnutiBrontosaurus\BisApiClient\Request\Parameters; -use HnutiBrontosaurus\BisApiClient\Response\Event; -use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit; +use HnutiBrontosaurus\BisApiClient\Response\Event\Event; +use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit\OrganizationalUnit; use HnutiBrontosaurus\BisApiClient\Response\Response; @@ -64,9 +64,9 @@ public function __construct($url, $username, $password, HttpClient $httpClient) * @throws GuzzleException * @throws ResourceNotFoundException */ - public function getEvent($id, EventParameters $params = NULL) + public function getEvent($id, EventParameters $params = null) { - $params = ($params !== NULL ? $params : new EventParameters()); + $params = ($params !== null ? $params : new EventParameters()); $params->setId($id); $response = $this->processRequest($params); @@ -86,12 +86,12 @@ public function getEvent($id, EventParameters $params = NULL) * @throws GuzzleException * @throws ResourceNotFoundException */ - public function getEvents(EventParameters $params = NULL) + public function getEvents(EventParameters $params = null) { - $response = $this->processRequest($params !== NULL ? $params : new EventParameters()); + $response = $this->processRequest($params !== null ? $params : new EventParameters()); $data = $response->getData(); - if ($data === NULL) { + if ($data === null) { return []; } @@ -105,9 +105,9 @@ public function getEvents(EventParameters $params = NULL) * @throws GuzzleException * @throws ResourceNotFoundException */ - public function getOrganizationalUnits(OrganizationalUnitParameters $params = NULL) + public function getOrganizationalUnits(OrganizationalUnitParameters $params = null) { - $response = $this->processRequest($params !== NULL ? $params : new OrganizationalUnitParameters()); + $response = $this->processRequest($params !== null ? $params : new OrganizationalUnitParameters()); return \array_map(OrganizationalUnit::class . '::fromResponseData', $response->getData()); } diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index f03d707..8d8c83e 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -119,7 +119,7 @@ public function setType($type) self::TYPE_PUBLIC, self::TYPE_CLUB, self::TYPE_OHB, - ], TRUE)) { + ], true)) { throw new InvalidArgumentException('Value `' . $type . '` is not of valid types for `type` parameter.'); } @@ -153,7 +153,7 @@ public function setProgram($program) self::PROGRAM_EKOSTAN, self::PROGRAM_PSB, self::PROGRAM_EDUCATION, - ], TRUE)) { + ], true)) { throw new InvalidArgumentException('Value `' . $program . '` is not of valid types for `program` parameter.'); } @@ -184,7 +184,7 @@ public function setFor($for) self::FOR_ADULTS, self::FOR_CHILDREN, self::FOR_FAMILIES, - ], TRUE)) { + ], true)) { throw new InvalidArgumentException('Value `' . $for . '` is not of valid types for `for` parameter.'); } diff --git a/src/Request/OrganizationalUnitParameters.php b/src/Request/OrganizationalUnitParameters.php index bd544e1..f58f79c 100644 --- a/src/Request/OrganizationalUnitParameters.php +++ b/src/Request/OrganizationalUnitParameters.php @@ -32,7 +32,7 @@ public function setType($type) self::TYPE_CLUB, self::TYPE_BASE, self::TYPE_REGIONAL, - ], TRUE)) { + ], true)) { throw new InvalidArgumentException('Type `' . $type . '` is not of valid types.'); } diff --git a/src/Response/Event.php b/src/Response/Event/Event.php similarity index 55% rename from src/Response/Event.php rename to src/Response/Event/Event.php index 385fadf..de0115f 100644 --- a/src/Response/Event.php +++ b/src/Response/Event/Event.php @@ -1,6 +1,6 @@ id = $id; $this->name = $name; $this->dateFrom = $dateFrom; $this->dateUntil = $dateUntil; $this->type = $type; - $this->place = new Place($placeId, $placeName, $mapLinkOrCoords); + $this->place = Place::from($placeId, $placeName, $mapLinkOrCoords); $this->ageFrom = $ageFrom; $this->ageUntil = $ageUntil; $this->price = $price; @@ -172,8 +172,8 @@ public function __construct( // program - if ($programSlug !== NULL && $programName !== NULL) { - $this->program = new Program($programSlug, $programName); + if ($programSlug !== null && $programName !== null) { + $this->program = Program::from($programSlug, $programName); } @@ -182,20 +182,21 @@ public function __construct( $this->enableWebRegistration = $enableWebRegistration; $this->webRegistrationQuestions = \array_map(function ($webRegistrationQuestion) { // And then turn the rest into objects. - return new RegistrationQuestion($webRegistrationQuestion); + return RegistrationQuestion::from($webRegistrationQuestion); }, \array_filter([ // First exclude all null items. $webRegistrationQuestion1, $webRegistrationQuestion2, $webRegistrationQuestion3, ], function ($v, $k) { - return $v !== NULL; + return $v !== null; }, ARRAY_FILTER_USE_BOTH)); // organizers - $this->organizer = new Organizer( - ($organizationalUnitId !== NULL && $organizationalUnitName !== NULL) ? new OrganizerOrganizationalUnit($organizationalUnitId, $organizationalUnitName) : NULL, + $this->organizer = Organizer::from( + $organizationalUnitId, + $organizationalUnitName, $responsiblePerson, $organizers, $contactPersonName, @@ -207,10 +208,10 @@ public function __construct( // attachments - if ($attachment1 !== NULL) { + if ($attachment1 !== null) { $this->attachments[] = $attachment1; } - if ($attachment2 !== NULL) { + if ($attachment2 !== null) { $this->attachments[] = $attachment2; } } @@ -218,12 +219,12 @@ public function __construct( public static function fromResponseData(array $data) { - $price = NULL; + $price = null; if ($data['poplatek'] !== '') { $price = $data['poplatek']; if (\preg_match('|^[0-9]+$|', $price)) { - $price = (int)$price; + $price = (int) $price; } } @@ -233,36 +234,36 @@ public static function fromResponseData(array $data) \DateTimeImmutable::createFromFormat('Y-m-d', $data['od']), \DateTimeImmutable::createFromFormat('Y-m-d', $data['do']), $data['typ'], - $data['program_id'] !== '' ? $data['program_id'] : NULL, - $data['program'] !== '' ? $data['program'] : NULL, - $data['lokalita_id'] !== '' ? ((int)$data['lokalita_id']) : NULL, + $data['program_id'] !== '' ? $data['program_id'] : null, + $data['program'] !== '' ? $data['program'] : null, + $data['lokalita_id'] !== '' ? ((int) $data['lokalita_id']) : null, $data['lokalita'], - $data['add_info_title'] !== '' ? $data['add_info_title'] : NULL, - $data['add_info_title_2'] !== '' ? $data['add_info_title_2'] : NULL, - $data['add_info_title_3'] !== '' ? $data['add_info_title_3'] : NULL, - $data['vek_od'] !== '' ? ((int)$data['vek_od']) : NULL, - $data['vek_do'] !== '' ? ((int)$data['vek_do']) : NULL, + $data['add_info_title'] !== '' ? $data['add_info_title'] : null, + $data['add_info_title_2'] !== '' ? $data['add_info_title_2'] : null, + $data['add_info_title_3'] !== '' ? $data['add_info_title_3'] : null, + $data['vek_od'] !== '' ? ((int) $data['vek_od']) : null, + $data['vek_do'] !== '' ? ((int) $data['vek_do']) : null, $price, $data['prihlaska'] == 1, // intentionally == - $data['porada_id'] !== '' ? ((int)$data['porada_id']) : NULL, - $data['porada'] !== '' ? $data['porada'] : NULL, - $data['org'] !== '' ? $data['org'] : NULL, - $data['kontakt'] !== '' ? $data['kontakt'] : NULL, + $data['porada_id'] !== '' ? ((int)$data['porada_id']) : null, + $data['porada'] !== '' ? $data['porada'] : null, + $data['org'] !== '' ? $data['org'] : null, + $data['kontakt'] !== '' ? $data['kontakt'] : null, $data['kontakt_telefon'], $data['kontakt_email'], - $data['web'] !== '' ? $data['web'] : NULL, - $data['text'] !== '' ? $data['text'] : NULL, - $data['prace'] !== '' ? $data['prace'] : NULL, - $data['sraz'] !== '' ? $data['sraz'] : NULL, - $data['odpovedna'] !== '' ? $data['odpovedna'] : NULL, - $data['pracovni_doba'] !== '' ? ((int)$data['pracovni_doba']) : NULL, - $data['popis_programu'] !== '' ? $data['popis_programu'] : NULL, - $data['ubytovani'] !== '' ? $data['ubytovani'] : NULL, - $data['strava'] !== '' ? $data['strava'] : NULL, - $data['jak_se_prihlasit'] !== '' ? $data['jak_se_prihlasit'] : NULL, - $data['lokalita_mapa'] !== '' ? $data['lokalita_mapa'] : NULL, - $data['priloha_1'] !== '' ? $data['priloha_1'] : NULL, - $data['priloha_2'] !== '' ? $data['priloha_2'] : NULL + $data['web'] !== '' ? $data['web'] : null, + $data['text'] !== '' ? $data['text'] : null, + $data['prace'] !== '' ? $data['prace'] : null, + $data['sraz'] !== '' ? $data['sraz'] : null, + $data['odpovedna'] !== '' ? $data['odpovedna'] : null, + $data['pracovni_doba'] !== '' ? ((int) $data['pracovni_doba']) : null, + $data['popis_programu'] !== '' ? $data['popis_programu'] : null, + $data['ubytovani'] !== '' ? $data['ubytovani'] : null, + $data['strava'] !== '' ? $data['strava'] : null, + $data['jak_se_prihlasit'] !== '' ? $data['jak_se_prihlasit'] : null, + $data['lokalita_mapa'] !== '' ? $data['lokalita_mapa'] : null, + $data['priloha_1'] !== '' ? $data['priloha_1'] : null, + $data['priloha_2'] !== '' ? $data['priloha_2'] : null ); } @@ -308,7 +309,7 @@ public function getType() } /** - * @return Program|NULL + * @return Program|null */ public function getProgram() { @@ -340,7 +341,7 @@ public function getWebRegistrationQuestions() } /** - * @return int|NULL + * @return int|null */ public function getAgeFrom() { @@ -348,7 +349,7 @@ public function getAgeFrom() } /** - * @return int|NULL + * @return int|null */ public function getAgeUntil() { @@ -356,7 +357,7 @@ public function getAgeUntil() } /** - * @return int|string|NULL + * @return int|string|null */ public function getPrice() { @@ -372,7 +373,7 @@ public function getOrganizer() } /** - * @return string|NULL + * @return string|null */ public function getInvitationText() { @@ -380,7 +381,7 @@ public function getInvitationText() } /** - * @return string|NULL + * @return string|null */ public function getWorkDescription() { @@ -388,7 +389,7 @@ public function getWorkDescription() } /** - * @return string|NULL + * @return string|null */ public function getMeetingInformation() { @@ -396,7 +397,7 @@ public function getMeetingInformation() } /** - * @return int|NULL + * @return int|null */ public function getWorkingTime() { @@ -404,7 +405,7 @@ public function getWorkingTime() } /** - * @return string|NULL + * @return string|null */ public function getProgramDescription() { @@ -412,7 +413,7 @@ public function getProgramDescription() } /** - * @return string|NULL + * @return string|null */ public function getAccommodation() { @@ -420,7 +421,7 @@ public function getAccommodation() } /** - * @return string|NULL + * @return string|null */ public function getFood() { @@ -428,7 +429,7 @@ public function getFood() } /** - * @return string|NULL + * @return string|null */ public function getNotes() { diff --git a/src/Response/Event/Organizer.php b/src/Response/Event/Organizer.php new file mode 100644 index 0000000..2de71f3 --- /dev/null +++ b/src/Response/Event/Organizer.php @@ -0,0 +1,151 @@ +organizationalUnit = ($organizationalUnitId !== null && $organizationalUnitName !== null) ? OrganizerOrganizationalUnit::from($organizationalUnitId, $organizationalUnitName) : null; + $this->responsiblePerson = $responsiblePerson; + $this->organizers = $organizers; + $this->contactPersonName = $contactPersonName; + $this->contactPhone = $contactPhone; + $this->contactEmail = $contactEmail; + $this->contactWebsite = $contactWebsite; + } + + /** + * @param int|null $organizationalUnitId + * @param string|null $organizationalUnitName + * @param string|null $responsiblePerson + * @param string|null $organizers + * @param string|null $contactPersonName + * @param string $contactPhone + * @param string $contactEmail + * @param string|null $contactWebsite + * + * @return self + */ + public static function from( + $organizationalUnitId = null, + $organizationalUnitName = null, + $responsiblePerson = null, + $organizers = null, + $contactPersonName = null, + $contactPhone, + $contactEmail, + $contactWebsite = null + ) { + return new self( + $organizationalUnitId, + $organizationalUnitName, + $responsiblePerson, + $organizers, + $contactPersonName, + $contactPhone, + $contactEmail, + $contactWebsite + ); + } + + + /** + * @return OrganizerOrganizationalUnit|null + */ + public function getOrganizationalUnit() + { + return $this->organizationalUnit; + } + + /** + * @return string|null + */ + public function getResponsiblePerson() + { + return $this->responsiblePerson; + } + + /** + * @return string|null + */ + public function getOrganizers() + { + return $this->organizers; + } + + /** + * @return string|null + */ + public function getContactPersonName() + { + return $this->contactPersonName; + } + + /** + * @return string + */ + public function getContactPhone() + { + return $this->contactPhone; + } + + /** + * @return string + */ + public function getContactEmail() + { + return $this->contactEmail; + } + + /** + * @return string|null + */ + public function getContactWebsite() + { + return $this->contactWebsite; + } + +} diff --git a/src/Response/OrganizerOrganizationalUnit.php b/src/Response/Event/OrganizerOrganizationalUnit.php similarity index 63% rename from src/Response/OrganizerOrganizationalUnit.php rename to src/Response/Event/OrganizerOrganizationalUnit.php index ae6a3e2..e36ec14 100644 --- a/src/Response/OrganizerOrganizationalUnit.php +++ b/src/Response/Event/OrganizerOrganizationalUnit.php @@ -1,10 +1,10 @@ id = $id; $this->name = $name; } + /** + * @param int $id + * @param string $name + * @return self + */ + public static function from($id, $name) + { + return new self($id, $name); + } + /** * @return int diff --git a/src/Response/Place.php b/src/Response/Event/Place.php similarity index 59% rename from src/Response/Place.php rename to src/Response/Event/Place.php index 7b6dc1c..f632568 100644 --- a/src/Response/Place.php +++ b/src/Response/Event/Place.php @@ -1,30 +1,30 @@ id = $id; $this->name = $name; @@ -37,9 +37,23 @@ public function __construct($id = NULL, $name, $mapLinkOrCoords = NULL) } } + /** + * @param int|null $id + * @param string $name + * @param string|null $mapLinkOrCoords + * @return self + */ + public static function from( + $id = null, + $name, + $mapLinkOrCoords = null + ) { + return new self($id, $name, $mapLinkOrCoords); + } + /** - * @return int|NULL + * @return int|null */ public function getId() { @@ -55,7 +69,7 @@ public function getName() } /** - * @return string|NULL + * @return string|null */ public function getMapLink() { @@ -63,7 +77,7 @@ public function getMapLink() } /** - * @return string|NULL + * @return string|null */ public function getCoords() { diff --git a/src/Response/Program.php b/src/Response/Event/Program.php similarity index 81% rename from src/Response/Program.php rename to src/Response/Event/Program.php index c3f13e5..4269f21 100644 --- a/src/Response/Program.php +++ b/src/Response/Event/Program.php @@ -1,6 +1,6 @@ name = $name; } + /** + * @param string $slug + * @param string $name + * @return self + */ + public static function from($slug, $name) + { + return new self($slug, $name); + } + /** * @return string diff --git a/src/Response/RegistrationQuestion.php b/src/Response/Event/RegistrationQuestion.php similarity index 52% rename from src/Response/RegistrationQuestion.php rename to src/Response/Event/RegistrationQuestion.php index eb2e3d9..a737b62 100644 --- a/src/Response/RegistrationQuestion.php +++ b/src/Response/Event/RegistrationQuestion.php @@ -1,6 +1,6 @@ question = $question; } + /** + * @param string $question + * @return self + */ + public static function from($question) + { + return new self($question); + } + /** * @return string diff --git a/src/Response/OrganizationalUnit.php b/src/Response/OrganizationalUnit/OrganizationalUnit.php similarity index 75% rename from src/Response/OrganizationalUnit.php rename to src/Response/OrganizationalUnit/OrganizationalUnit.php index 04f1fdf..160c0da 100644 --- a/src/Response/OrganizationalUnit.php +++ b/src/Response/OrganizationalUnit/OrganizationalUnit.php @@ -1,6 +1,6 @@ id = $id; $this->name = $name; @@ -90,7 +90,7 @@ public function __construct( self::TYPE_BASE, self::TYPE_REGIONAL, self::TYPE_OFFICE, - ], TRUE)) { + ], true)) { throw new InvalidArgumentException('Type `' . $type . '` is not of valid types.'); } $this->type = $type; @@ -105,12 +105,12 @@ public static function fromResponseData(array $data) $data['ulice'], $data['mesto'], $data['psc'], - $data['telefon'] !== '' ? $data['telefon'] : NULL, - $data['email'] !== '' ? $data['email'] : NULL, - $data['www'] !== '' ? $data['www'] : NULL, + $data['telefon'] !== '' ? $data['telefon'] : null, + $data['email'] !== '' ? $data['email'] : null, + $data['www'] !== '' ? $data['www'] : null, (int) $data['uroven'], - $data['predseda'] !== '' ? $data['predseda'] : NULL, - $data['hospodar'] !== '' ? $data['hospodar'] : NULL + $data['predseda'] !== '' ? $data['predseda'] : null, + $data['hospodar'] !== '' ? $data['hospodar'] : null ); } @@ -156,7 +156,7 @@ public function getPostCode() } /** - * @return string|NULL + * @return string|null */ public function getPhone() { @@ -164,7 +164,7 @@ public function getPhone() } /** - * @return string|NULL + * @return string|null */ public function getEmail() { @@ -172,7 +172,7 @@ public function getEmail() } /** - * @return string|NULL + * @return string|null */ public function getWebsite() { @@ -188,7 +188,7 @@ public function getType() } /** - * @return string|NULL + * @return string|null */ public function getChairman() { @@ -196,7 +196,7 @@ public function getChairman() } /** - * @return string|NULL + * @return string|null */ public function getManager() { diff --git a/src/Response/Organizer.php b/src/Response/Organizer.php deleted file mode 100644 index 51480e5..0000000 --- a/src/Response/Organizer.php +++ /dev/null @@ -1,116 +0,0 @@ -organizationalUnit = $organizationalUnit; - $this->responsiblePerson = $responsiblePerson; - $this->organizers = $organizers; - $this->contactPersonName = $contactPersonName; - $this->contactPhone = $contactPhone; - $this->contactEmail = $contactEmail; - $this->contactWebsite = $contactWebsite; - } - - - /** - * @return OrganizerOrganizationalUnit|NULL - */ - public function getOrganizationalUnit() - { - return $this->organizationalUnit; - } - - /** - * @return string|NULL - */ - public function getResponsiblePerson() - { - return $this->responsiblePerson; - } - - /** - * @return string|NULL - */ - public function getOrganizers() - { - return $this->organizers; - } - - /** - * @return string|NULL - */ - public function getContactPersonName() - { - return $this->contactPersonName; - } - - /** - * @return string - */ - public function getContactPhone() - { - return $this->contactPhone; - } - - /** - * @return string - */ - public function getContactEmail() - { - return $this->contactEmail; - } - - /** - * @return string|NULL - */ - public function getContactWebsite() - { - return $this->contactWebsite; - } - -} From 36e40f3277928dfc4f6ae4df435605c8ae25238b Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 9 Feb 2019 11:25:16 +0100 Subject: [PATCH 03/41] Response\Event: implemented new API features such as multiple invitation text or more photos; renamed imagePath to coverImagePath, made optional --- src/Response/Event/Event.php | 130 +++++++++++------- src/Response/Event/Invitation/Invitation.php | 110 +++++++++++++++ src/Response/Event/Invitation/Photo.php | 40 ++++++ .../Event/Invitation/Presentation.php | 87 ++++++++++++ 4 files changed, 315 insertions(+), 52 deletions(-) create mode 100644 src/Response/Event/Invitation/Invitation.php create mode 100644 src/Response/Event/Invitation/Photo.php create mode 100644 src/Response/Event/Invitation/Presentation.php diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index de0115f..88aeb6d 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -2,6 +2,8 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event; +use HnutiBrontosaurus\BisApiClient\Response\Event\Invitation\Invitation; + final class Event { @@ -12,6 +14,9 @@ final class Event /** @var string */ private $name; + /** @var string|null */ + private $coverPhotoPath; + /** @var \DateTimeImmutable */ private $dateFrom; @@ -48,11 +53,8 @@ final class Event /** @var Organizer */ private $organizer; - /** @var string|null */ - private $invitationText; - - /** @var string|null */ - private $workDescription; + /** @var Invitation|null */ + private $invitation; /** @var string|null */ private $meetingInformation; @@ -72,12 +74,8 @@ final class Event /** @var string|null */ private $notes; - /** @var array */ - private $attachments = []; - /** - * Event constructor. * @param int $id * @param string $name * @param \DateTimeImmutable $dateFrom @@ -101,8 +99,10 @@ final class Event * @param string $contactPhone * @param string $contactEmail * @param string|null $contactWebsite - * @param string|null $invitationText - * @param string|null $workDescription + * @param string|null $invitationOrganizationalInformation + * @param string|null $invitationIntroduction + * @param string|null $invitationPresentationText + * @param string|null $invitationWorkDescription * @param string|null $meetingInformation * @param string|null $responsiblePerson * @param int|null $workingTime @@ -111,10 +111,8 @@ final class Event * @param string|null $food * @param string|null $notes * @param string|null $mapLinkOrCoords - * @param string|null $attachment1 - * @param string|null $attachment2 */ - public function __construct( + private function __construct( $id, $name, \DateTimeImmutable $dateFrom, @@ -138,8 +136,11 @@ public function __construct( $contactPhone, $contactEmail, $contactWebsite = null, - $invitationText = null, - $workDescription = null, + $invitationOrganizationalInformation = null, + $invitationIntroduction = null, + $invitationPresentationText = null, + array $invitationPresentationPhotos = [], + $invitationWorkDescription = null, $meetingInformation = null, $responsiblePerson = null, $workingTime = null, @@ -147,9 +148,7 @@ public function __construct( $accommodation = null, $food = null, $notes = null, - $mapLinkOrCoords = null, - $attachment1 = null, - $attachment2 = null + $mapLinkOrCoords = null ) { $this->id = $id; $this->name = $name; @@ -160,8 +159,6 @@ public function __construct( $this->ageFrom = $ageFrom; $this->ageUntil = $ageUntil; $this->price = $price; - $this->invitationText = $invitationText; - $this->workDescription = $workDescription; $this->meetingInformation = $meetingInformation; $this->workingTime = $workingTime; $this->programDescription = $programDescription; @@ -170,6 +167,13 @@ public function __construct( $this->notes = $notes; + // cover photo + + if (\count($invitationPresentationPhotos) > 0) { + $this->coverPhotoPath = \reset($invitationPresentationPhotos); + } + + // program if ($programSlug !== null && $programName !== null) { @@ -206,14 +210,15 @@ public function __construct( ); - // attachments + // invitation - if ($attachment1 !== null) { - $this->attachments[] = $attachment1; - } - if ($attachment2 !== null) { - $this->attachments[] = $attachment2; - } + $this->invitation = Invitation::from( + $invitationIntroduction, + $invitationOrganizationalInformation, + $invitationWorkDescription, + $invitationPresentationText, + $invitationPresentationPhotos + ); } @@ -228,6 +233,26 @@ public static function fromResponseData(array $data) } } + $invitationPresentationPhotos = []; + if ($data['priloha_1'] !== '') { + $invitationPresentationPhotos[] = $data['priloha_1']; + } + if ($data['priloha_2'] !== '') { + $invitationPresentationPhotos[] = $data['priloha_2']; + } + if ($data['priloha_4'] !== '') { + $invitationPresentationPhotos[] = $data['priloha_3']; + } + if ($data['priloha_4'] !== '') { + $invitationPresentationPhotos[] = $data['priloha_4']; + } + if ($data['priloha_5'] !== '') { + $invitationPresentationPhotos[] = $data['priloha_5']; + } + if ($data['priloha_6'] !== '') { + $invitationPresentationPhotos[] = $data['priloha_6']; + } + return new self( (int)$data['id'], $data['nazev'], @@ -252,8 +277,11 @@ public static function fromResponseData(array $data) $data['kontakt_telefon'], $data['kontakt_email'], $data['web'] !== '' ? $data['web'] : null, - $data['text'] !== '' ? $data['text'] : null, - $data['prace'] !== '' ? $data['prace'] : null, + $data['text_info'] !== '' ? $data['text_info'] : null, + $data['text_uvod'] !== '' ? $data['text_uvod'] : null, + $data['text_mnam'] !== '' ? $data['text_mnam'] : null, + $invitationPresentationPhotos, + $data['text_prace'] !== '' ? $data['text_prace'] : null, $data['sraz'] !== '' ? $data['sraz'] : null, $data['odpovedna'] !== '' ? $data['odpovedna'] : null, $data['pracovni_doba'] !== '' ? ((int) $data['pracovni_doba']) : null, @@ -261,9 +289,7 @@ public static function fromResponseData(array $data) $data['ubytovani'] !== '' ? $data['ubytovani'] : null, $data['strava'] !== '' ? $data['strava'] : null, $data['jak_se_prihlasit'] !== '' ? $data['jak_se_prihlasit'] : null, - $data['lokalita_mapa'] !== '' ? $data['lokalita_mapa'] : null, - $data['priloha_1'] !== '' ? $data['priloha_1'] : null, - $data['priloha_2'] !== '' ? $data['priloha_2'] : null + $data['lokalita_mapa'] !== '' ? $data['lokalita_mapa'] : null ); } @@ -276,6 +302,22 @@ public function getId() return $this->id; } + /** + * @return string|null + */ + public function getCoverPhotoPath() + { + return $this->coverPhotoPath; + } + + /** + * @return bool + */ + public function hasCoverPhoto() + { + return $this->coverPhotoPath !== null; + } + /** * @return string */ @@ -373,19 +415,11 @@ public function getOrganizer() } /** - * @return string|null - */ - public function getInvitationText() - { - return $this->invitationText; - } - - /** - * @return string|null + * @return Invitation|null */ - public function getWorkDescription() + public function getInvitation() { - return $this->workDescription; + return $this->invitation; } /** @@ -436,12 +470,4 @@ public function getNotes() return $this->notes; } - /** - * @return array - */ - public function getAttachments() - { - return $this->attachments; - } - } diff --git a/src/Response/Event/Invitation/Invitation.php b/src/Response/Event/Invitation/Invitation.php new file mode 100644 index 0000000..7dcab09 --- /dev/null +++ b/src/Response/Event/Invitation/Invitation.php @@ -0,0 +1,110 @@ +introduction = $introduction; + $this->organizationalInformation = $organizationalInformation; + $this->workDescription = $workDescription; + + if ($presentationText !== null) { + $this->hasPresentation = true; + $this->presentation = Presentation::from($presentationText); + + if (\count($presentationPhotos) > 0) { + $this->presentation->addPhotos($presentationPhotos); + } + } + } + + /** + * @param string $introduction + * @param string $organizationalInformation + * @param string $workDescription + * @param string|null $presentationText + * @param string[] $presentationPhotos + * @return self + */ + public static function from( + $introduction, + $organizationalInformation, + $workDescription, + $presentationText = null, + array $presentationPhotos = [] + ) { + return new self( + $introduction, + $organizationalInformation, + $workDescription, + $presentationText, + $presentationPhotos + ); + } + + + /** + * @return string + */ + public function getIntroduction() + { + return $this->introduction; + } + + /** + * @return string + */ + public function getOrganizationalInformation() + { + return $this->organizationalInformation; + } + + /** + * @return string + */ + public function getWorkDescription() + { + return $this->workDescription; + } + + /** + * @return Presentation|null + */ + public function getPresentation() + { + return $this->presentation; + } + +} diff --git a/src/Response/Event/Invitation/Photo.php b/src/Response/Event/Invitation/Photo.php new file mode 100644 index 0000000..ca9b745 --- /dev/null +++ b/src/Response/Event/Invitation/Photo.php @@ -0,0 +1,40 @@ +path = $path; + } + + + /** + * @param $path + * @return self + */ + public static function from($path) + { + return new self($path); + } + + + /** + * @return string + */ + public function getPath() + { + return $this->path; + } + +} diff --git a/src/Response/Event/Invitation/Presentation.php b/src/Response/Event/Invitation/Presentation.php new file mode 100644 index 0000000..ee5645a --- /dev/null +++ b/src/Response/Event/Invitation/Presentation.php @@ -0,0 +1,87 @@ +text = $text; + } + + + /** + * @param $text + * @return self + */ + public static function from($text) + { + return new self($text); + } + + /** + * @param string $photoPath + * @return self + */ + public function addPhoto($photoPath) + { + $this->hasAnyPhotos = true; + $this->photos[] = Photo::from($photoPath); + + return $this; + } + + /** + * @param string[] $photoPaths + * @return self + */ + public function addPhotos(array $photoPaths) + { + foreach ($photoPaths as $photoPath) { + $this->addPhoto($photoPath); + } + + return $this; + } + + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @return bool + */ + public function hasAnyPhotos() + { + return $this->hasAnyPhotos; + } + + /** + * @return Photo[] + */ + public function getPhotos() + { + return $this->photos; + } + +} From abd5d15be2ec2c30e2f70a182520da659e0ea5c1 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 9 Feb 2019 11:42:26 +0100 Subject: [PATCH 04/41] Response\Event: improved price typing --- src/Response/Event/Event.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 88aeb6d..6ce3038 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -45,8 +45,8 @@ final class Event private $ageUntil; /** - * Single number, interval or null. - * @var int|string|null + * Single number or interval. + * @var int|string */ private $price; @@ -90,7 +90,7 @@ final class Event * @param string|null $webRegistrationQuestion3 * @param int|null $ageFrom * @param int|null $ageUntil - * @param int|string|null $price + * @param int|string $price * @param bool $enableWebRegistration * @param int|null $organizationalUnitId * @param string|null $organizationalUnitName @@ -222,9 +222,13 @@ private function __construct( } + /** + * @param string[] $data Everything is string as it comes from HTTP response body. + * @return self + */ public static function fromResponseData(array $data) { - $price = null; + $price = 0; if ($data['poplatek'] !== '') { $price = $data['poplatek']; @@ -399,13 +403,18 @@ public function getAgeUntil() } /** - * @return int|string|null + * @return int|string */ public function getPrice() { return $this->price; } + public function isPaid() + { + return $this->price !== 0; + } + /** * @return Organizer */ From c9bb5179da64e1fb7ebf838ebac8c16ef2d71062 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Wed, 13 Feb 2019 10:36:37 +0100 Subject: [PATCH 05/41] Response\Event: added check method to Organizer DTO --- src/Response/Event/Organizer.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Response/Event/Organizer.php b/src/Response/Event/Organizer.php index 2de71f3..8d530de 100644 --- a/src/Response/Event/Organizer.php +++ b/src/Response/Event/Organizer.php @@ -108,6 +108,14 @@ public function getResponsiblePerson() return $this->responsiblePerson; } + /** + * @return bool + */ + public function areOrganizersListed() + { + return $this->organizers !== null; + } + /** * @return string|null */ From d86f8d3ecaba468340df1d136d24bd8bf01ec648 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Wed, 13 Feb 2019 11:26:47 +0100 Subject: [PATCH 06/41] Response\Event: implemented multiple registration types --- src/Response/Event/Event.php | 43 ++-- .../RegistrationQuestion.php | 12 +- .../Event/Registration/RegistrationType.php | 193 ++++++++++++++++++ src/exceptions.php | 11 + 4 files changed, 231 insertions(+), 28 deletions(-) rename src/Response/Event/{ => Registration}/RegistrationQuestion.php (67%) create mode 100644 src/Response/Event/Registration/RegistrationType.php diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 6ce3038..5d7bbbe 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -3,6 +3,7 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event; use HnutiBrontosaurus\BisApiClient\Response\Event\Invitation\Invitation; +use HnutiBrontosaurus\BisApiClient\Response\Event\Registration\RegistrationType; final class Event @@ -32,11 +33,8 @@ final class Event /** @var Place */ private $place; - /** @var bool */ - private $enableWebRegistration = false; - - /** @var RegistrationQuestion[]|array */ - private $webRegistrationQuestions = []; + /** @var RegistrationType */ + private $registrationType; /** @var int|null */ private $ageFrom; @@ -85,13 +83,14 @@ final class Event * @param string|null $programName * @param int|null $placeId * @param string $placeName + * @param int $registrationType * @param string|null $webRegistrationQuestion1 * @param string|null $webRegistrationQuestion2 * @param string|null $webRegistrationQuestion3 + * @param string|null $registrationCustomUrl * @param int|null $ageFrom * @param int|null $ageUntil * @param int|string $price - * @param bool $enableWebRegistration * @param int|null $organizationalUnitId * @param string|null $organizationalUnitName * @param string|null $organizers @@ -102,6 +101,7 @@ final class Event * @param string|null $invitationOrganizationalInformation * @param string|null $invitationIntroduction * @param string|null $invitationPresentationText + * @param array $invitationPresentationPhotos * @param string|null $invitationWorkDescription * @param string|null $meetingInformation * @param string|null $responsiblePerson @@ -122,13 +122,14 @@ private function __construct( $programName = null, $placeId = null, $placeName, + $registrationType, $webRegistrationQuestion1 = null, $webRegistrationQuestion2 = null, $webRegistrationQuestion3 = null, + $registrationCustomUrl = null, $ageFrom = null, $ageUntil = null, $price = null, - $enableWebRegistration, $organizationalUnitId = null, $organizationalUnitName = null, $organizers = null, @@ -181,19 +182,16 @@ private function __construct( } - // web registration - - $this->enableWebRegistration = $enableWebRegistration; + // registration - $this->webRegistrationQuestions = \array_map(function ($webRegistrationQuestion) { // And then turn the rest into objects. - return RegistrationQuestion::from($webRegistrationQuestion); - }, \array_filter([ // First exclude all null items. + $registrationQuestions = \array_filter([ // exclude all null items $webRegistrationQuestion1, $webRegistrationQuestion2, $webRegistrationQuestion3, ], function ($v, $k) { return $v !== null; - }, ARRAY_FILTER_USE_BOTH)); + }, ARRAY_FILTER_USE_BOTH); + $this->registrationType = RegistrationType::from($registrationType, $registrationQuestions, $contactEmail, $registrationCustomUrl); // organizers @@ -267,13 +265,14 @@ public static function fromResponseData(array $data) $data['program'] !== '' ? $data['program'] : null, $data['lokalita_id'] !== '' ? ((int) $data['lokalita_id']) : null, $data['lokalita'], + (int) $data['prihlasovani_id'], $data['add_info_title'] !== '' ? $data['add_info_title'] : null, $data['add_info_title_2'] !== '' ? $data['add_info_title_2'] : null, $data['add_info_title_3'] !== '' ? $data['add_info_title_3'] : null, + $data['kontakt_url'] !== '' ? $data['kontakt_url'] : null, $data['vek_od'] !== '' ? ((int) $data['vek_od']) : null, $data['vek_do'] !== '' ? ((int) $data['vek_do']) : null, $price, - $data['prihlaska'] == 1, // intentionally == $data['porada_id'] !== '' ? ((int)$data['porada_id']) : null, $data['porada'] !== '' ? $data['porada'] : null, $data['org'] !== '' ? $data['org'] : null, @@ -371,19 +370,11 @@ public function getPlace() } /** - * @return bool - */ - public function isEnableWebRegistration() - { - return $this->enableWebRegistration; - } - - /** - * @return RegistrationQuestion[]|array + * @return RegistrationType */ - public function getWebRegistrationQuestions() + public function getRegistrationType() { - return $this->webRegistrationQuestions; + return $this->registrationType; } /** diff --git a/src/Response/Event/RegistrationQuestion.php b/src/Response/Event/Registration/RegistrationQuestion.php similarity index 67% rename from src/Response/Event/RegistrationQuestion.php rename to src/Response/Event/Registration/RegistrationQuestion.php index a737b62..4125336 100644 --- a/src/Response/Event/RegistrationQuestion.php +++ b/src/Response/Event/Registration/RegistrationQuestion.php @@ -1,6 +1,6 @@ __toString(); + } + + /** + * @return string + */ + public function __toString() { return $this->question; } diff --git a/src/Response/Event/Registration/RegistrationType.php b/src/Response/Event/Registration/RegistrationType.php new file mode 100644 index 0000000..8e3f541 --- /dev/null +++ b/src/Response/Event/Registration/RegistrationType.php @@ -0,0 +1,193 @@ +type = $type; + + if ($type === self::TYPE_VIA_BRONTOWEB && $questions !== null && \count($questions) > 0) { + $this->questions = \array_map(function ($question) { + return RegistrationQuestion::from($question); + }, $questions); + } + + if ($type === self::TYPE_VIA_EMAIL) { + if ($email === null) { + $this->hasValidData = false; + } + + $this->email = $email; + } + + if ($type === self::TYPE_VIA_CUSTOM_WEBPAGE) { + if ($url === null) { + $this->hasValidData = false; + } + + $this->url = $url; + } + } + + /** + * @param int $type + * @param array|null $questions + * @param string|null $email + * @param string|null $url + * @return self + */ + public static function from($type, array $questions = null, $email = null, $url = null) + { + return new self($type, $questions, $email, $url); + } + + + /** + * @return bool + */ + public function isOfTypeNone() + { + return $this->type === self::TYPE_NONE; + } + + + // registration via Brontoweb + + /** + * @return bool + */ + public function isOfTypeBrontoWeb() + { + return $this->type === self::TYPE_VIA_BRONTOWEB; + } + + /** + * @return bool + */ + public function areAnyQuestions() + { + return \count($this->questions) > 0; + } + + /** + * @return RegistrationQuestion[] + */ + public function getQuestions() + { + return $this->questions; + } + + + // registration via e-mail + + /** + * @return bool + */ + public function isOfTypeEmail() + { + return $this->type === self::TYPE_VIA_EMAIL; + } + + /** + * @return string|null + */ + public function getEmail() + { + if ( ! $this->hasValidData()) { + throw RegistrationTypeException::missingAdditionalData('email', $this->type); + } + + if ( ! $this->isOfTypeEmail()) { + throw new BisClientException('This method can not be called when the registration is not of `via e-mail` type.'); + } + + return $this->email; + } + + + // registration custom webpage + + /** + * @return bool + */ + public function isOfTypeCustomWebpage() + { + return $this->type === self::TYPE_VIA_CUSTOM_WEBPAGE; + } + + /** + * @return string|null + */ + public function getUrl() + { + if ( ! $this->hasValidData()) { + throw RegistrationTypeException::missingAdditionalData('url', $this->type); + } + + if ( ! $this->isOfTypeCustomWebpage()) { + throw new BisClientException('This method can not be called when the registration is not of `via custom webpage` type.'); + } + + return $this->url; + } + + + // registration disabled + + public function isOfTypeDisabled() + { + return $this->type === self::TYPE_DISABLED; + } + + + public function hasValidData() + { + return $this->hasValidData; + } + +} diff --git a/src/exceptions.php b/src/exceptions.php index 7ed4155..7a858bc 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -11,3 +11,14 @@ class ResourceNotFoundException extends \RuntimeException class BisClientException extends \RuntimeException {} + +final class RegistrationTypeException extends BisClientException +{ + + public static function missingAdditionalData($key, $type) + { + return new self(\sprintf('Missing additional data `%s` for selected type %d.', $key, $type)); + } + +} + From bc5c747b323c997fce803df0468d8dfb673b3641 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 14 Feb 2019 10:41:21 +0100 Subject: [PATCH 07/41] Response\Event: implemented target group --- src/Response/Event/Event.php | 20 ++++++ src/Response/Event/TargetGroup.php | 108 +++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 src/Response/Event/TargetGroup.php diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 5d7bbbe..1965ce7 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -2,6 +2,7 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event; +use HnutiBrontosaurus\BisApiClient\BisClientException; use HnutiBrontosaurus\BisApiClient\Response\Event\Invitation\Invitation; use HnutiBrontosaurus\BisApiClient\Response\Event\Registration\RegistrationType; @@ -51,6 +52,9 @@ final class Event /** @var Organizer */ private $organizer; + /** @var TargetGroup */ + private $targetGroup; + /** @var Invitation|null */ private $invitation; @@ -98,6 +102,7 @@ final class Event * @param string $contactPhone * @param string $contactEmail * @param string|null $contactWebsite + * @param int|null $targetGroupId * @param string|null $invitationOrganizationalInformation * @param string|null $invitationIntroduction * @param string|null $invitationPresentationText @@ -137,6 +142,7 @@ private function __construct( $contactPhone, $contactEmail, $contactWebsite = null, + $targetGroupId = null, $invitationOrganizationalInformation = null, $invitationIntroduction = null, $invitationPresentationText = null, @@ -208,6 +214,10 @@ private function __construct( ); + // target group + $this->targetGroup = $targetGroupId !== null ? TargetGroup::from($targetGroupId) : TargetGroup::unknown(); + + // invitation $this->invitation = Invitation::from( @@ -223,6 +233,7 @@ private function __construct( /** * @param string[] $data Everything is string as it comes from HTTP response body. * @return self + * @throws BisClientException */ public static function fromResponseData(array $data) { @@ -280,6 +291,7 @@ public static function fromResponseData(array $data) $data['kontakt_telefon'], $data['kontakt_email'], $data['web'] !== '' ? $data['web'] : null, + $data['prokoho_id'] !== '' ? ((int) $data['prokoho_id']) : null, $data['text_info'] !== '' ? $data['text_info'] : null, $data['text_uvod'] !== '' ? $data['text_uvod'] : null, $data['text_mnam'] !== '' ? $data['text_mnam'] : null, @@ -414,6 +426,14 @@ public function getOrganizer() return $this->organizer; } + /** + * @return TargetGroup + */ + public function getTargetGroup() + { + return $this->targetGroup; + } + /** * @return Invitation|null */ diff --git a/src/Response/Event/TargetGroup.php b/src/Response/Event/TargetGroup.php new file mode 100644 index 0000000..0840906 --- /dev/null +++ b/src/Response/Event/TargetGroup.php @@ -0,0 +1,108 @@ +id = $id; + } + + /** + * @param int $id + * @return self + */ + public static function from($id) + { + return new self($id); + } + + /** + * @return self + */ + public static function unknown() + { + return new self(self::UNKNOWN); + } + + + /** + * @return bool + */ + public function isOfUnknownType() + { + return $this->id === self::UNKNOWN; + } + + /** + * @return bool + */ + public function isOfTypeEveryone() + { + return $this->id === self::EVERYONE; + } + + /** + * @return bool + */ + public function isOfTypeAdults() + { + return $this->id === self::ADULTS; + } + + /** + * @return bool + */ + public function isOfTypeChildren() + { + return $this->id === self::CHILDREN; + } + + /** + * @return bool + */ + public function isOfTypeFamilies() + { + return $this->id === self::FAMILIES; + } + + /** + * @return bool + */ + public function isOfTypeFirstTimeAttendees() + { + return $this->id === self::FIRST_TIME_ATTENDEES; + } + +} From 3eee2937b94815acdedfe617613f8aa7d15e7d92 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 14 Feb 2019 16:04:43 +0100 Subject: [PATCH 08/41] Implemented Request\EventAttendee to being able to save application forms --- src/Client.php | 70 +++++++++++++++++++++++++++++++++- src/Request/EventAttendee.php | 71 +++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 src/Request/EventAttendee.php diff --git a/src/Client.php b/src/Client.php index 78cf29a..223e39f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,12 +7,14 @@ use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\Request; +use HnutiBrontosaurus\BisApiClient\Request\EventAttendee; use HnutiBrontosaurus\BisApiClient\Request\EventParameters; use HnutiBrontosaurus\BisApiClient\Request\OrganizationalUnitParameters; use HnutiBrontosaurus\BisApiClient\Request\Parameters; use HnutiBrontosaurus\BisApiClient\Response\Event\Event; use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit\OrganizationalUnit; use HnutiBrontosaurus\BisApiClient\Response\Response; +use Psr\Http\Message\ResponseInterface; final class Client @@ -56,6 +58,8 @@ public function __construct($url, $username, $password, HttpClient $httpClient) } + // events + /** * @param int $id * @param EventParameters $params @@ -98,6 +102,24 @@ public function getEvents(EventParameters $params = null) return \array_map(Event::class . '::fromResponseData', $data); } + /** + * @param EventAttendee $eventAttendee + * @throws BisClientException + */ + public function addAttendeeToEvent(EventAttendee $eventAttendee) + { + $eventAttendee->setCredentials($this->username, $this->password); + $response = $this->httpClient->post($this->buildUrl($eventAttendee), $this->convertArrayToFormData($eventAttendee->getData())); + + $this->checkForResponseContentType($response); + + $domDocument = $this->generateDOM($response); + $this->checkForResponseErrors($domDocument); + } + + + // organizational units + /** * @param OrganizationalUnitParameters $params * @return OrganizationalUnit[] @@ -135,10 +157,33 @@ private function processRequest(Parameters $requestParameters) throw new BisClientException('Unable to process request: transfer error.', 0, $e); } + $this->checkForResponseContentType($response); + + $domDocument = $this->generateDOM($response); + $this->checkForResponseErrors($domDocument); + + return new Response($response, $domDocument); + } + + + /** + * @param ResponseInterface $response + * @throws BisClientException + */ + private function checkForResponseContentType(ResponseInterface $response) + { if (\strncmp($response->getHeaderLine('Content-Type'), 'text/xml', \strlen('text/xml')) !== 0) { throw new BisClientException('Unable to process response: the response Content-Type is invalid or missing.'); } + } + /** + * @param ResponseInterface $response + * @return \DOMDocument + * @throws BisClientException + */ + private function generateDOM(ResponseInterface $response) + { try { $domDocument = new \DOMDocument(); $domDocument->loadXML($response->getBody()); @@ -147,9 +192,21 @@ private function processRequest(Parameters $requestParameters) throw new BisClientException('Unable to process response: response body contains invalid XML.', 0, $e); } + return $domDocument; + } + + /** + * @param \DOMDocument $domDocument + * @throws BisClientException + */ + private function checkForResponseErrors(\DOMDocument $domDocument) + { $resultNode = $domDocument->getElementsByTagName(Response::TAG_RESULT)->item(0); if ($resultNode->hasAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR)) { switch ($resultNode->getAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR)) { + case 'success': // In case of POST request with form data, BIS returns `` for some reason... Let's pretend that there is no error in such case because... you know... there is no error! + break; + case 'forbidden': throw new BisClientException('You are not authorized to make such request with given credentials. Or you have simply wrong credentials. :-)'); break; @@ -163,8 +220,6 @@ private function processRequest(Parameters $requestParameters) break; } } - - return new Response($response, $domDocument); } /** @@ -177,4 +232,15 @@ private function buildUrl(Parameters $params) return $this->url . ($queryString !== '' ? '?' . $queryString : ''); } + /** + * @param array $array + * @return array + */ + private function convertArrayToFormData(array $array) + { + return [ + 'form_params' => $array, + ]; + } + } diff --git a/src/Request/EventAttendee.php b/src/Request/EventAttendee.php new file mode 100644 index 0000000..a0b15c6 --- /dev/null +++ b/src/Request/EventAttendee.php @@ -0,0 +1,71 @@ + 'prihlaska', + ]); + + + // the rest goes to data array which will be sent in headers, not through URI + + $this->data = [ + 'akce' => $eventId, + 'jmeno' => $firstName, + 'prijmeni' => $lastName, + 'telefon' => $phoneNumber, + 'email' => $emailAddress, + 'datum_narozeni' => $birthDate, + 'poznamka' => $note, + ]; + + + if (\count($questionAnswers) === 0) { + return; + } + + // currently 3 questions are supported + $i = 1; + foreach ($questionAnswers as $questionAnswer) { + $this->data['add_info' . ($i >= 2 ? '_' . $i : '')] = $questionAnswer; // key syntax is `add_info` for first key and `add_info_X` for any other + $i++; + } + } + + + /** + * @return array + */ + public function getData() + { + return $this->data; + } + +} From 79bc73e31fb54e0d9ab68d550d4b0b7d8758a15d Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 15 Feb 2019 07:16:48 +0100 Subject: [PATCH 09/41] Client: added ResponseErrorException --- src/Client.php | 14 ++++++++++---- src/exceptions.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 223e39f..a76d9f0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -104,6 +104,7 @@ public function getEvents(EventParameters $params = null) /** * @param EventAttendee $eventAttendee + * @throws ResponseErrorException * @throws BisClientException */ public function addAttendeeToEvent(EventAttendee $eventAttendee) @@ -137,6 +138,7 @@ public function getOrganizationalUnits(OrganizationalUnitParameters $params = nu /** * @param Parameters $requestParameters * @return Response + * @throws ResponseErrorException * @throws BisClientException * @throws GuzzleException * @throws ResourceNotFoundException @@ -197,7 +199,7 @@ private function generateDOM(ResponseInterface $response) /** * @param \DOMDocument $domDocument - * @throws BisClientException + * @throws ResponseErrorException */ private function checkForResponseErrors(\DOMDocument $domDocument) { @@ -207,16 +209,20 @@ private function checkForResponseErrors(\DOMDocument $domDocument) case 'success': // In case of POST request with form data, BIS returns `` for some reason... Let's pretend that there is no error in such case because... you know... there is no error! break; + case 'user': + throw ResponseErrorException::invalidUserInput($resultNode); + break; + case 'forbidden': - throw new BisClientException('You are not authorized to make such request with given credentials. Or you have simply wrong credentials. :-)'); + throw ResponseErrorException::unauthorizedAccess(); break; case 'params': - throw new BisClientException('Parameters are invalid.'); + throw ResponseErrorException::invalidParameters(); break; default: - throw new BisClientException('Unknown error. Error type returned from BIS: `' . $resultNode->getAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR) . '`'); + throw ResponseErrorException::unknown($resultNode->getAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR)); break; } } diff --git a/src/exceptions.php b/src/exceptions.php index 7a858bc..7d52cab 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -22,3 +22,41 @@ public static function missingAdditionalData($key, $type) } +final class ResponseErrorException extends BisClientException +{ + + /** + * @return self + */ + public static function invalidParameters() + { + return new self('Parameters are invalid.'); + } + + /** + * @param \DOMElement $element + * @return self + */ + public static function invalidUserInput(\DOMElement $element) + { + return new self('User input is invalid. Details: ' . $element->nodeValue); + } + + /** + * @return self + */ + public static function unauthorizedAccess() + { + return new self('You are not authorized to make such request with given credentials. Or you have simply wrong credentials. :-)'); + } + + /** + * @param string $unknownErrorTypeKey + * @return self + */ + public static function unknown($unknownErrorTypeKey) + { + return new self('Unknown error. Error type returned from BIS: `' . $unknownErrorTypeKey); + } + +} From e21654373c7b655335b67c8df7e3601aa786de8f Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 15 Feb 2019 11:32:36 +0100 Subject: [PATCH 10/41] Client: moved ResponseErrorException to Response directory and split to single exceptions per each state --- composer.json | 5 +++- src/Client.php | 13 ++++++---- src/Response/exceptions.php | 48 +++++++++++++++++++++++++++++++++++++ src/exceptions.php | 39 ------------------------------ 4 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 src/Response/exceptions.php diff --git a/composer.json b/composer.json index 4bd8f2e..a6a8f31 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,10 @@ "psr-4": { "HnutiBrontosaurus\\BisApiClient\\": "src/" }, - "classmap": ["src/exceptions.php"] + "classmap": [ + "src/Response/exceptions.php", + "src/exceptions.php" + ] }, "config": { "sort-packages": true diff --git a/src/Client.php b/src/Client.php index a76d9f0..d53de28 100644 --- a/src/Client.php +++ b/src/Client.php @@ -12,8 +12,13 @@ use HnutiBrontosaurus\BisApiClient\Request\OrganizationalUnitParameters; use HnutiBrontosaurus\BisApiClient\Request\Parameters; use HnutiBrontosaurus\BisApiClient\Response\Event\Event; +use HnutiBrontosaurus\BisApiClient\Response\InvalidParametersException; +use HnutiBrontosaurus\BisApiClient\Response\InvalidUserInputException; use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit\OrganizationalUnit; use HnutiBrontosaurus\BisApiClient\Response\Response; +use HnutiBrontosaurus\BisApiClient\Response\ResponseErrorException; +use HnutiBrontosaurus\BisApiClient\Response\UnauthorizedAccessException; +use HnutiBrontosaurus\BisApiClient\Response\UnknownErrorException; use Psr\Http\Message\ResponseInterface; @@ -210,19 +215,19 @@ private function checkForResponseErrors(\DOMDocument $domDocument) break; case 'user': - throw ResponseErrorException::invalidUserInput($resultNode); + throw new InvalidUserInputException($resultNode); break; case 'forbidden': - throw ResponseErrorException::unauthorizedAccess(); + throw new UnauthorizedAccessException(); break; case 'params': - throw ResponseErrorException::invalidParameters(); + throw new InvalidParametersException(); break; default: - throw ResponseErrorException::unknown($resultNode->getAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR)); + throw new UnknownErrorException($resultNode->getAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR)); break; } } diff --git a/src/Response/exceptions.php b/src/Response/exceptions.php new file mode 100644 index 0000000..a899147 --- /dev/null +++ b/src/Response/exceptions.php @@ -0,0 +1,48 @@ +nodeValue); + } + +} + +final class UnauthorizedAccessException extends ResponseErrorException +{ + + public function __construct() + { + parent::__construct('You are not authorized to make such request with given credentials. Or you have simply wrong credentials. :-)'); + } + +} + +final class UnknownErrorException extends ResponseErrorException +{ + + /** + * @param string $unknownErrorTypeKey + */ + public function __construct($unknownErrorTypeKey) + { + parent::__construct('Unknown error. Error type returned from BIS: ' . $unknownErrorTypeKey); + } + +} diff --git a/src/exceptions.php b/src/exceptions.php index 7d52cab..fd9c36a 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -21,42 +21,3 @@ public static function missingAdditionalData($key, $type) } } - -final class ResponseErrorException extends BisClientException -{ - - /** - * @return self - */ - public static function invalidParameters() - { - return new self('Parameters are invalid.'); - } - - /** - * @param \DOMElement $element - * @return self - */ - public static function invalidUserInput(\DOMElement $element) - { - return new self('User input is invalid. Details: ' . $element->nodeValue); - } - - /** - * @return self - */ - public static function unauthorizedAccess() - { - return new self('You are not authorized to make such request with given credentials. Or you have simply wrong credentials. :-)'); - } - - /** - * @param string $unknownErrorTypeKey - * @return self - */ - public static function unknown($unknownErrorTypeKey) - { - return new self('Unknown error. Error type returned from BIS: `' . $unknownErrorTypeKey); - } - -} From 272994e3509b92dc0eb50c05657c9eb13690d5c8 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 15 Feb 2019 15:49:41 +0100 Subject: [PATCH 11/41] Response\Event: updated Place object --- src/Response/Event/Event.php | 20 ++++++------ src/Response/Event/Place.php | 62 +++++++++++++++--------------------- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 1965ce7..413cf76 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -85,8 +85,9 @@ final class Event * @param string $type * @param string|null $programSlug * @param string|null $programName - * @param int|null $placeId * @param string $placeName + * @param string|null $placeAlternativeName + * @param string|null $placeCoordinates * @param int $registrationType * @param string|null $webRegistrationQuestion1 * @param string|null $webRegistrationQuestion2 @@ -115,7 +116,6 @@ final class Event * @param string|null $accommodation * @param string|null $food * @param string|null $notes - * @param string|null $mapLinkOrCoords */ private function __construct( $id, @@ -125,8 +125,9 @@ private function __construct( $type, $programSlug = null, $programName = null, - $placeId = null, $placeName, + $placeAlternativeName = null, + $placeCoordinates = null, $registrationType, $webRegistrationQuestion1 = null, $webRegistrationQuestion2 = null, @@ -154,15 +155,14 @@ private function __construct( $programDescription = null, $accommodation = null, $food = null, - $notes = null, - $mapLinkOrCoords = null + $notes = null ) { $this->id = $id; $this->name = $name; $this->dateFrom = $dateFrom; $this->dateUntil = $dateUntil; $this->type = $type; - $this->place = Place::from($placeId, $placeName, $mapLinkOrCoords); + $this->place = Place::from($placeName, $placeAlternativeName, $placeCoordinates); $this->ageFrom = $ageFrom; $this->ageUntil = $ageUntil; $this->price = $price; @@ -274,8 +274,9 @@ public static function fromResponseData(array $data) $data['typ'], $data['program_id'] !== '' ? $data['program_id'] : null, $data['program'] !== '' ? $data['program'] : null, - $data['lokalita_id'] !== '' ? ((int) $data['lokalita_id']) : null, - $data['lokalita'], + $data['lokalita_nazev'], + $data['lokalita_misto'] !== '' ? $data['lokalita_misto'] : null, + $data['lokalita_gps'] !== '' ? $data['lokalita_gps'] : null, (int) $data['prihlasovani_id'], $data['add_info_title'] !== '' ? $data['add_info_title'] : null, $data['add_info_title_2'] !== '' ? $data['add_info_title_2'] : null, @@ -303,8 +304,7 @@ public static function fromResponseData(array $data) $data['popis_programu'] !== '' ? $data['popis_programu'] : null, $data['ubytovani'] !== '' ? $data['ubytovani'] : null, $data['strava'] !== '' ? $data['strava'] : null, - $data['jak_se_prihlasit'] !== '' ? $data['jak_se_prihlasit'] : null, - $data['lokalita_mapa'] !== '' ? $data['lokalita_mapa'] : null + $data['jak_se_prihlasit'] !== '' ? $data['jak_se_prihlasit'] : null ); } diff --git a/src/Response/Event/Place.php b/src/Response/Event/Place.php index f632568..efa4682 100644 --- a/src/Response/Event/Place.php +++ b/src/Response/Event/Place.php @@ -6,60 +6,48 @@ final class Place { - /** @var int|null */ - private $id; - /** @var string */ private $name; - /** @var string|null */ - private $mapLink; - - /** @var string|null */ - private $coords; + /** + * In format `49.132456 16.123456`. + * @var string|null + */ + private $coordinates; /** - * @param int|null $id * @param string $name - * @param string|null $mapLinkOrCoords Map hypertext link or coordinates depending on what user has filled in BIS. + * @param string|null $alternativeName + * @param string|null $coordinates */ - private function __construct($id = null, $name, $mapLinkOrCoords = null) - { - $this->id = $id; - $this->name = $name; + private function __construct( + $name, + $alternativeName = null, + $coordinates = null + ) { + $this->name = $alternativeName !== null ? $alternativeName : $name; // It looks like alternative names are more concrete. - if (\strncmp($mapLinkOrCoords, 'http', \strlen('http')) === 0) { // Copied from `Nette\Utils\Strings::startsWith()`. - $this->mapLink = $mapLinkOrCoords; - } - elseif (\preg_match('|[0-9]+(\.[0-9]+)N, [0-9]+(\.[0-9]+)E|', $mapLinkOrCoords)) { // Only `49.132456N, 16.123456E` format is used by users right now. - $this->coords = $mapLinkOrCoords; + if ($coordinates !== null && \preg_match('|[0-9]+(\.[0-9]+) [0-9]+(\.[0-9]+)|', $coordinates)) { // Only `49.132456 16.123456` format is used by users right now. + $this->coordinates = $coordinates; } } /** - * @param int|null $id * @param string $name - * @param string|null $mapLinkOrCoords + * @param string|null $alternativeName + * @param string|null $coordinates * @return self */ public static function from( - $id = null, $name, - $mapLinkOrCoords = null + $alternativeName = null, + $coordinates = null ) { - return new self($id, $name, $mapLinkOrCoords); + return new self($name, $alternativeName, $coordinates); } - /** - * @return int|null - */ - public function getId() - { - return $this->id; - } - /** * @return string */ @@ -69,19 +57,19 @@ public function getName() } /** - * @return string|null + * @return bool */ - public function getMapLink() + public function areCoordinatesListed() { - return $this->mapLink; + return $this->coordinates !== null; } /** * @return string|null */ - public function getCoords() + public function getCoordinates() { - return $this->coords; + return $this->coordinates; } } From c54666f6ab284c217118d0bc1b60116c1f2c4ab2 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 15 Feb 2019 17:05:21 +0100 Subject: [PATCH 12/41] Response\OrganizationalUnit: updated to ignore unknown unit types --- composer.json | 3 ++- src/Client.php | 15 ++++++++++++++- .../OrganizationalUnit/OrganizationalUnit.php | 2 +- src/Response/OrganizationalUnit/exceptions.php | 7 +++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/Response/OrganizationalUnit/exceptions.php diff --git a/composer.json b/composer.json index a6a8f31..24ae02e 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,9 @@ "HnutiBrontosaurus\\BisApiClient\\": "src/" }, "classmap": [ + "src/exceptions.php", "src/Response/exceptions.php", - "src/exceptions.php" + "src/Response/OrganizationalUnit/exceptions.php" ] }, "config": { diff --git a/src/Client.php b/src/Client.php index d53de28..a4e46a8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -15,6 +15,7 @@ use HnutiBrontosaurus\BisApiClient\Response\InvalidParametersException; use HnutiBrontosaurus\BisApiClient\Response\InvalidUserInputException; use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit\OrganizationalUnit; +use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit\UnknownOrganizationUnitTypeException; use HnutiBrontosaurus\BisApiClient\Response\Response; use HnutiBrontosaurus\BisApiClient\Response\ResponseErrorException; use HnutiBrontosaurus\BisApiClient\Response\UnauthorizedAccessException; @@ -136,7 +137,19 @@ public function addAttendeeToEvent(EventAttendee $eventAttendee) public function getOrganizationalUnits(OrganizationalUnitParameters $params = null) { $response = $this->processRequest($params !== null ? $params : new OrganizationalUnitParameters()); - return \array_map(OrganizationalUnit::class . '::fromResponseData', $response->getData()); + + $organizationalUnits = []; + foreach ($response->getData() as $organizationalUnit) { + try { + $organizationalUnits[] = OrganizationalUnit::fromResponseData($organizationalUnit); + + } catch (UnknownOrganizationUnitTypeException $e) { + continue; // In case of unknown type - just ignore it. + + } + } + + return $organizationalUnits; } diff --git a/src/Response/OrganizationalUnit/OrganizationalUnit.php b/src/Response/OrganizationalUnit/OrganizationalUnit.php index 160c0da..1a07adf 100644 --- a/src/Response/OrganizationalUnit/OrganizationalUnit.php +++ b/src/Response/OrganizationalUnit/OrganizationalUnit.php @@ -91,7 +91,7 @@ private function __construct( self::TYPE_REGIONAL, self::TYPE_OFFICE, ], true)) { - throw new InvalidArgumentException('Type `' . $type . '` is not of valid types.'); + throw new UnknownOrganizationUnitTypeException('Type `' . $type . '` is not of valid types.'); } $this->type = $type; } diff --git a/src/Response/OrganizationalUnit/exceptions.php b/src/Response/OrganizationalUnit/exceptions.php new file mode 100644 index 0000000..ba73fa9 --- /dev/null +++ b/src/Response/OrganizationalUnit/exceptions.php @@ -0,0 +1,7 @@ + Date: Mon, 18 Feb 2019 16:40:28 +0100 Subject: [PATCH 13/41] Request\EventParameters: added first time attendees to for filter --- src/Request/EventParameters.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index 8d8c83e..06065f9 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -32,6 +32,7 @@ final class EventParameters extends Parameters const FOR_ADULTS = 'dospeli'; const FOR_CHILDREN = 'deti'; const FOR_FAMILIES = 'detirodice'; + const FOR_FIRST_TIME_ATTENDEES = 'prvouc'; const PARAM_DATE_FORMAT = 'Y-m-d'; @@ -184,6 +185,7 @@ public function setFor($for) self::FOR_ADULTS, self::FOR_CHILDREN, self::FOR_FAMILIES, + self::FOR_FIRST_TIME_ATTENDEES, ], true)) { throw new InvalidArgumentException('Value `' . $for . '` is not of valid types for `for` parameter.'); } From 5aa0a93f801d200275c03848a6f0922a4f0abe15 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Tue, 19 Feb 2019 06:27:01 +0100 Subject: [PATCH 14/41] Request\EventParameters: added meeting to types --- src/Request/EventParameters.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index 06065f9..cf8a8ab 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -21,6 +21,7 @@ final class EventParameters extends Parameters const TYPE_PUBLIC = 'verejnost'; const TYPE_CLUB = 'klub'; const TYPE_OHB = 'ohb'; + const TYPE_MEETING = 'schuzka'; const PROGRAM_NATURE = 'ap'; const PROGRAM_SIGHTS = 'pamatky'; @@ -120,6 +121,7 @@ public function setType($type) self::TYPE_PUBLIC, self::TYPE_CLUB, self::TYPE_OHB, + self::TYPE_MEETING, ], true)) { throw new InvalidArgumentException('Value `' . $type . '` is not of valid types for `type` parameter.'); } From 42f1c3e5b98c995d16e01d62f130e32cb0bb119f Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 22 Feb 2019 11:23:26 +0100 Subject: [PATCH 15/41] Implemented Request\Adoption to being able to save request for adoption --- src/Client.php | 22 +++++++++++++ src/Request/Adoption.php | 69 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/Request/Adoption.php diff --git a/src/Client.php b/src/Client.php index a4e46a8..f8769d5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,6 +7,7 @@ use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\Request; +use HnutiBrontosaurus\BisApiClient\Request\Adoption; use HnutiBrontosaurus\BisApiClient\Request\EventAttendee; use HnutiBrontosaurus\BisApiClient\Request\EventParameters; use HnutiBrontosaurus\BisApiClient\Request\OrganizationalUnitParameters; @@ -121,6 +122,7 @@ public function addAttendeeToEvent(EventAttendee $eventAttendee) $this->checkForResponseContentType($response); $domDocument = $this->generateDOM($response); + $this->checkForResponseErrors($domDocument); } @@ -153,6 +155,26 @@ public function getOrganizationalUnits(OrganizationalUnitParameters $params = nu } + // adoption + + /** + * @param Adoption $adoption + * @throws ResponseErrorException + * @throws BisClientException + */ + public function saveRequestForAdoption(Adoption $adoption) + { + $adoption->setCredentials($this->username, $this->password); + $response = $this->httpClient->post($this->buildUrl($adoption), $this->convertArrayToFormData($adoption->getData())); + + $this->checkForResponseContentType($response); + + $domDocument = $this->generateDOM($response); + + $this->checkForResponseErrors($domDocument); + } + + /** * @param Parameters $requestParameters * @return Response diff --git a/src/Request/Adoption.php b/src/Request/Adoption.php new file mode 100644 index 0000000..e789b3e --- /dev/null +++ b/src/Request/Adoption.php @@ -0,0 +1,69 @@ + 'adopce', + ]); + + + // the rest goes to data array which will be sent in headers, not through URI + + $this->data = [ + 'f_jmeno' => $firstName, + 'f_prijmeni' => $lastName, + 'f_ulice' => $streetAddress . ' ' . $streetNumber, + 'f_mesto' => $city, + 'f_psc' => $postalCode, + 'f_email' => $emailAddress, + 'f_pohlavi' => null, // not required, but accepted by BIS (values muz/zena) + 'f_uvest_v_seznamu' => $excludeFromPublic ? 'off' : 'on', + 'f_clanek' => $preferredUnitOfTypeBase, + 'f_rc' => $preferredUnitOfTypeRegional, + 'f_castka' => $amount, + ]; + } + + + /** + * @return array + */ + public function getData() + { + return $this->data; + } + +} From 416c4c3858b6cfa8ed17edf606e0cea6b2282de3 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 22 Feb 2019 18:17:47 +0100 Subject: [PATCH 16/41] Response\Event: added isOfTypeHoliday into program --- src/Response/Event/Program.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Response/Event/Program.php b/src/Response/Event/Program.php index 4269f21..1bf65a1 100644 --- a/src/Response/Event/Program.php +++ b/src/Response/Event/Program.php @@ -88,4 +88,12 @@ public function isOfTypeSights() return $this->slug === self::PROGRAM_SIGHTS; } + /** + * @return bool + */ + public function isOfTypeHoliday() + { + return $this->slug === self::PROGRAM_PSB; + } + } From d2f52dc4df740465bdc34e4d0e6dd6cbc3b67061 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 23 Feb 2019 09:13:02 +0100 Subject: [PATCH 17/41] Request\Event: renamed setFor() to setTargetGroup() and moved stuff along the file to keep relevant thigns together --- src/Request/EventParameters.php | 142 ++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 62 deletions(-) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index cf8a8ab..f2e06ad 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -8,35 +8,6 @@ final class EventParameters extends Parameters { - const FILTER_CLUB = 1; - const FILTER_WEEKEND = 2; - const FILTER_CAMP = 4; - const FILTER_EKOSTAN = 8; - - const TYPE_WORK = 'pracovni'; - const TYPE_EXPERIENCE = 'prozitkova'; - const TYPE_SPORT = 'sportovni'; - const TYPE_EDUCATIONAL = 'vzdelavaci'; - const TYPE_COURSE = 'prednaska'; - const TYPE_PUBLIC = 'verejnost'; - const TYPE_CLUB = 'klub'; - const TYPE_OHB = 'ohb'; - const TYPE_MEETING = 'schuzka'; - - const PROGRAM_NATURE = 'ap'; - const PROGRAM_SIGHTS = 'pamatky'; - const PROGRAM_BRDO = 'brdo'; - const PROGRAM_EKOSTAN = 'ekostan'; - const PROGRAM_PSB = 'psb'; - const PROGRAM_EDUCATION = 'vzdelavani'; - - const FOR_ADULTS = 'dospeli'; - const FOR_CHILDREN = 'deti'; - const FOR_FAMILIES = 'detirodice'; - const FOR_FIRST_TIME_ATTENDEES = 'prvouc'; - - const PARAM_DATE_FORMAT = 'Y-m-d'; - const PARAM_DISPLAY_ALREADY_STARTED_KEY = 'aktualni'; const PARAM_DISPLAY_ALREADY_STARTED_NO = 'od'; const PARAM_DISPLAY_ALREADY_STARTED_YES = 'do'; @@ -66,6 +37,14 @@ public function setId($id) return $this; } + + // filter + + const FILTER_CLUB = 1; + const FILTER_WEEKEND = 2; + const FILTER_CAMP = 4; + const FILTER_EKOSTAN = 8; + /** * Beside standard constant usage as a paramer, you can pass bitwise operation argument, e.g. `EventParameters::FILTER_WEEKEND|EventParameters::FILTER_CAMP`. * @param int $filter @@ -106,13 +85,26 @@ public function setFilter($filter) return $this; } + + // type + + const TYPE_WORK = 'pracovni'; + const TYPE_EXPERIENCE = 'prozitkova'; + const TYPE_SPORT = 'sportovni'; + const TYPE_EDUCATIONAL = 'vzdelavaci'; + const TYPE_COURSE = 'prednaska'; + const TYPE_PUBLIC = 'verejnost'; + const TYPE_CLUB = 'klub'; + const TYPE_OHB = 'ohb'; + const TYPE_MEETING = 'schuzka'; + /** * @param string $type * @return self */ public function setType($type) { - if (!\in_array($type, [ + if ( ! \in_array($type, [ self::TYPE_WORK, self::TYPE_EXPERIENCE, self::TYPE_SPORT, @@ -143,13 +135,23 @@ public function setTypes(array $types) return $this; } + + // program + + const PROGRAM_NATURE = 'ap'; + const PROGRAM_SIGHTS = 'pamatky'; + const PROGRAM_BRDO = 'brdo'; + const PROGRAM_EKOSTAN = 'ekostan'; + const PROGRAM_PSB = 'psb'; + const PROGRAM_EDUCATION = 'vzdelavani'; + /** * @param string $program * @return self */ public function setProgram($program) { - if (!\in_array($program, [ + if ( ! \in_array($program, [ self::PROGRAM_NATURE, self::PROGRAM_SIGHTS, self::PROGRAM_BRDO, @@ -177,49 +179,37 @@ public function setPrograms(array $programs) return $this; } + + // target group + + const TARGET_GROUP_ADULTS = 'dospeli'; + const TARGET_GROUP_CHILDREN = 'deti'; + const TARGET_GROUP_FAMILIES = 'detirodice'; + const TARGET_GROUP_FIRST_TIME_ATTENDEES = 'prvouc'; + /** - * @param string $for + * @param string $targetGroup * @return self */ - public function setFor($for) + public function setTargetGroup($targetGroup) { - if (!\in_array($for, [ - self::FOR_ADULTS, - self::FOR_CHILDREN, - self::FOR_FAMILIES, - self::FOR_FIRST_TIME_ATTENDEES, + if ( ! \in_array($targetGroup, [ + self::TARGET_GROUP_ADULTS, + self::TARGET_GROUP_CHILDREN, + self::TARGET_GROUP_FAMILIES, + self::TARGET_GROUP_FIRST_TIME_ATTENDEES, ], true)) { - throw new InvalidArgumentException('Value `' . $for . '` is not of valid types for `for` parameter.'); + throw new InvalidArgumentException('Value `' . $targetGroup . '` is not of valid types for `for` parameter.'); } - $this->params['pro'] = $for; + $this->params['pro'] = $targetGroup; return $this; } - /** - * @param int|int[] $unitIds - * @return self - */ - public function setOrganizedBy($unitIds) - { - $organizedByKey = 'zc'; - - // If just single value, wrap it into an array. - if (!\is_array($unitIds)) { - $unitIds = [$unitIds]; - } - foreach ($unitIds as $unitId) { - // If such value is not present yet, initialize it with an empty array. - if (!\is_array($this->params[$organizedByKey])) { - $this->params[$organizedByKey] = []; - } + // date constraints - $this->params[$organizedByKey][] = (int) $unitId; - } - - return $this; - } + const PARAM_DATE_FORMAT = 'Y-m-d'; /** * @param \DateTimeImmutable $dateFrom @@ -260,6 +250,9 @@ public function hideTheseAlreadyStarted() return $this; } + + // miscellaneous + /** * @return self */ @@ -269,6 +262,31 @@ public function orderByStartDate() return $this; } + /** + * @param int|int[] $unitIds + * @return self + */ + public function setOrganizedBy($unitIds) + { + $organizedByKey = 'zc'; + + // If just single value, wrap it into an array. + if ( ! \is_array($unitIds)) { + $unitIds = [$unitIds]; + } + + foreach ($unitIds as $unitId) { + // If such value is not present yet, initialize it with an empty array. + if ( ! \is_array($this->params[$organizedByKey])) { + $this->params[$organizedByKey] = []; + } + + $this->params[$organizedByKey][] = (int) $unitId; + } + + return $this; + } + /** * @return self */ From 0928a92e75ca27bcc837f6373b8c0d93d9efa5e2 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 23 Feb 2019 09:13:59 +0100 Subject: [PATCH 18/41] Request\Event: added "not selected" parameter to program and target group --- src/Request/EventParameters.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index f2e06ad..424f347 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -138,6 +138,7 @@ public function setTypes(array $types) // program + const PROGRAM_NOT_SELECTED = 0; const PROGRAM_NATURE = 'ap'; const PROGRAM_SIGHTS = 'pamatky'; const PROGRAM_BRDO = 'brdo'; @@ -152,6 +153,7 @@ public function setTypes(array $types) public function setProgram($program) { if ( ! \in_array($program, [ + self::PROGRAM_NOT_SELECTED, self::PROGRAM_NATURE, self::PROGRAM_SIGHTS, self::PROGRAM_BRDO, @@ -182,6 +184,7 @@ public function setPrograms(array $programs) // target group + const TARGET_GROUP_NOT_SELECTED = 0; const TARGET_GROUP_ADULTS = 'dospeli'; const TARGET_GROUP_CHILDREN = 'deti'; const TARGET_GROUP_FAMILIES = 'detirodice'; @@ -194,6 +197,7 @@ public function setPrograms(array $programs) public function setTargetGroup($targetGroup) { if ( ! \in_array($targetGroup, [ + self::TARGET_GROUP_NOT_SELECTED, self::TARGET_GROUP_ADULTS, self::TARGET_GROUP_CHILDREN, self::TARGET_GROUP_FAMILIES, From 7b26d9ee117d41a4991f9b78f4682d92f065bfa5 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 23 Feb 2019 09:15:53 +0100 Subject: [PATCH 19/41] Request\Event: allowed multiple values for target groups --- src/Request/EventParameters.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index 424f347..980f5cb 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -206,7 +206,20 @@ public function setTargetGroup($targetGroup) throw new InvalidArgumentException('Value `' . $targetGroup . '` is not of valid types for `for` parameter.'); } - $this->params['pro'] = $targetGroup; + $this->params['pro'][] = $targetGroup; + return $this; + } + + /** + * @param string[] $targetGroups + * @return self + */ + public function setTargetGroups(array $targetGroups) + { + foreach ($targetGroups as $targetGroup) { + $this->setTargetGroup($targetGroup); + } + return $this; } From 1784c55bff1b46795a251fd9c335a6c72b5636b2 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sat, 23 Feb 2019 09:36:00 +0100 Subject: [PATCH 20/41] Request\Event: added missing type, program and target group options, deprecated filter parameter --- src/Request/EventParameters.php | 60 +++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index 980f5cb..cd4239b 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -46,9 +46,10 @@ public function setId($id) const FILTER_EKOSTAN = 8; /** - * Beside standard constant usage as a paramer, you can pass bitwise operation argument, e.g. `EventParameters::FILTER_WEEKEND|EventParameters::FILTER_CAMP`. + * Beside standard constant usage as a parameter, you can pass bitwise operation argument, e.g. `EventParameters::FILTER_WEEKEND|EventParameters::FILTER_CAMP`. * @param int $filter * @return self + * @deprecated This is blackbox parameter as nobody really knows from outside what this parameter really does. It is recommended to use combination of other parameters instead. */ public function setFilter($filter) { @@ -88,15 +89,24 @@ public function setFilter($filter) // type - const TYPE_WORK = 'pracovni'; - const TYPE_EXPERIENCE = 'prozitkova'; + const TYPE_VOLUNTARY = 'pracovni'; // dobrovolnická + const TYPE_EXPERIENCE = 'prozitkova'; // zážitková const TYPE_SPORT = 'sportovni'; - const TYPE_EDUCATIONAL = 'vzdelavaci'; - const TYPE_COURSE = 'prednaska'; - const TYPE_PUBLIC = 'verejnost'; - const TYPE_CLUB = 'klub'; - const TYPE_OHB = 'ohb'; - const TYPE_MEETING = 'schuzka'; + + const TYPE_EDUCATIONAL_TALK = 'prednaska'; // vzdělávací - přednášky + const TYPE_EDUCATIONAL_COURSES = 'vzdelavaci'; // vzdělávací - kurzy, školení + const TYPE_EDUCATIONAL_OHB = 'ohb'; // vzdělávací - kurz ohb + const TYPE_LEARNING_PROGRAM = 'vyuka'; // výukový program + const TYPE_RESIDENTIAL_LEARNING_PROGRAM = 'pobyt'; // pobytový výukový program + + const TYPE_CLUB_MEETUP = 'klub'; // klub - setkání + const TYPE_CLUB_TALK = 'klub-vzdel'; // klub - přednáška + const TYPE_FOR_PUBLIC = 'verejnost'; // akce pro veřejnost + const TYPE_EKOSTAN = 'ekostan'; + const TYPE_EXHIBITION = 'vystava'; + const TYPE_ACTION_GROUP = 'akcni'; // akční skupina + const TYPE_INTERNAL = 'jina'; // interní akce (VH a jiné) + const TYPE_GROUP_MEETING = 'schuzka'; // oddílová, družinová schůzka /** * @param string $type @@ -105,15 +115,24 @@ public function setFilter($filter) public function setType($type) { if ( ! \in_array($type, [ - self::TYPE_WORK, + self::TYPE_VOLUNTARY, self::TYPE_EXPERIENCE, self::TYPE_SPORT, - self::TYPE_EDUCATIONAL, - self::TYPE_COURSE, - self::TYPE_PUBLIC, - self::TYPE_CLUB, - self::TYPE_OHB, - self::TYPE_MEETING, + + self::TYPE_EDUCATIONAL_TALK, + self::TYPE_EDUCATIONAL_COURSES, + self::TYPE_EDUCATIONAL_OHB, + self::TYPE_LEARNING_PROGRAM, + self::TYPE_RESIDENTIAL_LEARNING_PROGRAM, + + self::TYPE_CLUB_MEETUP, + self::TYPE_CLUB_TALK, + self::TYPE_FOR_PUBLIC, + self::TYPE_EKOSTAN, + self::TYPE_EXHIBITION, + self::TYPE_ACTION_GROUP, + self::TYPE_INTERNAL, + self::TYPE_GROUP_MEETING, ], true)) { throw new InvalidArgumentException('Value `' . $type . '` is not of valid types for `type` parameter.'); } @@ -138,12 +157,14 @@ public function setTypes(array $types) // program - const PROGRAM_NOT_SELECTED = 0; + const PROGRAM_NOT_SELECTED = 'none'; const PROGRAM_NATURE = 'ap'; const PROGRAM_SIGHTS = 'pamatky'; const PROGRAM_BRDO = 'brdo'; + /** @deprecated */ const PROGRAM_EKOSTAN = 'ekostan'; const PROGRAM_PSB = 'psb'; + /** @deprecated */ const PROGRAM_EDUCATION = 'vzdelavani'; /** @@ -184,10 +205,12 @@ public function setPrograms(array $programs) // target group - const TARGET_GROUP_NOT_SELECTED = 0; + const TARGET_GROUP_NOT_SELECTED = 'none'; const TARGET_GROUP_ADULTS = 'dospeli'; const TARGET_GROUP_CHILDREN = 'deti'; const TARGET_GROUP_FAMILIES = 'detirodice'; + /** @deprecated */ + const TARGET_GROUP_EVERYONE = 'vsichni'; const TARGET_GROUP_FIRST_TIME_ATTENDEES = 'prvouc'; /** @@ -201,6 +224,7 @@ public function setTargetGroup($targetGroup) self::TARGET_GROUP_ADULTS, self::TARGET_GROUP_CHILDREN, self::TARGET_GROUP_FAMILIES, + self::TARGET_GROUP_EVERYONE, self::TARGET_GROUP_FIRST_TIME_ATTENDEES, ], true)) { throw new InvalidArgumentException('Value `' . $targetGroup . '` is not of valid types for `for` parameter.'); From 8a038da4d9c2d6f54369eebbc47b87e2c1e96a43 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sun, 24 Feb 2019 11:22:41 +0100 Subject: [PATCH 21/41] Response\Event\Program: added missing none type --- src/Response/Event/Program.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Response/Event/Program.php b/src/Response/Event/Program.php index 1bf65a1..cdf4198 100644 --- a/src/Response/Event/Program.php +++ b/src/Response/Event/Program.php @@ -8,6 +8,7 @@ final class Program { + const PROGRAM_NONE = 'none'; const PROGRAM_NATURE = 'ap'; const PROGRAM_SIGHTS = 'pamatky'; const PROGRAM_BRDO = 'brdo'; @@ -26,10 +27,12 @@ final class Program /** * @param string $slug * @param string $name + * @param InvalidArgumentException */ private function __construct($slug, $name) { if (!\in_array($slug, [ + self::PROGRAM_NONE, self::PROGRAM_NATURE, self::PROGRAM_SIGHTS, self::PROGRAM_BRDO, From 142880eeb36ddf3ecf212920fa42282de89bad24 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Sun, 24 Feb 2019 11:23:15 +0100 Subject: [PATCH 22/41] Response\Event: fixed throwing errors when unknown stuff comes from BIS --- src/Response/Event/Event.php | 9 ++++++++- src/Response/Event/TargetGroup.php | 2 -- src/Response/OrganizationalUnit/OrganizationalUnit.php | 2 -- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 413cf76..eeecc84 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -3,6 +3,7 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event; use HnutiBrontosaurus\BisApiClient\BisClientException; +use HnutiBrontosaurus\BisApiClient\InvalidArgumentException; use HnutiBrontosaurus\BisApiClient\Response\Event\Invitation\Invitation; use HnutiBrontosaurus\BisApiClient\Response\Event\Registration\RegistrationType; @@ -184,7 +185,13 @@ private function __construct( // program if ($programSlug !== null && $programName !== null) { - $this->program = Program::from($programSlug, $programName); + try { + $this->program = Program::from($programSlug, $programName); + + } catch (InvalidArgumentException $e) { + // if exception, program remains null + + } } diff --git a/src/Response/Event/TargetGroup.php b/src/Response/Event/TargetGroup.php index 0840906..44d350a 100644 --- a/src/Response/Event/TargetGroup.php +++ b/src/Response/Event/TargetGroup.php @@ -2,8 +2,6 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event; -use HnutiBrontosaurus\BisApiClient\BisClientException; - final class TargetGroup { diff --git a/src/Response/OrganizationalUnit/OrganizationalUnit.php b/src/Response/OrganizationalUnit/OrganizationalUnit.php index 1a07adf..0ed3e03 100644 --- a/src/Response/OrganizationalUnit/OrganizationalUnit.php +++ b/src/Response/OrganizationalUnit/OrganizationalUnit.php @@ -2,8 +2,6 @@ namespace HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit; -use HnutiBrontosaurus\BisApiClient\InvalidArgumentException; - final class OrganizationalUnit { From 4a6f6d91eb5afbbdc22e9fae7f1e28846db11077 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 1 Mar 2019 16:57:05 +0100 Subject: [PATCH 23/41] Response\Event: implemented cover photo and presentational photo distinction --- src/Response/Event/Event.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index eeecc84..69f5f22 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -81,6 +81,7 @@ final class Event /** * @param int $id * @param string $name + * @param string|null $coverPhotoPath * @param \DateTimeImmutable $dateFrom * @param \DateTimeImmutable $dateUntil * @param string $type @@ -121,6 +122,7 @@ final class Event private function __construct( $id, $name, + $coverPhotoPath = null, \DateTimeImmutable $dateFrom, \DateTimeImmutable $dateUntil, $type, @@ -177,8 +179,8 @@ private function __construct( // cover photo - if (\count($invitationPresentationPhotos) > 0) { - $this->coverPhotoPath = \reset($invitationPresentationPhotos); + if ($coverPhotoPath !== null) { + $this->coverPhotoPath = $coverPhotoPath; } @@ -254,10 +256,7 @@ public static function fromResponseData(array $data) } $invitationPresentationPhotos = []; - if ($data['priloha_1'] !== '') { - $invitationPresentationPhotos[] = $data['priloha_1']; - } - if ($data['priloha_2'] !== '') { + if ($data['priloha_2'] !== '') { // intentionally ignoring `priloha_1` as that serves as cover image $invitationPresentationPhotos[] = $data['priloha_2']; } if ($data['priloha_4'] !== '') { @@ -272,10 +271,14 @@ public static function fromResponseData(array $data) if ($data['priloha_6'] !== '') { $invitationPresentationPhotos[] = $data['priloha_6']; } + if ($data['priloha_7'] !== '') { + $invitationPresentationPhotos[] = $data['priloha_7']; + } return new self( (int)$data['id'], $data['nazev'], + $data['priloha_1'] !== '' ? $data['priloha_1'] : null, \DateTimeImmutable::createFromFormat('Y-m-d', $data['od']), \DateTimeImmutable::createFromFormat('Y-m-d', $data['do']), $data['typ'], From 549848f38a1bcd27c6f3843d8b0dbaaf4f5a9959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jir=CC=8Ci=CC=81=20Pudil?= Date: Mon, 4 Mar 2019 13:16:40 +0100 Subject: [PATCH 24/41] Response: trust nobody - we don't want so many notices for undefined indices in response data --- src/Response/Event/Event.php | 70 +++++++++---------- .../OrganizationalUnit/OrganizationalUnit.php | 10 +-- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 69f5f22..e473e93 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -247,7 +247,7 @@ private function __construct( public static function fromResponseData(array $data) { $price = 0; - if ($data['poplatek'] !== '') { + if (isset($data['poplatek']) && $data['poplatek'] !== '') { $price = $data['poplatek']; if (\preg_match('|^[0-9]+$|', $price)) { @@ -256,65 +256,65 @@ public static function fromResponseData(array $data) } $invitationPresentationPhotos = []; - if ($data['priloha_2'] !== '') { // intentionally ignoring `priloha_1` as that serves as cover image + if (isset($data['priloha_2']) && $data['priloha_2'] !== '') { // intentionally ignoring `priloha_1` as that serves as cover image $invitationPresentationPhotos[] = $data['priloha_2']; } - if ($data['priloha_4'] !== '') { + if (isset($data['priloha_4']) && $data['priloha_4'] !== '') { $invitationPresentationPhotos[] = $data['priloha_3']; } - if ($data['priloha_4'] !== '') { + if (isset($data['priloha_4']) && $data['priloha_4'] !== '') { $invitationPresentationPhotos[] = $data['priloha_4']; } - if ($data['priloha_5'] !== '') { + if (isset($data['priloha_5']) && $data['priloha_5'] !== '') { $invitationPresentationPhotos[] = $data['priloha_5']; } - if ($data['priloha_6'] !== '') { + if (isset($data['priloha_6']) && $data['priloha_6'] !== '') { $invitationPresentationPhotos[] = $data['priloha_6']; } - if ($data['priloha_7'] !== '') { + if (isset($data['priloha_7']) && $data['priloha_7'] !== '') { $invitationPresentationPhotos[] = $data['priloha_7']; } return new self( (int)$data['id'], $data['nazev'], - $data['priloha_1'] !== '' ? $data['priloha_1'] : null, + (isset($data['priloha_1']) && $data['priloha_1'] !== '') ? $data['priloha_1'] : null, \DateTimeImmutable::createFromFormat('Y-m-d', $data['od']), \DateTimeImmutable::createFromFormat('Y-m-d', $data['do']), $data['typ'], - $data['program_id'] !== '' ? $data['program_id'] : null, - $data['program'] !== '' ? $data['program'] : null, + (isset($data['program_id']) && $data['program_id'] !== '') ? $data['program_id'] : null, + (isset($data['program']) && $data['program'] !== '') ? $data['program'] : null, $data['lokalita_nazev'], - $data['lokalita_misto'] !== '' ? $data['lokalita_misto'] : null, - $data['lokalita_gps'] !== '' ? $data['lokalita_gps'] : null, + (isset($data['lokalita_misto']) && $data['lokalita_misto'] !== '') ? $data['lokalita_misto'] : null, + (isset($data['lokalita_gps']) && $data['lokalita_gps'] !== '') ? $data['lokalita_gps'] : null, (int) $data['prihlasovani_id'], - $data['add_info_title'] !== '' ? $data['add_info_title'] : null, - $data['add_info_title_2'] !== '' ? $data['add_info_title_2'] : null, - $data['add_info_title_3'] !== '' ? $data['add_info_title_3'] : null, - $data['kontakt_url'] !== '' ? $data['kontakt_url'] : null, - $data['vek_od'] !== '' ? ((int) $data['vek_od']) : null, - $data['vek_do'] !== '' ? ((int) $data['vek_do']) : null, + (isset($data['add_info_title']) && $data['add_info_title'] !== '') ? $data['add_info_title'] : null, + (isset($data['add_info_title_2']) && $data['add_info_title_2'] !== '') ? $data['add_info_title_2'] : null, + (isset($data['add_info_title_3']) && $data['add_info_title_3'] !== '') ? $data['add_info_title_3'] : null, + (isset($data['kontakt_url']) && $data['kontakt_url'] !== '') ? $data['kontakt_url'] : null, + (isset($data['vek_od']) && $data['vek_od'] !== '') ? ((int) $data['vek_od']) : null, + (isset($data['vek_do']) && $data['vek_do'] !== '') ? ((int) $data['vek_do']) : null, $price, - $data['porada_id'] !== '' ? ((int)$data['porada_id']) : null, - $data['porada'] !== '' ? $data['porada'] : null, - $data['org'] !== '' ? $data['org'] : null, - $data['kontakt'] !== '' ? $data['kontakt'] : null, + (isset($data['porada_id']) && $data['porada_id'] !== '') ? ((int)$data['porada_id']) : null, + (isset($data['porada']) && $data['porada'] !== '') ? $data['porada'] : null, + (isset($data['org']) && $data['org'] !== '') ? $data['org'] : null, + (isset($data['kontakt']) && $data['kontakt'] !== '') ? $data['kontakt'] : null, $data['kontakt_telefon'], $data['kontakt_email'], - $data['web'] !== '' ? $data['web'] : null, - $data['prokoho_id'] !== '' ? ((int) $data['prokoho_id']) : null, - $data['text_info'] !== '' ? $data['text_info'] : null, - $data['text_uvod'] !== '' ? $data['text_uvod'] : null, - $data['text_mnam'] !== '' ? $data['text_mnam'] : null, + (isset($data['web']) && $data['web'] !== '') ? $data['web'] : null, + (isset($data['prokoho_id']) && $data['prokoho_id'] !== '') ? ((int) $data['prokoho_id']) : null, + (isset($data['text_info']) && $data['text_info'] !== '') ? $data['text_info'] : null, + (isset($data['text_uvod']) && $data['text_uvod'] !== '') ? $data['text_uvod'] : null, + (isset($data['text_mnam']) && $data['text_mnam'] !== '') ? $data['text_mnam'] : null, $invitationPresentationPhotos, - $data['text_prace'] !== '' ? $data['text_prace'] : null, - $data['sraz'] !== '' ? $data['sraz'] : null, - $data['odpovedna'] !== '' ? $data['odpovedna'] : null, - $data['pracovni_doba'] !== '' ? ((int) $data['pracovni_doba']) : null, - $data['popis_programu'] !== '' ? $data['popis_programu'] : null, - $data['ubytovani'] !== '' ? $data['ubytovani'] : null, - $data['strava'] !== '' ? $data['strava'] : null, - $data['jak_se_prihlasit'] !== '' ? $data['jak_se_prihlasit'] : null + (isset($data['text_prace']) && $data['text_prace'] !== '') ? $data['text_prace'] : null, + (isset($data['sraz']) && $data['sraz'] !== '') ? $data['sraz'] : null, + (isset($data['odpovedna']) && $data['odpovedna'] !== '') ? $data['odpovedna'] : null, + (isset($data['pracovni_doba']) && $data['pracovni_doba'] !== '') ? ((int) $data['pracovni_doba']) : null, + (isset($data['popis_programu']) && $data['popis_programu'] !== '') ? $data['popis_programu'] : null, + (isset($data['ubytovani']) && $data['ubytovani'] !== '') ? $data['ubytovani'] : null, + (isset($data['strava']) && $data['strava'] !== '') ? $data['strava'] : null, + (isset($data['jak_se_prihlasit']) && $data['jak_se_prihlasit'] !== '') ? $data['jak_se_prihlasit'] : null ); } diff --git a/src/Response/OrganizationalUnit/OrganizationalUnit.php b/src/Response/OrganizationalUnit/OrganizationalUnit.php index 0ed3e03..cb0e428 100644 --- a/src/Response/OrganizationalUnit/OrganizationalUnit.php +++ b/src/Response/OrganizationalUnit/OrganizationalUnit.php @@ -103,12 +103,12 @@ public static function fromResponseData(array $data) $data['ulice'], $data['mesto'], $data['psc'], - $data['telefon'] !== '' ? $data['telefon'] : null, - $data['email'] !== '' ? $data['email'] : null, - $data['www'] !== '' ? $data['www'] : null, + (isset($data['telefon']) && $data['telefon'] !== '') ? $data['telefon'] : null, + (isset($data['email']) && $data['email'] !== '') ? $data['email'] : null, + (isset($data['www']) && $data['www'] !== '') ? $data['www'] : null, (int) $data['uroven'], - $data['predseda'] !== '' ? $data['predseda'] : null, - $data['hospodar'] !== '' ? $data['hospodar'] : null + (isset($data['predseda']) && $data['predseda'] !== '') ? $data['predseda'] : null, + (isset($data['hospodar']) && $data['hospodar'] !== '') ? $data['hospodar'] : null ); } From 6bd7e97a330aa70a70fb18ebaa5a0fe0dfb247ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jir=CC=8Ci=CC=81=20Pudil?= Date: Mon, 4 Mar 2019 17:44:45 +0100 Subject: [PATCH 25/41] Event: some fields in BIS API were suddenly renamed --- src/Response/Event/Event.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index e473e93..973f569 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -256,23 +256,23 @@ public static function fromResponseData(array $data) } $invitationPresentationPhotos = []; - if (isset($data['priloha_2']) && $data['priloha_2'] !== '') { // intentionally ignoring `priloha_1` as that serves as cover image - $invitationPresentationPhotos[] = $data['priloha_2']; + if (isset($data['ochutnavka_1']) && $data['ochutnavka_1'] !== '') { + $invitationPresentationPhotos[] = $data['ochutnavka_1']; } - if (isset($data['priloha_4']) && $data['priloha_4'] !== '') { - $invitationPresentationPhotos[] = $data['priloha_3']; + if (isset($data['ochutnavka_2']) && $data['ochutnavka_2'] !== '') { + $invitationPresentationPhotos[] = $data['ochutnavka_2']; } - if (isset($data['priloha_4']) && $data['priloha_4'] !== '') { - $invitationPresentationPhotos[] = $data['priloha_4']; + if (isset($data['ochutnavka_3']) && $data['ochutnavka_3'] !== '') { + $invitationPresentationPhotos[] = $data['ochutnavka_3']; } - if (isset($data['priloha_5']) && $data['priloha_5'] !== '') { - $invitationPresentationPhotos[] = $data['priloha_5']; + if (isset($data['ochutnavka_4']) && $data['ochutnavka_4'] !== '') { + $invitationPresentationPhotos[] = $data['ochutnavka_4']; } - if (isset($data['priloha_6']) && $data['priloha_6'] !== '') { - $invitationPresentationPhotos[] = $data['priloha_6']; + if (isset($data['ochutnavka_5']) && $data['ochutnavka_5'] !== '') { + $invitationPresentationPhotos[] = $data['ochutnavka_5']; } - if (isset($data['priloha_7']) && $data['priloha_7'] !== '') { - $invitationPresentationPhotos[] = $data['priloha_7']; + if (isset($data['ochutnavka_6']) && $data['ochutnavka_6'] !== '') { + $invitationPresentationPhotos[] = $data['ochutnavka_6']; } return new self( @@ -284,10 +284,10 @@ public static function fromResponseData(array $data) $data['typ'], (isset($data['program_id']) && $data['program_id'] !== '') ? $data['program_id'] : null, (isset($data['program']) && $data['program'] !== '') ? $data['program'] : null, - $data['lokalita_nazev'], + $data['lokalita'], (isset($data['lokalita_misto']) && $data['lokalita_misto'] !== '') ? $data['lokalita_misto'] : null, (isset($data['lokalita_gps']) && $data['lokalita_gps'] !== '') ? $data['lokalita_gps'] : null, - (int) $data['prihlasovani_id'], + (int) $data['prihlaska'], (isset($data['add_info_title']) && $data['add_info_title'] !== '') ? $data['add_info_title'] : null, (isset($data['add_info_title_2']) && $data['add_info_title_2'] !== '') ? $data['add_info_title_2'] : null, (isset($data['add_info_title_3']) && $data['add_info_title_3'] !== '') ? $data['add_info_title_3'] : null, @@ -307,7 +307,7 @@ public static function fromResponseData(array $data) (isset($data['text_uvod']) && $data['text_uvod'] !== '') ? $data['text_uvod'] : null, (isset($data['text_mnam']) && $data['text_mnam'] !== '') ? $data['text_mnam'] : null, $invitationPresentationPhotos, - (isset($data['text_prace']) && $data['text_prace'] !== '') ? $data['text_prace'] : null, + (isset($data['prace']) && $data['prace'] !== '') ? $data['prace'] : null, (isset($data['sraz']) && $data['sraz'] !== '') ? $data['sraz'] : null, (isset($data['odpovedna']) && $data['odpovedna'] !== '') ? $data['odpovedna'] : null, (isset($data['pracovni_doba']) && $data['pracovni_doba'] !== '') ? ((int) $data['pracovni_doba']) : null, From 4b58eba369f7f44a568d9105083a6d6460e431f5 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Wed, 6 Mar 2019 13:49:15 +0100 Subject: [PATCH 26/41] Request\Event: undeprecated some stuff --- src/Request/EventParameters.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index cd4239b..792e6b4 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -46,10 +46,14 @@ public function setId($id) const FILTER_EKOSTAN = 8; /** + * This parameter serves as combinator for multiple conditions, which can not be achieved with concatenating type, program, target group or any other available parameters. + * For example you can not make an union among different parameters. Let's say you want all events which are of type=ohb or of program=brdo. This is not possible with API parameters. + * Thus you can take advantage of preset filters which are documented here: https://bis.brontosaurus.cz/myr.html + * * Beside standard constant usage as a parameter, you can pass bitwise operation argument, e.g. `EventParameters::FILTER_WEEKEND|EventParameters::FILTER_CAMP`. + * * @param int $filter * @return self - * @deprecated This is blackbox parameter as nobody really knows from outside what this parameter really does. It is recommended to use combination of other parameters instead. */ public function setFilter($filter) { @@ -161,10 +165,8 @@ public function setTypes(array $types) const PROGRAM_NATURE = 'ap'; const PROGRAM_SIGHTS = 'pamatky'; const PROGRAM_BRDO = 'brdo'; - /** @deprecated */ const PROGRAM_EKOSTAN = 'ekostan'; const PROGRAM_PSB = 'psb'; - /** @deprecated */ const PROGRAM_EDUCATION = 'vzdelavani'; /** @@ -209,10 +211,13 @@ public function setPrograms(array $programs) const TARGET_GROUP_ADULTS = 'dospeli'; const TARGET_GROUP_CHILDREN = 'deti'; const TARGET_GROUP_FAMILIES = 'detirodice'; - /** @deprecated */ - const TARGET_GROUP_EVERYONE = 'vsichni'; const TARGET_GROUP_FIRST_TIME_ATTENDEES = 'prvouc'; + /** + * @deprecated Seems like not useful as there is `none` option as well which should have the same semantic meaning. + */ + const TARGET_GROUP_EVERYONE = 'vsichni'; + /** * @param string $targetGroup * @return self From e518c855b0fc2a4945ccaccd50b6b2b4149cd14a Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Wed, 13 Mar 2019 18:11:45 +0100 Subject: [PATCH 27/41] Refactored and improved exceptions --- src/Client.php | 45 +++++++++---------- src/Request/EventParameters.php | 4 ++ src/Request/OrganizationalUnitParameters.php | 4 ++ src/Response/Event/Event.php | 8 +++- src/Response/Event/Program.php | 2 +- .../Event/Registration/RegistrationType.php | 12 +++-- src/Response/exceptions.php | 26 ++++++++++- src/exceptions.php | 30 ++++++++----- 8 files changed, 89 insertions(+), 42 deletions(-) diff --git a/src/Client.php b/src/Client.php index f8769d5..d45364e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,7 +5,6 @@ use GuzzleHttp\Client as HttpClient; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\GuzzleException; -use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\Request; use HnutiBrontosaurus\BisApiClient\Request\Adoption; use HnutiBrontosaurus\BisApiClient\Request\EventAttendee; @@ -13,8 +12,10 @@ use HnutiBrontosaurus\BisApiClient\Request\OrganizationalUnitParameters; use HnutiBrontosaurus\BisApiClient\Request\Parameters; use HnutiBrontosaurus\BisApiClient\Response\Event\Event; +use HnutiBrontosaurus\BisApiClient\Response\InvalidContentTypeException; use HnutiBrontosaurus\BisApiClient\Response\InvalidParametersException; use HnutiBrontosaurus\BisApiClient\Response\InvalidUserInputException; +use HnutiBrontosaurus\BisApiClient\Response\InvalidXMLStructureException; use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit\OrganizationalUnit; use HnutiBrontosaurus\BisApiClient\Response\OrganizationalUnit\UnknownOrganizationUnitTypeException; use HnutiBrontosaurus\BisApiClient\Response\Response; @@ -45,6 +46,7 @@ final class Client * @param string $username * @param string $password * @param HttpClient $httpClient + * @throws InvalidArgumentException */ public function __construct($url, $username, $password, HttpClient $httpClient) { @@ -71,9 +73,9 @@ public function __construct($url, $username, $password, HttpClient $httpClient) * @param int $id * @param EventParameters $params * @return Event - * @throws BisClientException - * @throws GuzzleException - * @throws ResourceNotFoundException + * @throws NotFoundException + * @throws TransferErrorException + * @throws ResponseErrorException */ public function getEvent($id, EventParameters $params = null) { @@ -84,7 +86,7 @@ public function getEvent($id, EventParameters $params = null) $data = $response->getData(); if (\count($data) === 0) { - throw new BisClientException('No result for event with id `' . $id . '`.'); + throw new NotFoundException('No result for event with id `' . $id . '`.'); } return Event::fromResponseData(\reset($data)); @@ -93,9 +95,9 @@ public function getEvent($id, EventParameters $params = null) /** * @param EventParameters $params * @return Event[] - * @throws BisClientException - * @throws GuzzleException - * @throws ResourceNotFoundException + * @throws NotFoundException + * @throws TransferErrorException + * @throws ResponseErrorException */ public function getEvents(EventParameters $params = null) { @@ -112,7 +114,6 @@ public function getEvents(EventParameters $params = null) /** * @param EventAttendee $eventAttendee * @throws ResponseErrorException - * @throws BisClientException */ public function addAttendeeToEvent(EventAttendee $eventAttendee) { @@ -132,9 +133,9 @@ public function addAttendeeToEvent(EventAttendee $eventAttendee) /** * @param OrganizationalUnitParameters $params * @return OrganizationalUnit[] - * @throws BisClientException - * @throws GuzzleException - * @throws ResourceNotFoundException + * @throws NotFoundException + * @throws TransferErrorException + * @throws ResponseErrorException */ public function getOrganizationalUnits(OrganizationalUnitParameters $params = null) { @@ -160,7 +161,6 @@ public function getOrganizationalUnits(OrganizationalUnitParameters $params = nu /** * @param Adoption $adoption * @throws ResponseErrorException - * @throws BisClientException */ public function saveRequestForAdoption(Adoption $adoption) { @@ -178,10 +178,9 @@ public function saveRequestForAdoption(Adoption $adoption) /** * @param Parameters $requestParameters * @return Response + * @throws NotFoundException + * @throws TransferErrorException * @throws ResponseErrorException - * @throws BisClientException - * @throws GuzzleException - * @throws ResourceNotFoundException */ private function processRequest(Parameters $requestParameters) { @@ -193,10 +192,10 @@ private function processRequest(Parameters $requestParameters) $response = $this->httpClient->send($httpRequest); } catch (ClientException $e) { - throw new ResourceNotFoundException('Bis client could not find the queried resource.', 0, $e); + throw new NotFoundException('Bis client could not find the queried resource.', 0, $e); - } catch (TransferException $e) { - throw new BisClientException('Unable to process request: transfer error.', 0, $e); + } catch (GuzzleException $e) { + throw new TransferErrorException('Unable to process request: transfer error.', 0, $e); } $this->checkForResponseContentType($response); @@ -210,19 +209,19 @@ private function processRequest(Parameters $requestParameters) /** * @param ResponseInterface $response - * @throws BisClientException + * @throws InvalidContentTypeException */ private function checkForResponseContentType(ResponseInterface $response) { if (\strncmp($response->getHeaderLine('Content-Type'), 'text/xml', \strlen('text/xml')) !== 0) { - throw new BisClientException('Unable to process response: the response Content-Type is invalid or missing.'); + throw new InvalidContentTypeException('Unable to process response: the response Content-Type is invalid or missing.'); } } /** * @param ResponseInterface $response * @return \DOMDocument - * @throws BisClientException + * @throws InvalidXMLStructureException */ private function generateDOM(ResponseInterface $response) { @@ -231,7 +230,7 @@ private function generateDOM(ResponseInterface $response) $domDocument->loadXML($response->getBody()); } catch (\Exception $e) { - throw new BisClientException('Unable to process response: response body contains invalid XML.', 0, $e); + throw new InvalidXMLStructureException('Unable to process response: response body contains invalid XML.', 0, $e); } return $domDocument; diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index 792e6b4..7e01701 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -54,6 +54,7 @@ public function setId($id) * * @param int $filter * @return self + * @throws InvalidArgumentException */ public function setFilter($filter) { @@ -115,6 +116,7 @@ public function setFilter($filter) /** * @param string $type * @return self + * @throws InvalidArgumentException */ public function setType($type) { @@ -172,6 +174,7 @@ public function setTypes(array $types) /** * @param string $program * @return self + * @throws InvalidArgumentException */ public function setProgram($program) { @@ -221,6 +224,7 @@ public function setPrograms(array $programs) /** * @param string $targetGroup * @return self + * @throws InvalidArgumentException */ public function setTargetGroup($targetGroup) { diff --git a/src/Request/OrganizationalUnitParameters.php b/src/Request/OrganizationalUnitParameters.php index f58f79c..4a0c339 100644 --- a/src/Request/OrganizationalUnitParameters.php +++ b/src/Request/OrganizationalUnitParameters.php @@ -25,6 +25,8 @@ public function __construct() /** * @param string $type + * @return self + * @throws InvalidArgumentException */ public function setType($type) { @@ -37,6 +39,8 @@ public function setType($type) } $this->params[self::PARAM_FILTER] = $type; + + return $this; } } diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 973f569..0004956 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -2,10 +2,11 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event; -use HnutiBrontosaurus\BisApiClient\BisClientException; +use HnutiBrontosaurus\BisApiClient\BadUsageException; use HnutiBrontosaurus\BisApiClient\InvalidArgumentException; use HnutiBrontosaurus\BisApiClient\Response\Event\Invitation\Invitation; use HnutiBrontosaurus\BisApiClient\Response\Event\Registration\RegistrationType; +use HnutiBrontosaurus\BisApiClient\Response\RegistrationTypeException; final class Event @@ -118,6 +119,8 @@ final class Event * @param string|null $accommodation * @param string|null $food * @param string|null $notes + * @throws RegistrationTypeException + * @throws BadUsageException */ private function __construct( $id, @@ -242,7 +245,8 @@ private function __construct( /** * @param string[] $data Everything is string as it comes from HTTP response body. * @return self - * @throws BisClientException + * @throws RegistrationTypeException + * @throws BadUsageException */ public static function fromResponseData(array $data) { diff --git a/src/Response/Event/Program.php b/src/Response/Event/Program.php index cdf4198..4aae850 100644 --- a/src/Response/Event/Program.php +++ b/src/Response/Event/Program.php @@ -27,7 +27,7 @@ final class Program /** * @param string $slug * @param string $name - * @param InvalidArgumentException + * @throws InvalidArgumentException */ private function __construct($slug, $name) { diff --git a/src/Response/Event/Registration/RegistrationType.php b/src/Response/Event/Registration/RegistrationType.php index 8e3f541..32c34de 100644 --- a/src/Response/Event/Registration/RegistrationType.php +++ b/src/Response/Event/Registration/RegistrationType.php @@ -2,8 +2,8 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event\Registration; -use HnutiBrontosaurus\BisApiClient\BisClientException; -use HnutiBrontosaurus\BisApiClient\RegistrationTypeException; +use HnutiBrontosaurus\BisApiClient\BadUsageException; +use HnutiBrontosaurus\BisApiClient\Response\RegistrationTypeException; final class RegistrationType @@ -135,6 +135,8 @@ public function isOfTypeEmail() /** * @return string|null + * @throws RegistrationTypeException + * @throws BadUsageException */ public function getEmail() { @@ -143,7 +145,7 @@ public function getEmail() } if ( ! $this->isOfTypeEmail()) { - throw new BisClientException('This method can not be called when the registration is not of `via e-mail` type.'); + throw new BadUsageException('This method can not be called when the registration is not of `via e-mail` type.'); } return $this->email; @@ -162,6 +164,8 @@ public function isOfTypeCustomWebpage() /** * @return string|null + * @throws RegistrationTypeException + * @throws BadUsageException */ public function getUrl() { @@ -170,7 +174,7 @@ public function getUrl() } if ( ! $this->isOfTypeCustomWebpage()) { - throw new BisClientException('This method can not be called when the registration is not of `via custom webpage` type.'); + throw new BadUsageException('This method can not be called when the registration is not of `via custom webpage` type.'); } return $this->url; diff --git a/src/Response/exceptions.php b/src/Response/exceptions.php index a899147..57904d0 100644 --- a/src/Response/exceptions.php +++ b/src/Response/exceptions.php @@ -2,12 +2,24 @@ namespace HnutiBrontosaurus\BisApiClient\Response; -use HnutiBrontosaurus\BisApiClient\BisClientException; +use HnutiBrontosaurus\BisApiClient\BisApiClientRuntimeException; -abstract class ResponseErrorException extends BisClientException +abstract class ResponseErrorException extends BisApiClientRuntimeException {} + +// invalid data structure + +final class InvalidContentTypeException extends ResponseErrorException +{} + +final class InvalidXMLStructureException extends ResponseErrorException +{} + + +// invalid data values + final class InvalidParametersException extends ResponseErrorException {} @@ -46,3 +58,13 @@ public function __construct($unknownErrorTypeKey) } } + +final class RegistrationTypeException extends ResponseErrorException +{ + + public static function missingAdditionalData($key, $type) + { + return new self(\sprintf('Missing additional data `%s` for selected type %d.', $key, $type)); + } + +} diff --git a/src/exceptions.php b/src/exceptions.php index fd9c36a..b3f1665 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -3,21 +3,31 @@ namespace HnutiBrontosaurus\BisApiClient; -class InvalidArgumentException extends \InvalidArgumentException +// overall exceptions + +abstract class BisApiClientLogicException extends \LogicException +{} + +abstract class BisApiClientRuntimeException extends \RuntimeException {} -class ResourceNotFoundException extends \RuntimeException + +// working with API exceptions + +final class InvalidArgumentException extends BisApiClientLogicException {} -class BisClientException extends \RuntimeException +final class BadUsageException extends BisApiClientLogicException {} -final class RegistrationTypeException extends BisClientException -{ - public static function missingAdditionalData($key, $type) - { - return new self(\sprintf('Missing additional data `%s` for selected type %d.', $key, $type)); - } +// communicating with BIS exceptions -} +abstract class ConnectionException extends BisApiClientRuntimeException +{} + +final class TransferErrorException extends ConnectionException +{} + +final class NotFoundException extends ConnectionException +{} From 872a8e486a1501145a9f935edc9a7938c5b84805 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 14 Mar 2019 13:57:26 +0100 Subject: [PATCH 28/41] Response\Event: moved accommodation & food to Invitation class and added their is* methods --- src/Response/Event/Event.php | 26 +------- src/Response/Event/Invitation/Invitation.php | 70 ++++++++++++++++++-- 2 files changed, 67 insertions(+), 29 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 0004956..e7d716a 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -69,12 +69,6 @@ final class Event /** @var string|null */ private $programDescription; - /** @var string|null */ - private $accommodation; - - /** @var string|null */ - private $food; - /** @var string|null */ private $notes; @@ -175,8 +169,6 @@ private function __construct( $this->meetingInformation = $meetingInformation; $this->workingTime = $workingTime; $this->programDescription = $programDescription; - $this->accommodation = $accommodation; - $this->food = $food; $this->notes = $notes; @@ -235,6 +227,8 @@ private function __construct( $this->invitation = Invitation::from( $invitationIntroduction, $invitationOrganizationalInformation, + $accommodation, + $food, $invitationWorkDescription, $invitationPresentationText, $invitationPresentationPhotos @@ -480,22 +474,6 @@ public function getProgramDescription() return $this->programDescription; } - /** - * @return string|null - */ - public function getAccommodation() - { - return $this->accommodation; - } - - /** - * @return string|null - */ - public function getFood() - { - return $this->food; - } - /** * @return string|null */ diff --git a/src/Response/Event/Invitation/Invitation.php b/src/Response/Event/Invitation/Invitation.php index 7dcab09..282d71b 100644 --- a/src/Response/Event/Invitation/Invitation.php +++ b/src/Response/Event/Invitation/Invitation.php @@ -12,12 +12,15 @@ final class Invitation /** @var string */ private $organizationalInformation; + /** @var string|null */ + private $accommodation; + + /** @var string|null */ + private $food; + /** @var string */ private $workDescription; - /** @var bool */ - private $hasPresentation = false; - /** @var Presentation|null */ private $presentation; @@ -25,23 +28,34 @@ final class Invitation /** * @param string $introduction * @param string $organizationalInformation + * @param string|null $accommodation + * @param string|null $food * @param string $workDescription * @param string|null $presentationText * @param string[] $presentationPhotos */ private function __construct( $introduction, - $organizationalInformation, + $organizationalInformation = null, + $accommodation = null, + $food, $workDescription, $presentationText = null, array $presentationPhotos = [] ) { $this->introduction = $introduction; $this->organizationalInformation = $organizationalInformation; + + if ($accommodation !== null) { + $this->accommodation = $accommodation; + } + if ($food !== null) { + $this->food = $food; + } + $this->workDescription = $workDescription; if ($presentationText !== null) { - $this->hasPresentation = true; $this->presentation = Presentation::from($presentationText); if (\count($presentationPhotos) > 0) { @@ -53,6 +67,8 @@ private function __construct( /** * @param string $introduction * @param string $organizationalInformation + * @param string|null $accommodation + * @param string|null $food * @param string $workDescription * @param string|null $presentationText * @param string[] $presentationPhotos @@ -61,6 +77,8 @@ private function __construct( public static function from( $introduction, $organizationalInformation, + $accommodation = null, + $food = null, $workDescription, $presentationText = null, array $presentationPhotos = [] @@ -68,6 +86,8 @@ public static function from( return new self( $introduction, $organizationalInformation, + $accommodation, + $food, $workDescription, $presentationText, $presentationPhotos @@ -91,6 +111,38 @@ public function getOrganizationalInformation() return $this->organizationalInformation; } + /** + * @return bool + */ + public function isAccommodationListed() + { + return $this->accommodation !== null; + } + + /** + * @return string|null + */ + public function getAccommodation() + { + return $this->accommodation; + } + + /** + * @return bool + */ + public function isFoodListed() + { + return $this->food !== null; + } + + /** + * @return string|null + */ + public function getFood() + { + return $this->food; + } + /** * @return string */ @@ -99,6 +151,14 @@ public function getWorkDescription() return $this->workDescription; } + /** + * @return bool + */ + public function hasPresentation() + { + return $this->presentation !== null; + } + /** * @return Presentation|null */ From 0310b1bc9a9e9c182cd0a2d85ae9f9195b59702f Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 14 Mar 2019 14:05:55 +0100 Subject: [PATCH 29/41] Response\Event: fixed pseudo-null value for food --- src/Response/Event/Event.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index e7d716a..aaa4ccf 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -253,6 +253,11 @@ public static function fromResponseData(array $data) } } + $food = (isset($data['strava']) && $data['strava'] !== '') ? $data['strava'] : null; + if ($food === 'můžete si vybrat') { // BIS API sends this string in case that user sets nothing - we want to get rid of it as it pretends to be a value when it is not + $food = null; + } + $invitationPresentationPhotos = []; if (isset($data['ochutnavka_1']) && $data['ochutnavka_1'] !== '') { $invitationPresentationPhotos[] = $data['ochutnavka_1']; @@ -311,7 +316,7 @@ public static function fromResponseData(array $data) (isset($data['pracovni_doba']) && $data['pracovni_doba'] !== '') ? ((int) $data['pracovni_doba']) : null, (isset($data['popis_programu']) && $data['popis_programu'] !== '') ? $data['popis_programu'] : null, (isset($data['ubytovani']) && $data['ubytovani'] !== '') ? $data['ubytovani'] : null, - (isset($data['strava']) && $data['strava'] !== '') ? $data['strava'] : null, + $food, (isset($data['jak_se_prihlasit']) && $data['jak_se_prihlasit'] !== '') ? $data['jak_se_prihlasit'] : null ); } From e676e4205eeebf1ec163a64b0b61031db4ae55b6 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 14 Mar 2019 14:36:58 +0100 Subject: [PATCH 30/41] Response\Event: moved contactWebsite to Event and renamed to relatedWebsite --- src/Response/Event/Event.php | 56 ++++++++++++++++++++++++++++---- src/Response/Event/Organizer.php | 23 ++----------- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index aaa4ccf..e121484 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -72,6 +72,9 @@ final class Event /** @var string|null */ private $notes; + /** @var string|null */ + private $relatedWebsite; + /** * @param int $id @@ -99,7 +102,6 @@ final class Event * @param string|null $contactPersonName * @param string $contactPhone * @param string $contactEmail - * @param string|null $contactWebsite * @param int|null $targetGroupId * @param string|null $invitationOrganizationalInformation * @param string|null $invitationIntroduction @@ -113,6 +115,7 @@ final class Event * @param string|null $accommodation * @param string|null $food * @param string|null $notes + * @param string|null $relatedWebsite * @throws RegistrationTypeException * @throws BadUsageException */ @@ -142,7 +145,6 @@ private function __construct( $contactPersonName = null, $contactPhone, $contactEmail, - $contactWebsite = null, $targetGroupId = null, $invitationOrganizationalInformation = null, $invitationIntroduction = null, @@ -155,7 +157,8 @@ private function __construct( $programDescription = null, $accommodation = null, $food = null, - $notes = null + $notes = null, + $relatedWebsite = null ) { $this->id = $id; $this->name = $name; @@ -213,8 +216,7 @@ private function __construct( $organizers, $contactPersonName, $contactPhone, - $contactEmail, - $contactWebsite + $contactEmail ); @@ -233,6 +235,17 @@ private function __construct( $invitationPresentationText, $invitationPresentationPhotos ); + + + // related website + + if ($relatedWebsite !== null) { + if ( ! self::startsWith($relatedWebsite, 'http')) { // count with no protocol typed URLs + $relatedWebsite = 'http://' . $relatedWebsite; + } + + $this->relatedWebsite = $relatedWebsite; + } } @@ -304,7 +317,6 @@ public static function fromResponseData(array $data) (isset($data['kontakt']) && $data['kontakt'] !== '') ? $data['kontakt'] : null, $data['kontakt_telefon'], $data['kontakt_email'], - (isset($data['web']) && $data['web'] !== '') ? $data['web'] : null, (isset($data['prokoho_id']) && $data['prokoho_id'] !== '') ? ((int) $data['prokoho_id']) : null, (isset($data['text_info']) && $data['text_info'] !== '') ? $data['text_info'] : null, (isset($data['text_uvod']) && $data['text_uvod'] !== '') ? $data['text_uvod'] : null, @@ -317,7 +329,8 @@ public static function fromResponseData(array $data) (isset($data['popis_programu']) && $data['popis_programu'] !== '') ? $data['popis_programu'] : null, (isset($data['ubytovani']) && $data['ubytovani'] !== '') ? $data['ubytovani'] : null, $food, - (isset($data['jak_se_prihlasit']) && $data['jak_se_prihlasit'] !== '') ? $data['jak_se_prihlasit'] : null + (isset($data['jak_se_prihlasit']) && $data['jak_se_prihlasit'] !== '') ? $data['jak_se_prihlasit'] : null, + (isset($data['web']) && $data['web'] !== '') ? $data['web'] : null ); } @@ -487,4 +500,33 @@ public function getNotes() return $this->notes; } + /** + * @return bool + */ + public function hasRelatedWebsite() + { + return $this->relatedWebsite !== null; + } + + /** + * @return string|null + */ + public function getRelatedWebsite() + { + return $this->relatedWebsite; + } + + + /** + * Extracted from \Nette\Utils\Strings (v2.3) + * Starts the $haystack string with the prefix $needle? + * @param string + * @param string + * @return bool + */ + private static function startsWith($haystack, $needle) + { + return strncmp($haystack, $needle, strlen($needle)) === 0; + } + } diff --git a/src/Response/Event/Organizer.php b/src/Response/Event/Organizer.php index 8d530de..ade2d0a 100644 --- a/src/Response/Event/Organizer.php +++ b/src/Response/Event/Organizer.php @@ -24,9 +24,6 @@ final class Organizer /** @var string */ private $contactEmail; - /** @var string|null */ - private $contactWebsite; - /** * @param int|null $organizationalUnitId @@ -36,7 +33,6 @@ final class Organizer * @param string|null $contactPersonName * @param string $contactPhone * @param string $contactEmail - * @param string|null $contactWebsite */ private function __construct( $organizationalUnitId = null, @@ -45,8 +41,7 @@ private function __construct( $organizers = null, $contactPersonName = null, $contactPhone, - $contactEmail, - $contactWebsite = null + $contactEmail ) { $this->organizationalUnit = ($organizationalUnitId !== null && $organizationalUnitName !== null) ? OrganizerOrganizationalUnit::from($organizationalUnitId, $organizationalUnitName) : null; $this->responsiblePerson = $responsiblePerson; @@ -54,7 +49,6 @@ private function __construct( $this->contactPersonName = $contactPersonName; $this->contactPhone = $contactPhone; $this->contactEmail = $contactEmail; - $this->contactWebsite = $contactWebsite; } /** @@ -65,7 +59,6 @@ private function __construct( * @param string|null $contactPersonName * @param string $contactPhone * @param string $contactEmail - * @param string|null $contactWebsite * * @return self */ @@ -76,8 +69,7 @@ public static function from( $organizers = null, $contactPersonName = null, $contactPhone, - $contactEmail, - $contactWebsite = null + $contactEmail ) { return new self( $organizationalUnitId, @@ -86,8 +78,7 @@ public static function from( $organizers, $contactPersonName, $contactPhone, - $contactEmail, - $contactWebsite + $contactEmail ); } @@ -148,12 +139,4 @@ public function getContactEmail() return $this->contactEmail; } - /** - * @return string|null - */ - public function getContactWebsite() - { - return $this->contactWebsite; - } - } From c994ceabfd2e8b5d873e059a561c4b59a158bfbf Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 14 Mar 2019 14:57:09 +0100 Subject: [PATCH 31/41] Response\Event: moved workingTime to Invitation and renamed to workHoursPerDay --- src/Response/Event/Event.php | 17 +++--------- src/Response/Event/Invitation/Invitation.php | 28 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index e121484..8ca3795 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -63,9 +63,6 @@ final class Event /** @var string|null */ private $meetingInformation; - /** @var int|null */ - private $workingTime; - /** @var string|null */ private $programDescription; @@ -110,7 +107,7 @@ final class Event * @param string|null $invitationWorkDescription * @param string|null $meetingInformation * @param string|null $responsiblePerson - * @param int|null $workingTime + * @param int|null $workHoursPerDay * @param string|null $programDescription * @param string|null $accommodation * @param string|null $food @@ -153,7 +150,7 @@ private function __construct( $invitationWorkDescription = null, $meetingInformation = null, $responsiblePerson = null, - $workingTime = null, + $workHoursPerDay = null, $programDescription = null, $accommodation = null, $food = null, @@ -170,7 +167,6 @@ private function __construct( $this->ageUntil = $ageUntil; $this->price = $price; $this->meetingInformation = $meetingInformation; - $this->workingTime = $workingTime; $this->programDescription = $programDescription; $this->notes = $notes; @@ -232,6 +228,7 @@ private function __construct( $accommodation, $food, $invitationWorkDescription, + $workHoursPerDay, $invitationPresentationText, $invitationPresentationPhotos ); @@ -476,14 +473,6 @@ public function getMeetingInformation() return $this->meetingInformation; } - /** - * @return int|null - */ - public function getWorkingTime() - { - return $this->workingTime; - } - /** * @return string|null */ diff --git a/src/Response/Event/Invitation/Invitation.php b/src/Response/Event/Invitation/Invitation.php index 282d71b..99d12db 100644 --- a/src/Response/Event/Invitation/Invitation.php +++ b/src/Response/Event/Invitation/Invitation.php @@ -21,6 +21,9 @@ final class Invitation /** @var string */ private $workDescription; + /** @var int|null */ + private $workHoursPerDay; + /** @var Presentation|null */ private $presentation; @@ -31,6 +34,7 @@ final class Invitation * @param string|null $accommodation * @param string|null $food * @param string $workDescription + * @param int|null $workHoursPerDay * @param string|null $presentationText * @param string[] $presentationPhotos */ @@ -40,6 +44,7 @@ private function __construct( $accommodation = null, $food, $workDescription, + $workHoursPerDay = null, $presentationText = null, array $presentationPhotos = [] ) { @@ -55,6 +60,10 @@ private function __construct( $this->workDescription = $workDescription; + if ($workHoursPerDay !== null) { + $this->workHoursPerDay = $workHoursPerDay; + } + if ($presentationText !== null) { $this->presentation = Presentation::from($presentationText); @@ -70,6 +79,7 @@ private function __construct( * @param string|null $accommodation * @param string|null $food * @param string $workDescription + * @param int|null $workHoursPerDay * @param string|null $presentationText * @param string[] $presentationPhotos * @return self @@ -80,6 +90,7 @@ public static function from( $accommodation = null, $food = null, $workDescription, + $workHoursPerDay = null, $presentationText = null, array $presentationPhotos = [] ) { @@ -89,6 +100,7 @@ public static function from( $accommodation, $food, $workDescription, + $workHoursPerDay, $presentationText, $presentationPhotos ); @@ -151,6 +163,22 @@ public function getWorkDescription() return $this->workDescription; } + /** + * @return bool + */ + public function areWorkHoursPerDayListed() + { + return $this->workHoursPerDay !== null; + } + + /** + * @return int|null + */ + public function getWorkHoursPerDay() + { + return $this->workHoursPerDay; + } + /** * @return bool */ From 0ab43f07f6e28d1178551f85cf032b4a41ee4e39 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 12 Apr 2019 09:06:57 +0200 Subject: [PATCH 32/41] Request\Event: fixed id of registration of type none --- .../Event/Registration/RegistrationType.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Response/Event/Registration/RegistrationType.php b/src/Response/Event/Registration/RegistrationType.php index 32c34de..4463dec 100644 --- a/src/Response/Event/Registration/RegistrationType.php +++ b/src/Response/Event/Registration/RegistrationType.php @@ -9,10 +9,10 @@ final class RegistrationType { - const TYPE_NONE = 0; const TYPE_VIA_BRONTOWEB = 1; const TYPE_VIA_EMAIL = 2; const TYPE_VIA_CUSTOM_WEBPAGE = 3; + const TYPE_NONE = 4; const TYPE_DISABLED = 5; @@ -41,10 +41,10 @@ final class RegistrationType private function __construct($type, array $questions = null, $email = null, $url = null) { if ( ! \in_array($type, [ - self::TYPE_NONE, self::TYPE_VIA_BRONTOWEB, self::TYPE_VIA_EMAIL, self::TYPE_VIA_CUSTOM_WEBPAGE, + self::TYPE_NONE, ], true)) { $type = self::TYPE_DISABLED; // silent fallback } @@ -87,15 +87,6 @@ public static function from($type, array $questions = null, $email = null, $url } - /** - * @return bool - */ - public function isOfTypeNone() - { - return $this->type === self::TYPE_NONE; - } - - // registration via Brontoweb /** @@ -152,7 +143,7 @@ public function getEmail() } - // registration custom webpage + // registration via custom webpage /** * @return bool @@ -181,6 +172,17 @@ public function getUrl() } + // no registration needed + + /** + * @return bool + */ + public function isOfTypeNone() + { + return $this->type === self::TYPE_NONE; + } + + // registration disabled public function isOfTypeDisabled() From 91bd8c815cbf87fa82d5e1b04653fff3ff7f458f Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Tue, 16 Apr 2019 13:47:44 +0200 Subject: [PATCH 33/41] Response\Event: renamed meetingInformation to timeFrom --- src/Response/Event/Event.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 8ca3795..e081830 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -24,6 +24,9 @@ final class Event /** @var \DateTimeImmutable */ private $dateFrom; + /** @var string|null */ + private $timeFrom; + /** @var \DateTimeImmutable */ private $dateUntil; @@ -60,9 +63,6 @@ final class Event /** @var Invitation|null */ private $invitation; - /** @var string|null */ - private $meetingInformation; - /** @var string|null */ private $programDescription; @@ -105,7 +105,7 @@ final class Event * @param string|null $invitationPresentationText * @param array $invitationPresentationPhotos * @param string|null $invitationWorkDescription - * @param string|null $meetingInformation + * @param string|null $timeFrom * @param string|null $responsiblePerson * @param int|null $workHoursPerDay * @param string|null $programDescription @@ -148,7 +148,7 @@ private function __construct( $invitationPresentationText = null, array $invitationPresentationPhotos = [], $invitationWorkDescription = null, - $meetingInformation = null, + $timeFrom = null, $responsiblePerson = null, $workHoursPerDay = null, $programDescription = null, @@ -166,7 +166,7 @@ private function __construct( $this->ageFrom = $ageFrom; $this->ageUntil = $ageUntil; $this->price = $price; - $this->meetingInformation = $meetingInformation; + $this->timeFrom = $timeFrom; $this->programDescription = $programDescription; $this->notes = $notes; @@ -465,12 +465,20 @@ public function getInvitation() return $this->invitation; } + /** + * @return bool + */ + public function hasTimeFrom() + { + return $this->timeFrom !== null; + } + /** * @return string|null */ - public function getMeetingInformation() + public function getTimeFrom() { - return $this->meetingInformation; + return $this->timeFrom; } /** From b6af0f6840f741348aa0b5b0050d8c9ff65006d3 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 3 May 2019 21:50:55 +0200 Subject: [PATCH 34/41] Updated client to latest API changes --- src/Client.php | 2 ++ src/Request/EventParameters.php | 10 ++-------- src/Response/Event/Event.php | 12 ++++++------ src/Response/Event/TargetGroup.php | 22 +++------------------- src/Response/Response.php | 12 +++++++++--- 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/Client.php b/src/Client.php index d45364e..6ff66aa 100644 --- a/src/Client.php +++ b/src/Client.php @@ -243,6 +243,8 @@ private function generateDOM(ResponseInterface $response) private function checkForResponseErrors(\DOMDocument $domDocument) { $resultNode = $domDocument->getElementsByTagName(Response::TAG_RESULT)->item(0); + \assert($resultNode instanceof \DOMElement); + if ($resultNode->hasAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR)) { switch ($resultNode->getAttribute(Response::TAG_RESULT_ATTRIBUTE_ERROR)) { case 'success': // In case of POST request with form data, BIS returns `` for some reason... Let's pretend that there is no error in such case because... you know... there is no error! diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index 7e01701..bba130a 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -210,17 +210,12 @@ public function setPrograms(array $programs) // target group - const TARGET_GROUP_NOT_SELECTED = 'none'; + const TARGET_GROUP_EVERYONE = 'vsichni'; const TARGET_GROUP_ADULTS = 'dospeli'; const TARGET_GROUP_CHILDREN = 'deti'; const TARGET_GROUP_FAMILIES = 'detirodice'; const TARGET_GROUP_FIRST_TIME_ATTENDEES = 'prvouc'; - /** - * @deprecated Seems like not useful as there is `none` option as well which should have the same semantic meaning. - */ - const TARGET_GROUP_EVERYONE = 'vsichni'; - /** * @param string $targetGroup * @return self @@ -229,11 +224,10 @@ public function setPrograms(array $programs) public function setTargetGroup($targetGroup) { if ( ! \in_array($targetGroup, [ - self::TARGET_GROUP_NOT_SELECTED, + self::TARGET_GROUP_EVERYONE, self::TARGET_GROUP_ADULTS, self::TARGET_GROUP_CHILDREN, self::TARGET_GROUP_FAMILIES, - self::TARGET_GROUP_EVERYONE, self::TARGET_GROUP_FIRST_TIME_ATTENDEES, ], true)) { throw new InvalidArgumentException('Value `' . $targetGroup . '` is not of valid types for `for` parameter.'); diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index e081830..252b192 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -99,7 +99,7 @@ final class Event * @param string|null $contactPersonName * @param string $contactPhone * @param string $contactEmail - * @param int|null $targetGroupId + * @param int $targetGroupId * @param string|null $invitationOrganizationalInformation * @param string|null $invitationIntroduction * @param string|null $invitationPresentationText @@ -142,7 +142,7 @@ private function __construct( $contactPersonName = null, $contactPhone, $contactEmail, - $targetGroupId = null, + $targetGroupId, $invitationOrganizationalInformation = null, $invitationIntroduction = null, $invitationPresentationText = null, @@ -217,7 +217,7 @@ private function __construct( // target group - $this->targetGroup = $targetGroupId !== null ? TargetGroup::from($targetGroupId) : TargetGroup::unknown(); + $this->targetGroup = TargetGroup::from($targetGroupId); // invitation @@ -289,9 +289,9 @@ public static function fromResponseData(array $data) } return new self( - (int)$data['id'], + (int) $data['id'], $data['nazev'], - (isset($data['priloha_1']) && $data['priloha_1'] !== '') ? $data['priloha_1'] : null, + (isset($data['foto_hlavni']) && $data['foto_hlavni'] !== '') ? $data['foto_hlavni'] : null, \DateTimeImmutable::createFromFormat('Y-m-d', $data['od']), \DateTimeImmutable::createFromFormat('Y-m-d', $data['do']), $data['typ'], @@ -314,7 +314,7 @@ public static function fromResponseData(array $data) (isset($data['kontakt']) && $data['kontakt'] !== '') ? $data['kontakt'] : null, $data['kontakt_telefon'], $data['kontakt_email'], - (isset($data['prokoho_id']) && $data['prokoho_id'] !== '') ? ((int) $data['prokoho_id']) : null, + (int) $data['prokoho'], (isset($data['text_info']) && $data['text_info'] !== '') ? $data['text_info'] : null, (isset($data['text_uvod']) && $data['text_uvod'] !== '') ? $data['text_uvod'] : null, (isset($data['text_mnam']) && $data['text_mnam'] !== '') ? $data['text_mnam'] : null, diff --git a/src/Response/Event/TargetGroup.php b/src/Response/Event/TargetGroup.php index 44d350a..8cb76a3 100644 --- a/src/Response/Event/TargetGroup.php +++ b/src/Response/Event/TargetGroup.php @@ -2,11 +2,12 @@ namespace HnutiBrontosaurus\BisApiClient\Response\Event; +use HnutiBrontosaurus\BisApiClient\InvalidArgumentException; + final class TargetGroup { - const UNKNOWN = 0; const EVERYONE = 1; const ADULTS = 2; const CHILDREN = 3; @@ -24,14 +25,13 @@ final class TargetGroup private function __construct($id) { if ( ! \in_array($id, [ - self::UNKNOWN, self::EVERYONE, self::ADULTS, self::CHILDREN, self::FAMILIES, self::FIRST_TIME_ATTENDEES, ], true)) { - $id = self::UNKNOWN; // silent fallback + throw new InvalidArgumentException('Value `' . $id . '` is not of valid types for `id` parameter.'); } $this->id = $id; @@ -46,22 +46,6 @@ public static function from($id) return new self($id); } - /** - * @return self - */ - public static function unknown() - { - return new self(self::UNKNOWN); - } - - - /** - * @return bool - */ - public function isOfUnknownType() - { - return $this->id === self::UNKNOWN; - } /** * @return bool diff --git a/src/Response/Response.php b/src/Response/Response.php index ae5df08..9a2166e 100644 --- a/src/Response/Response.php +++ b/src/Response/Response.php @@ -10,6 +10,7 @@ final class Response const TAG_RESULT = 'result'; const TAG_RESULT_ATTRIBUTE_ERROR = 'error'; + const TAG_ATTRIBUTE_ID = 'id'; /** @var ResponseInterface */ @@ -37,13 +38,18 @@ private function parseDom(\DOMDocument $domDocument) $rowNodeList = $domFinder->query('*', $domDocument->getElementsByTagName(self::TAG_RESULT)->item(0)); foreach ($rowNodeList as $rowNode) { - \assert($rowNode instanceof \DOMNode); + \assert($rowNode instanceof \DOMElement); + /** @var array $row */ $row = []; foreach ($domFinder->query('*', $rowNode) as $node) { - \assert($node instanceof \DOMNode); + \assert($node instanceof \DOMElement); - $row[$node->nodeName] = $node->nodeValue; + // if there is an ID attribute, use this one a the value as it is numeric representation (thus more technically reliable) of element's content + $row[$node->nodeName] = $node->hasAttribute(self::TAG_ATTRIBUTE_ID) ? + $node->getAttribute(self::TAG_ATTRIBUTE_ID) + : + $node->nodeValue; } $this->data[] = $row; From 907ee4d0e5a5a6b1b64a020e98fd4569b273a520 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Tue, 7 May 2019 10:35:56 +0200 Subject: [PATCH 35/41] Response\Event: fixed work information --- src/Response/Event/Event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 252b192..4cf1398 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -319,7 +319,7 @@ public static function fromResponseData(array $data) (isset($data['text_uvod']) && $data['text_uvod'] !== '') ? $data['text_uvod'] : null, (isset($data['text_mnam']) && $data['text_mnam'] !== '') ? $data['text_mnam'] : null, $invitationPresentationPhotos, - (isset($data['prace']) && $data['prace'] !== '') ? $data['prace'] : null, + (isset($data['text_dobr']) && $data['text_dobr'] !== '') ? $data['text_dobr'] : null, (isset($data['sraz']) && $data['sraz'] !== '') ? $data['sraz'] : null, (isset($data['odpovedna']) && $data['odpovedna'] !== '') ? $data['odpovedna'] : null, (isset($data['pracovni_doba']) && $data['pracovni_doba'] !== '') ? ((int) $data['pracovni_doba']) : null, From 4edb0205ecb212b1c8e9194fad2099ca5136434d Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Tue, 7 May 2019 12:40:53 +0200 Subject: [PATCH 36/41] Client: moved parameters from URI to request body --- src/Client.php | 35 ++++++++++++++--------------------- src/Request/Adoption.php | 20 +------------------- src/Request/EventAttendee.php | 22 ++-------------------- 3 files changed, 17 insertions(+), 60 deletions(-) diff --git a/src/Client.php b/src/Client.php index 6ff66aa..02a0951 100644 --- a/src/Client.php +++ b/src/Client.php @@ -118,7 +118,7 @@ public function getEvents(EventParameters $params = null) public function addAttendeeToEvent(EventAttendee $eventAttendee) { $eventAttendee->setCredentials($this->username, $this->password); - $response = $this->httpClient->post($this->buildUrl($eventAttendee), $this->convertArrayToFormData($eventAttendee->getData())); + $response = $this->httpClient->send($this->createRequest($eventAttendee)); $this->checkForResponseContentType($response); @@ -165,7 +165,8 @@ public function getOrganizationalUnits(OrganizationalUnitParameters $params = nu public function saveRequestForAdoption(Adoption $adoption) { $adoption->setCredentials($this->username, $this->password); - $response = $this->httpClient->post($this->buildUrl($adoption), $this->convertArrayToFormData($adoption->getData())); + + $response = $this->httpClient->send($this->createRequest($adoption)); $this->checkForResponseContentType($response); @@ -186,10 +187,8 @@ private function processRequest(Parameters $requestParameters) { $requestParameters->setCredentials($this->username, $this->password); - $httpRequest = new Request('POST', $this->buildUrl($requestParameters)); - try { - $response = $this->httpClient->send($httpRequest); + $response = $this->httpClient->send($this->createRequest($requestParameters)); } catch (ClientException $e) { throw new NotFoundException('Bis client could not find the queried resource.', 0, $e); @@ -270,24 +269,18 @@ private function checkForResponseErrors(\DOMDocument $domDocument) } /** - * @param Parameters $params - * @return string - */ - private function buildUrl(Parameters $params) - { - $queryString = $params->getQueryString(); - return $this->url . ($queryString !== '' ? '?' . $queryString : ''); - } - - /** - * @param array $array - * @return array + * @return Request */ - private function convertArrayToFormData(array $array) + private function createRequest(Parameters $parameters) { - return [ - 'form_params' => $array, - ]; + return new Request( + 'POST', + $this->url, + [ + 'Content-Type' => 'application/x-www-form-urlencoded', + ], + \http_build_query($parameters->getAll()) + ); } } diff --git a/src/Request/Adoption.php b/src/Request/Adoption.php index e789b3e..6bf0a87 100644 --- a/src/Request/Adoption.php +++ b/src/Request/Adoption.php @@ -6,9 +6,6 @@ final class Adoption extends Parameters { - private $data = []; - - /** * @param int $amount * @param string $firstName @@ -37,12 +34,6 @@ public function __construct( ) { parent::__construct([ self::PARAM_QUERY => 'adopce', - ]); - - - // the rest goes to data array which will be sent in headers, not through URI - - $this->data = [ 'f_jmeno' => $firstName, 'f_prijmeni' => $lastName, 'f_ulice' => $streetAddress . ' ' . $streetNumber, @@ -54,16 +45,7 @@ public function __construct( 'f_clanek' => $preferredUnitOfTypeBase, 'f_rc' => $preferredUnitOfTypeRegional, 'f_castka' => $amount, - ]; - } - - - /** - * @return array - */ - public function getData() - { - return $this->data; + ]); } } diff --git a/src/Request/EventAttendee.php b/src/Request/EventAttendee.php index a0b15c6..e1e0bdd 100644 --- a/src/Request/EventAttendee.php +++ b/src/Request/EventAttendee.php @@ -6,9 +6,6 @@ final class EventAttendee extends Parameters { - private $data = []; - - /** * @param int $eventId * @param string $firstName @@ -31,12 +28,6 @@ public function __construct( ) { parent::__construct([ self::PARAM_QUERY => 'prihlaska', - ]); - - - // the rest goes to data array which will be sent in headers, not through URI - - $this->data = [ 'akce' => $eventId, 'jmeno' => $firstName, 'prijmeni' => $lastName, @@ -44,7 +35,7 @@ public function __construct( 'email' => $emailAddress, 'datum_narozeni' => $birthDate, 'poznamka' => $note, - ]; + ]); if (\count($questionAnswers) === 0) { @@ -54,18 +45,9 @@ public function __construct( // currently 3 questions are supported $i = 1; foreach ($questionAnswers as $questionAnswer) { - $this->data['add_info' . ($i >= 2 ? '_' . $i : '')] = $questionAnswer; // key syntax is `add_info` for first key and `add_info_X` for any other + $this->params['add_info' . ($i >= 2 ? '_' . $i : '')] = $questionAnswer; // key syntax is `add_info` for first key and `add_info_X` for any other $i++; } } - - /** - * @return array - */ - public function getData() - { - return $this->data; - } - } From a542bbd9d3b0e5a6c3a64fc4eef2cf0d03f228ce Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Tue, 28 May 2019 16:08:58 +0200 Subject: [PATCH 37/41] Response\Event\Invitation: extracted food into separate DTO --- src/Response/Event/Event.php | 6 +- src/Response/Event/Invitation/Food.php | 87 ++++++++++++++++++++ src/Response/Event/Invitation/Invitation.php | 21 ++--- 3 files changed, 95 insertions(+), 19 deletions(-) create mode 100644 src/Response/Event/Invitation/Food.php diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 4cf1398..3d6875b 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -263,10 +263,8 @@ public static function fromResponseData(array $data) } } - $food = (isset($data['strava']) && $data['strava'] !== '') ? $data['strava'] : null; - if ($food === 'můžete si vybrat') { // BIS API sends this string in case that user sets nothing - we want to get rid of it as it pretends to be a value when it is not - $food = null; - } + // BIS API returns "0", "1", "2" etc. for real options and "" when nothing is set + $food = (isset($data['strava']) && $data['strava'] !== '') ? (int) $data['strava'] : null; $invitationPresentationPhotos = []; if (isset($data['ochutnavka_1']) && $data['ochutnavka_1'] !== '') { diff --git a/src/Response/Event/Invitation/Food.php b/src/Response/Event/Invitation/Food.php new file mode 100644 index 0000000..2f9cf0a --- /dev/null +++ b/src/Response/Event/Invitation/Food.php @@ -0,0 +1,87 @@ +isListed = true; + + $this->isOfTypeChooseable = $food === self::CHOOSEABLE; + $this->isOfTypeVegetarian = $food === self::VEGETARIAN; + $this->isOfTypeNonVegetarian = $food === self::NON_VEGETARIAN; + } + } + + /** + * @param int|null $food + * @return self + */ + public static function from($food) + { + return new self($food); + } + + + /** + * @return bool + */ + public function isListed() + { + return $this->isListed; + } + + /** + * @return bool + */ + public function isOfTypeChooseable() + { + return $this->isOfTypeChooseable; + } + + /** + * @return bool + */ + public function isOfTypeVegetarian() + { + return $this->isOfTypeVegetarian; + } + + /** + * @return bool + */ + public function isOfTypeNonVegetarian() + { + return $this->isOfTypeNonVegetarian; + } + +} diff --git a/src/Response/Event/Invitation/Invitation.php b/src/Response/Event/Invitation/Invitation.php index 99d12db..f39d97c 100644 --- a/src/Response/Event/Invitation/Invitation.php +++ b/src/Response/Event/Invitation/Invitation.php @@ -15,7 +15,7 @@ final class Invitation /** @var string|null */ private $accommodation; - /** @var string|null */ + /** @var Food */ private $food; /** @var string */ @@ -32,7 +32,7 @@ final class Invitation * @param string $introduction * @param string $organizationalInformation * @param string|null $accommodation - * @param string|null $food + * @param int|null $food * @param string $workDescription * @param int|null $workHoursPerDay * @param string|null $presentationText @@ -54,9 +54,8 @@ private function __construct( if ($accommodation !== null) { $this->accommodation = $accommodation; } - if ($food !== null) { - $this->food = $food; - } + + $this->food = Food::from($food); $this->workDescription = $workDescription; @@ -77,7 +76,7 @@ private function __construct( * @param string $introduction * @param string $organizationalInformation * @param string|null $accommodation - * @param string|null $food + * @param int|null $food * @param string $workDescription * @param int|null $workHoursPerDay * @param string|null $presentationText @@ -140,15 +139,7 @@ public function getAccommodation() } /** - * @return bool - */ - public function isFoodListed() - { - return $this->food !== null; - } - - /** - * @return string|null + * @return Food */ public function getFood() { From 6a3e1906d88f95af84a21ab16141d8a9f85f0296 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Fri, 31 May 2019 10:36:31 +0200 Subject: [PATCH 38/41] Response\Event\Invitiation: presentation can contain text or photos or both --- src/Response/Event/Invitation/Invitation.php | 8 ++--- .../Event/Invitation/Presentation.php | 36 +++++++++++++------ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Response/Event/Invitation/Invitation.php b/src/Response/Event/Invitation/Invitation.php index f39d97c..b936b3c 100644 --- a/src/Response/Event/Invitation/Invitation.php +++ b/src/Response/Event/Invitation/Invitation.php @@ -63,12 +63,8 @@ private function __construct( $this->workHoursPerDay = $workHoursPerDay; } - if ($presentationText !== null) { - $this->presentation = Presentation::from($presentationText); - - if (\count($presentationPhotos) > 0) { - $this->presentation->addPhotos($presentationPhotos); - } + if ($presentationText !== null || \count($presentationPhotos) > 0) { + $this->presentation = Presentation::from($presentationText, $presentationPhotos); } } diff --git a/src/Response/Event/Invitation/Presentation.php b/src/Response/Event/Invitation/Presentation.php index ee5645a..f85a72c 100644 --- a/src/Response/Event/Invitation/Presentation.php +++ b/src/Response/Event/Invitation/Presentation.php @@ -6,7 +6,7 @@ final class Presentation { - /** @var string */ + /** @var string|null */ private $text; /** @var bool */ @@ -17,28 +17,36 @@ final class Presentation /** - * @param $text + * @param string|null $text + * @param string[] $photoPaths */ - private function __construct($text) + private function __construct($text, array $photoPaths) { - $this->text = $text; + if ($text !== null) { + $this->text = $text; + } + + if (\count($photoPaths) > 0) { + $this->addPhotos($photoPaths); + } } /** - * @param $text + * @param string|null $text + * @param string[] $photoPaths * @return self */ - public static function from($text) + public static function from($text = null, array $photoPaths) { - return new self($text); + return new self($text, $photoPaths); } /** * @param string $photoPath * @return self */ - public function addPhoto($photoPath) + private function addPhoto($photoPath) { $this->hasAnyPhotos = true; $this->photos[] = Photo::from($photoPath); @@ -50,7 +58,7 @@ public function addPhoto($photoPath) * @param string[] $photoPaths * @return self */ - public function addPhotos(array $photoPaths) + private function addPhotos(array $photoPaths) { foreach ($photoPaths as $photoPath) { $this->addPhoto($photoPath); @@ -61,7 +69,15 @@ public function addPhotos(array $photoPaths) /** - * @return string + * @return bool + */ + public function hasText() + { + return $this->text !== null; + } + + /** + * @return string|null */ public function getText() { From 7610bc7c99cd9bf2b4c69cdb4e6a555fd15c613a Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Thu, 6 Jun 2019 08:13:32 +0200 Subject: [PATCH 39/41] Response\Event\Program: not nullable, handled null state properly, added more is*() methods --- src/Response/Event/Event.php | 14 ++------ src/Response/Event/Program.php | 61 ++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/Response/Event/Event.php b/src/Response/Event/Event.php index 3d6875b..f19ca55 100644 --- a/src/Response/Event/Event.php +++ b/src/Response/Event/Event.php @@ -33,7 +33,7 @@ final class Event /** @var string */ private $type; - /** @var Program|null */ + /** @var Program */ private $program; /** @var Place */ @@ -180,15 +180,7 @@ private function __construct( // program - if ($programSlug !== null && $programName !== null) { - try { - $this->program = Program::from($programSlug, $programName); - - } catch (InvalidArgumentException $e) { - // if exception, program remains null - - } - } + $this->program = Program::from($programSlug, $programName); // registration @@ -387,7 +379,7 @@ public function getType() } /** - * @return Program|null + * @return Program */ public function getProgram() { diff --git a/src/Response/Event/Program.php b/src/Response/Event/Program.php index 4aae850..91b7c83 100644 --- a/src/Response/Event/Program.php +++ b/src/Response/Event/Program.php @@ -20,18 +20,22 @@ final class Program /** @var string */ private $slug; - /** @var string */ + /** @var string|null */ private $name; /** - * @param string $slug - * @param string $name + * @param string|null $slug + * @param string|null $name * @throws InvalidArgumentException */ - private function __construct($slug, $name) + private function __construct($slug = null, $name = null) { - if (!\in_array($slug, [ + if ($slug === null) { + $slug = self::PROGRAM_NONE; + } + + if ( ! \in_array($slug, [ self::PROGRAM_NONE, self::PROGRAM_NATURE, self::PROGRAM_SIGHTS, @@ -40,19 +44,22 @@ private function __construct($slug, $name) self::PROGRAM_PSB, self::PROGRAM_EDUCATION, ], true)) { - throw new InvalidArgumentException('Value `' . $slug . '` is not of valid types for `slug` parameter.'); + $slug = self::PROGRAM_NONE; } $this->slug = $slug; - $this->name = $name; + + if ($name !== null) { + $this->name = $name; + } } /** - * @param string $slug - * @param string $name + * @param string|null $slug + * @param string|null $name * @return self */ - public static function from($slug, $name) + public static function from($slug = null, $name = null) { return new self($slug, $name); } @@ -75,6 +82,14 @@ public function getName() } + /** + * @return bool + */ + public function isNotSelected() + { + return $this->slug === self::PROGRAM_NONE; + } + /** * @return bool */ @@ -94,9 +109,33 @@ public function isOfTypeSights() /** * @return bool */ - public function isOfTypeHoliday() + public function isOfTypeBrdo() + { + return $this->slug === self::PROGRAM_BRDO; + } + + /** + * @return bool + */ + public function isOfTypeEkostan() + { + return $this->slug === self::PROGRAM_EKOSTAN; + } + + /** + * @return bool + */ + public function isOfTypePsb() { return $this->slug === self::PROGRAM_PSB; } + /** + * @return bool + */ + public function isOfTypeEducation() + { + return $this->slug === self::PROGRAM_EDUCATION; + } + } From 8e2fdecd14ccf23a1629aa5dd7e0a8c80b70cd55 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Wed, 5 Feb 2020 17:29:13 +0100 Subject: [PATCH 40/41] EventParameters: updated values to be up-to-date with current BIS API --- src/Request/EventParameters.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index bba130a..32539f9 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -8,12 +8,10 @@ final class EventParameters extends Parameters { - const PARAM_DISPLAY_ALREADY_STARTED_KEY = 'aktualni'; - const PARAM_DISPLAY_ALREADY_STARTED_NO = 'od'; - const PARAM_DISPLAY_ALREADY_STARTED_YES = 'do'; + const PARAM_DISPLAY_ALREADY_STARTED_KEY = 'probihajici'; // for default just omit this parameter + const PARAM_DISPLAY_ALREADY_STARTED_VALUE = ''; // whatever value - const PARAM_ORDER_BY_KEY = 'razeni'; - const PARAM_ORDER_BY_START_DATE = 'od'; + const PARAM_ORDER_BY_KEY = 'sort'; // for default sorting just omit this parameter const PARAM_ORDER_BY_END_DATE = 'do'; @@ -21,7 +19,7 @@ public function __construct() { parent::__construct([ self::PARAM_QUERY => 'akce', - self::PARAM_DISPLAY_ALREADY_STARTED_KEY => self::PARAM_DISPLAY_ALREADY_STARTED_YES, + self::PARAM_DISPLAY_ALREADY_STARTED_KEY => self::PARAM_DISPLAY_ALREADY_STARTED_VALUE, self::PARAM_ORDER_BY_KEY => self::PARAM_ORDER_BY_END_DATE, ]); } @@ -105,7 +103,7 @@ public function setFilter($filter) const TYPE_RESIDENTIAL_LEARNING_PROGRAM = 'pobyt'; // pobytový výukový program const TYPE_CLUB_MEETUP = 'klub'; // klub - setkání - const TYPE_CLUB_TALK = 'klub-vzdel'; // klub - přednáška + const TYPE_CLUB_TALK = 'klub-predn'; // klub - přednáška const TYPE_FOR_PUBLIC = 'verejnost'; // akce pro veřejnost const TYPE_EKOSTAN = 'ekostan'; const TYPE_EXHIBITION = 'vystava'; @@ -290,7 +288,7 @@ public function setYear($year) */ public function hideTheseAlreadyStarted() { - $this->params[self::PARAM_DISPLAY_ALREADY_STARTED_KEY] = self::PARAM_DISPLAY_ALREADY_STARTED_NO; + unset($this->params[self::PARAM_DISPLAY_ALREADY_STARTED_KEY]); return $this; } @@ -302,7 +300,7 @@ public function hideTheseAlreadyStarted() */ public function orderByStartDate() { - $this->params[self::PARAM_ORDER_BY_KEY] = self::PARAM_ORDER_BY_START_DATE; + unset($this->params[self::PARAM_ORDER_BY_KEY]); return $this; } From eb3a96593a367e2f8ca8d7fb738571f069d8ae28 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Wed, 5 Feb 2020 17:29:23 +0100 Subject: [PATCH 41/41] Updated docs URL --- src/Request/EventParameters.php | 2 +- src/Request/Parameters.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Request/EventParameters.php b/src/Request/EventParameters.php index 32539f9..3046bb7 100644 --- a/src/Request/EventParameters.php +++ b/src/Request/EventParameters.php @@ -46,7 +46,7 @@ public function setId($id) /** * This parameter serves as combinator for multiple conditions, which can not be achieved with concatenating type, program, target group or any other available parameters. * For example you can not make an union among different parameters. Let's say you want all events which are of type=ohb or of program=brdo. This is not possible with API parameters. - * Thus you can take advantage of preset filters which are documented here: https://bis.brontosaurus.cz/myr.html + * Thus you can take advantage of preset filters which are documented here: https://bis.brontosaurus.cz/myr.php * * Beside standard constant usage as a parameter, you can pass bitwise operation argument, e.g. `EventParameters::FILTER_WEEKEND|EventParameters::FILTER_CAMP`. * diff --git a/src/Request/Parameters.php b/src/Request/Parameters.php index 0df7395..d8c63d8 100644 --- a/src/Request/Parameters.php +++ b/src/Request/Parameters.php @@ -1,7 +1,7 @@