From bbfc4eda39cb70abe878f1793ff1bd15912ac10e Mon Sep 17 00:00:00 2001 From: mroloux Date: Tue, 18 Feb 2020 09:01:46 +0100 Subject: [PATCH] Added support for changing object status in batch --- src/Events/Events.php | 35 ++++++++++++++ src/Events/StatusChangeRequest.php | 46 +++++++++++++++++++ .../Events/ChangeObjectStatusInBatchTest.php | 31 +++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 src/Events/StatusChangeRequest.php create mode 100644 tests/Events/ChangeObjectStatusInBatchTest.php diff --git a/src/Events/Events.php b/src/Events/Events.php index 7b63c50..228c9b4 100644 --- a/src/Events/Events.php +++ b/src/Events/Events.php @@ -316,6 +316,41 @@ public function changeObjectStatus($eventKeyOrKeys, $objectOrObjects, $status, $ return $mapper->map($json, new ChangeObjectStatusResult()); } + /** + * @param $statusChangeRequests StatusChangeRequest[] + * @return ChangeObjectStatusResult[] + */ + public function changeObjectStatusInBatch($statusChangeRequests) { + $request = new \stdClass(); + $request->statusChanges = \Functional\map($statusChangeRequests, function($statusChangeRequest) { + return $this->serializeStatusChangeRequest($statusChangeRequest); + }); + $res = $this->client->post( + '/events/actions/change-object-status', + ['json' => $request, 'query' => ['expand' => 'objects']] + ); + $json = \GuzzleHttp\json_decode($res->getBody()); + $mapper = SeatsioJsonMapper::create(); + return $mapper->mapArray($json->results, array(), ChangeObjectStatusResult::class); + } + + private function serializeStatusChangeRequest($statusChangeRequest) { + $request = new \stdClass(); + $request->event = $statusChangeRequest->event; + $request->objects = self::normalizeObjects($statusChangeRequest->objectOrObjects); + $request->status = $statusChangeRequest->status; + if ($statusChangeRequest->holdToken !== null) { + $request->holdToken = $statusChangeRequest->holdToken; + } + if ($statusChangeRequest->orderId !== null) { + $request->orderId = $statusChangeRequest->orderId; + } + if ($statusChangeRequest->keepExtraData !== null) { + $request->keepExtraData = $statusChangeRequest->keepExtraData; + } + return $request; + } + /** * @param $eventKeyOrKeys string|string[] * @param $objectOrObjects mixed diff --git a/src/Events/StatusChangeRequest.php b/src/Events/StatusChangeRequest.php new file mode 100644 index 0000000..8284bb4 --- /dev/null +++ b/src/Events/StatusChangeRequest.php @@ -0,0 +1,46 @@ +event = $event; + $this->objectOrObjects = $objectOrObjects; + $this->status = $status; + $this->holdToken = $holdToken; + $this->orderId = $orderId; + $this->keepExtraData = $keepExtraData; + } +} diff --git a/tests/Events/ChangeObjectStatusInBatchTest.php b/tests/Events/ChangeObjectStatusInBatchTest.php new file mode 100644 index 0000000..6d65866 --- /dev/null +++ b/tests/Events/ChangeObjectStatusInBatchTest.php @@ -0,0 +1,31 @@ +createTestChart(); + $chartKey2 = $this->createTestChart(); + $event1 = $this->seatsioClient->events->create($chartKey1); + $event2 = $this->seatsioClient->events->create($chartKey2); + + $response = $this->seatsioClient->events->changeObjectStatusInBatch([ + new StatusChangeRequest($event1->key, "A-1", "lolzor"), + new StatusChangeRequest($event2->key, "A-2", "lolzor") + ]); + + self::assertEquals('lolzor', $response[0]->objects['A-1']->status); + $objectStatus1 = $this->seatsioClient->events->retrieveObjectStatus($event1->key, "A-1"); + self::assertEquals("lolzor", $objectStatus1->status); + + self::assertEquals('lolzor', $response[1]->objects['A-2']->status); + $objectStatus2 = $this->seatsioClient->events->retrieveObjectStatus($event2->key, "A-2"); + self::assertEquals("lolzor", $objectStatus2->status); + } + +}