From ea204080f8645b54afe34cc141e7e4b2db1d4fa0 Mon Sep 17 00:00:00 2001 From: mroloux Date: Mon, 15 Jul 2024 13:42:00 +0200 Subject: [PATCH] Zones can be expanded --- src/Charts/Chart.php | 4 ++++ src/Charts/ChartListParams.php | 18 +++++++++++++++++- src/Charts/Zone.php | 27 +++++++++++++++++++++++++++ tests/Charts/ListAllChartsTest.php | 15 +++++++++------ tests/Charts/RetrieveChartTest.php | 10 ++++++++++ 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 src/Charts/Zone.php diff --git a/src/Charts/Chart.php b/src/Charts/Chart.php index 0044cae..18cdbd9 100644 --- a/src/Charts/Chart.php +++ b/src/Charts/Chart.php @@ -48,4 +48,8 @@ class Chart * @var string */ public $venueType; + /** + * @var \Seatsio\Charts\Zone[] + */ + public $zones; } diff --git a/src/Charts/ChartListParams.php b/src/Charts/ChartListParams.php index 3fbba05..a82451a 100644 --- a/src/Charts/ChartListParams.php +++ b/src/Charts/ChartListParams.php @@ -31,13 +31,19 @@ class ChartListParams */ public $expandVenueType; - public function __construct(string $filter = null, string $tag = null, bool $expandEvents = false, bool $withExpandValidation = false, bool $withExpandVenueType = false) + /** + * @var boolean + */ + public $expandZones; + + public function __construct(string $filter = null, string $tag = null, bool $expandEvents = false, bool $withExpandValidation = false, bool $withExpandVenueType = false, bool $withExpandZones = false) { $this->filter = $filter; $this->tag = $tag; $this->expandEvents = $expandEvents; $this->expandValidation = $withExpandValidation; $this->expandVenueType = $withExpandVenueType; + $this->expandZones = $withExpandZones; } public function withFilter(string $filter): self @@ -78,6 +84,12 @@ public function withExpandVenueType(bool $expandVenueType): self return $this; } + public function withExpandZones(bool $expandZones): self + { + $this->expandZones = $expandZones; + return $this; + } + public function toArray(): array { $result = []; @@ -111,6 +123,10 @@ private function expandParams() $result[] = "venueType"; } + if ($this->expandZones) { + $result[] = "zones"; + } + return $result; } } diff --git a/src/Charts/Zone.php b/src/Charts/Zone.php new file mode 100644 index 0000000..45f351f --- /dev/null +++ b/src/Charts/Zone.php @@ -0,0 +1,27 @@ +key = $key; + $this->label = $label; + } + + +} diff --git a/tests/Charts/ListAllChartsTest.php b/tests/Charts/ListAllChartsTest.php index fda1900..e081233 100644 --- a/tests/Charts/ListAllChartsTest.php +++ b/tests/Charts/ListAllChartsTest.php @@ -84,32 +84,35 @@ public function testTagAndFilter() public function testAllFieldsExpanded() { - $chart = $this->seatsioClient->charts->create(); - $event1 = $this->seatsioClient->events->create($chart->key); - $event2 = $this->seatsioClient->events->create($chart->key); + $chart = $this->createTestChartWithZones(); + $event1 = $this->seatsioClient->events->create($chart); + $event2 = $this->seatsioClient->events->create($chart); $params = (new ChartListParams()) ->withExpandEvents(true) ->withExpandValidation(true) - ->withExpandVenueType(true); + ->withExpandVenueType(true) + ->withExpandZones(true); $charts = $this->seatsioClient->charts->listAll($params); $eventIds = map($charts->current()->events, function ($event) { return $event->id; }); self::assertEquals([$event2->id, $event1->id], array_values($eventIds)); - self::assertEquals("MIXED", $charts->current()->venueType); + self::assertEquals("ZONES", $charts->current()->venueType); + self::assertEquals([new Zone("finishline", "Finish Line"), new Zone("midtrack", "Mid Track")], $charts->current()->zones); self::assertNotNull($charts->current()->validation); } public function testNoFieldsExpanded() { - $chart = $this->seatsioClient->charts->create(); + $this->createTestChartWithZones(); $charts = $this->seatsioClient->charts->listAll((new ChartListParams())->withExpandEvents(true)); self::assertEmpty($charts->current()->events); self::assertNull($charts->current()->venueType); self::assertNull($charts->current()->validation); + self::assertNull($charts->current()->zones); } public function testWithValidation() diff --git a/tests/Charts/RetrieveChartTest.php b/tests/Charts/RetrieveChartTest.php index d8c551c..6a2065d 100644 --- a/tests/Charts/RetrieveChartTest.php +++ b/tests/Charts/RetrieveChartTest.php @@ -24,6 +24,16 @@ public function test() self::assertEquals(['tag1'], $retrievedChart->tags); self::assertFalse($retrievedChart->archived); self::assertNull($retrievedChart->events); + self::assertNull($retrievedChart->zones); + } + + public function zones() + { + $chart = $this->createTestChartWithZones(); + + $retrievedChart = $this->seatsioClient->charts->retrieve($chart); + + self::assertEquals([new Zone("finishline", "Finish Line"), new Zone("midtrack", "Mid Track")], $retrievedChart->zones); } public function testRetrieveWithEvents()