Skip to content

Commit

Permalink
Zones can be expanded
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jul 15, 2024
1 parent bd704df commit ea20408
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Charts/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ class Chart
* @var string
*/
public $venueType;
/**
* @var \Seatsio\Charts\Zone[]
*/
public $zones;
}
18 changes: 17 additions & 1 deletion src/Charts/ChartListParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -111,6 +123,10 @@ private function expandParams()
$result[] = "venueType";
}

if ($this->expandZones) {
$result[] = "zones";
}

return $result;
}
}
27 changes: 27 additions & 0 deletions src/Charts/Zone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Seatsio\Charts;

class Zone
{
/**
* @var string
*/
public $key;
/**
* @var string
*/
public $label;

/**
* @param string $key
* @param string $label
*/
public function __construct(string $key, string $label)
{
$this->key = $key;
$this->label = $label;
}


}
15 changes: 9 additions & 6 deletions tests/Charts/ListAllChartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions tests/Charts/RetrieveChartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ea20408

Please sign in to comment.