From 3eddb321afd25f2a79c785b9444c4f95fc89f996 Mon Sep 17 00:00:00 2001 From: mroloux Date: Wed, 3 Oct 2018 11:05:09 +0200 Subject: [PATCH] Changing the status of an object with a numeric labels works fine now. --- src/Events/BestAvailableObjects.php | 17 +---------------- src/Events/ChangeObjectStatusResult.php | 17 +---------------- src/Events/Events.php | 6 ++++-- src/SeatsioJsonMapper.php | 10 ++++++++-- ...ChangeObjectStatusForMultipleObjectsTest.php | 4 ++-- tests/Events/ChangeObjectStatusTest.php | 4 ++-- tests/sampleChart.json | 2 +- 7 files changed, 19 insertions(+), 41 deletions(-) diff --git a/src/Events/BestAvailableObjects.php b/src/Events/BestAvailableObjects.php index d5781b0..17c4435 100644 --- a/src/Events/BestAvailableObjects.php +++ b/src/Events/BestAvailableObjects.php @@ -2,8 +2,6 @@ namespace Seatsio\Events; -use Seatsio\SeatsioJsonMapper; - class BestAvailableObjects { /** @@ -11,7 +9,7 @@ class BestAvailableObjects */ public $objects; /** - * @var array + * @var array[Labels] */ public $labels; /** @@ -19,17 +17,4 @@ class BestAvailableObjects */ public $nextToEachOther; - /** - * @param $json - * @return BestAvailableObjects - */ - static function fromJson($json) - { - $mapper = SeatsioJsonMapper::create(); - $result = $mapper->map($json, new BestAvailableObjects()); - array_walk($result->labels, function ($labels, $id) use ($mapper, $result) { - $result->labels[$id] = $mapper->map($labels, new Labels()); - }); - return $result; - } } \ No newline at end of file diff --git a/src/Events/ChangeObjectStatusResult.php b/src/Events/ChangeObjectStatusResult.php index da3883c..1f220ca 100644 --- a/src/Events/ChangeObjectStatusResult.php +++ b/src/Events/ChangeObjectStatusResult.php @@ -2,26 +2,11 @@ namespace Seatsio\Events; -use Seatsio\SeatsioJsonMapper; - class ChangeObjectStatusResult { /** - * @var array + * @var array[Labels] */ var $labels; - /** - * @param $json - * @return ChangeObjectStatusResult - */ - static function fromJson($json) - { - $mapper = SeatsioJsonMapper::create(); - $result = $mapper->map($json, new ChangeObjectStatusResult()); - array_walk($result->labels, function ($labels, $id) use ($mapper, $result) { - $result->labels[$id] = $mapper->map($labels, new Labels()); - }); - return $result; - } } \ No newline at end of file diff --git a/src/Events/Events.php b/src/Events/Events.php index 51c17bf..257edca 100644 --- a/src/Events/Events.php +++ b/src/Events/Events.php @@ -261,7 +261,8 @@ public function changeObjectStatus($eventKeyOrKeys, $objectOrObjects, $status, $ ['json' => $request, 'query' => ['expand' => 'labels']] ); $json = \GuzzleHttp\json_decode($res->getBody()); - return ChangeObjectStatusResult::fromJson($json); + $mapper = SeatsioJsonMapper::create(); + return $mapper->map($json, new ChangeObjectStatusResult()); } /** @@ -360,7 +361,8 @@ public function changeBestAvailableObjectStatus($eventKey, $number, $status, $ca ['json' => $request] ); $json = \GuzzleHttp\json_decode($res->getBody()); - return BestAvailableObjects::fromJson($json); + $mapper = SeatsioJsonMapper::create(); + return $mapper->map($json, new BestAvailableObjects()); } private static function normalizeObjects($objectOrObjects) diff --git a/src/SeatsioJsonMapper.php b/src/SeatsioJsonMapper.php index 29e6bb9..772e73d 100644 --- a/src/SeatsioJsonMapper.php +++ b/src/SeatsioJsonMapper.php @@ -4,15 +4,21 @@ use JsonMapper; -class SeatsioJsonMapper +class SeatsioJsonMapper extends JsonMapper { /** * @return JsonMapper */ public static function create() { - $mapper = new JsonMapper(); + $mapper = new SeatsioJsonMapper(); $mapper->classMap["\DateTime"] = JsonDateTime::class; return $mapper; } + + protected function getSafeName($name) + { + // avoid object labels such as B-4 being converted into B4 + return $name; + } } \ No newline at end of file diff --git a/tests/Events/ChangeObjectStatusForMultipleObjectsTest.php b/tests/Events/ChangeObjectStatusForMultipleObjectsTest.php index 3688046..d4f9dda 100644 --- a/tests/Events/ChangeObjectStatusForMultipleObjectsTest.php +++ b/tests/Events/ChangeObjectStatusForMultipleObjectsTest.php @@ -94,7 +94,7 @@ public function testQuantity() $event = $this->seatsioClient->events->create($chartKey); $objects = [ (new ObjectProperties("GA1"))->setQuantity(5), - (new ObjectProperties("GA2"))->setQuantity(10) + (new ObjectProperties("34"))->setQuantity(10) ]; $this->seatsioClient->events->changeObjectStatus($event->key, $objects, "lolzor"); @@ -102,7 +102,7 @@ public function testQuantity() $status1 = $this->seatsioClient->events->retrieveObjectStatus($event->key, "GA1"); self::assertEquals(5, $status1->quantity); - $status2 = $this->seatsioClient->events->retrieveObjectStatus($event->key, "GA2"); + $status2 = $this->seatsioClient->events->retrieveObjectStatus($event->key, "34"); self::assertEquals(10, $status2->quantity); } diff --git a/tests/Events/ChangeObjectStatusTest.php b/tests/Events/ChangeObjectStatusTest.php index 296d87f..a5765e4 100644 --- a/tests/Events/ChangeObjectStatusTest.php +++ b/tests/Events/ChangeObjectStatusTest.php @@ -48,10 +48,10 @@ public function testGA() $chartKey = $this->createTestChart(); $event = $this->seatsioClient->events->create($chartKey); - $result = $this->seatsioClient->events->changeObjectStatus($event->key, "GA1", "lolzor"); + $result = $this->seatsioClient->events->changeObjectStatus($event->key, "34", "lolzor"); self::assertEquals([ - "GA1" => someLabels("GA1", "generalAdmission") + "34" => someLabels("34", "generalAdmission") ], $result->labels); } diff --git a/tests/sampleChart.json b/tests/sampleChart.json index efe0992..2e01add 100644 --- a/tests/sampleChart.json +++ b/tests/sampleChart.json @@ -421,7 +421,7 @@ "categoryLabel": "Cat2", "categoryKey": 10, "capacity": 100, - "label": "GA2", + "label": "34", "labelSize": 24, "labelShown": true, "labelHorizontalOffset": 0,