From 8abbac27e9dffd3580813145bd7cdebe2548b3db Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Thu, 24 Feb 2022 14:18:16 +0100 Subject: [PATCH] add support for creating and updating events with objectCategories (#46) --- src/Events/Event.php | 5 +++++ src/Events/Events.php | 12 ++++++++++-- tests/Events/CreateEventTest.php | 9 +++++++++ tests/Events/UpdateEventTest.php | 22 ++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Events/Event.php b/src/Events/Event.php index 3dba178..4918942 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -74,6 +74,11 @@ class Event */ public $isEventInSeason; + /** + * @var array + */ + public $objectCategories; + public function isSeason() { return false; } diff --git a/src/Events/Events.php b/src/Events/Events.php index 6df9b0f..9ad7328 100644 --- a/src/Events/Events.php +++ b/src/Events/Events.php @@ -24,7 +24,7 @@ public function __construct(Client $client) $this->client = $client; } - public function create(string $chartKey, string $eventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null): Event + public function create(string $chartKey, string $eventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null, array $objectCategories = null): Event { $request = new stdClass(); @@ -42,6 +42,10 @@ public function create(string $chartKey, string $eventKey = null, TableBookingCo $request->socialDistancingRulesetKey = $socialDistancingRulesetKey; } + if ($objectCategories !== null) { + $request->objectCategories = $objectCategories; + } + $res = $this->client->post('/events', ['json' => $request]); $json = \GuzzleHttp\json_decode($res->getBody()); $mapper = SeatsioJsonMapper::create(); @@ -90,7 +94,7 @@ public function retrieve(string $eventKey): Event return $mapper->map($json, new Event()); } - public function update(string $eventKey, string $chartKey = null, string $newEventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null): void + public function update(string $eventKey, string $chartKey = null, string $newEventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null, $objectCategories = null): void { $request = new stdClass(); @@ -110,6 +114,10 @@ public function update(string $eventKey, string $chartKey = null, string $newEve $request->socialDistancingRulesetKey = $socialDistancingRulesetKey; } + if ($objectCategories !== null) { + $request->objectCategories = $objectCategories; + } + $this->client->post(UriTemplate::expand('/events/{key}', array("key" => $eventKey)), ['json' => $request]); } diff --git a/tests/Events/CreateEventTest.php b/tests/Events/CreateEventTest.php index 1c14db2..9ce7fb2 100644 --- a/tests/Events/CreateEventTest.php +++ b/tests/Events/CreateEventTest.php @@ -64,4 +64,13 @@ public function testSocialDistancingRulesetKeyCanBePassedIn() self::assertEquals("ruleset1", $event->socialDistancingRulesetKey); } + public function testObjectCategoriesCanBePassedIn() + { + $chartKey = $this->createTestChart(); + + $event = $this->seatsioClient->events->create($chartKey, null, null, null, ["A-1" => 10]); + + self::assertEquals(["A-1" => 10], $event->objectCategories); + } + } diff --git a/tests/Events/UpdateEventTest.php b/tests/Events/UpdateEventTest.php index f265e9f..f422e59 100644 --- a/tests/Events/UpdateEventTest.php +++ b/tests/Events/UpdateEventTest.php @@ -4,6 +4,7 @@ use Seatsio\Charts\SocialDistancingRuleset; use Seatsio\SeatsioClientTest; +use stdClass; class UpdateEventTest extends SeatsioClientTest { @@ -75,4 +76,25 @@ public function testRemoveSocialDistancingRulesetKey() self::assertNull($retrievedEvent->socialDistancingRulesetKey); } + public function testUpdateObjectCategories() + { + $chartKey = $this->createTestChart(); + $event = $this->seatsioClient->events->create($chartKey, null, null, null, ["A-1" => 9]); + + $this->seatsioClient->events->update($event->key, null, null, null, null, ["A-2" => 10]); + + $retrievedEvent = $this->seatsioClient->events->retrieve($event->key); + self::assertEquals(["A-2" => 10], $retrievedEvent->objectCategories); + } + + public function testRemoveObjectCategories() + { + $chartKey = $this->createTestChart(); + $event = $this->seatsioClient->events->create($chartKey, null, null, null, ["A-1" => 9]); + + $this->seatsioClient->events->update($event->key, null, null, null, null, new stdClass()); + + $retrievedEvent = $this->seatsioClient->events->retrieve($event->key); + self::assertNull($retrievedEvent->objectCategories); + } }