From b3431a20aeb0c56238aa094f3acaae05362c351e Mon Sep 17 00:00:00 2001 From: mroloux Date: Thu, 29 Mar 2018 11:27:45 +0200 Subject: [PATCH] Added summary report calls --- src/Events/Reports.php | 58 ++++++++++++----- tests/Events/EventReportSummaryTest.php | 84 +++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 tests/Events/EventReportSummaryTest.php diff --git a/src/Events/Reports.php b/src/Events/Reports.php index 2dff7a5..fbeeb31 100644 --- a/src/Events/Reports.php +++ b/src/Events/Reports.php @@ -29,6 +29,17 @@ public function byStatus($eventKey, $status = null) return $this->mapMultiValuedReport($json, $status); } + /** + * @param $eventKey string + * @return array + */ + public function summaryByStatus($eventKey) + { + $res = $this->client->get(self::summaryReportUrl('byStatus', $eventKey)); + $json = \GuzzleHttp\json_decode($res->getBody(), true); + return $json; + } + /** * @param $eventKey string * @param $categoryLabel string @@ -41,6 +52,16 @@ public function byCategoryLabel($eventKey, $categoryLabel = null) return $this->mapMultiValuedReport($json, $categoryLabel); } + /** + * @param $eventKey string + * @return array + */ + public function summaryByCategoryLabel($eventKey) + { + $res = $this->client->get(self::summaryReportUrl('byCategoryLabel', $eventKey)); + return \GuzzleHttp\json_decode($res->getBody(), true); + } + /** * @param $eventKey string * @param $categoryKey string @@ -53,6 +74,16 @@ public function byCategoryKey($eventKey, $categoryKey = null) return $this->mapMultiValuedReport($json, $categoryKey); } + /** + * @param $eventKey string + * @return array + */ + public function summaryByCategoryKey($eventKey) + { + $res = $this->client->get(self::summaryReportUrl('byCategoryKey', $eventKey)); + return \GuzzleHttp\json_decode($res->getBody(), true); + } + /** * @param $eventKey string * @param $label string @@ -90,21 +121,13 @@ public function bySection($eventKey, $section = null) } /** - * @param $json mixed - * @param $filter string + * @param $eventKey string * @return array */ - private static function mapMultiValuedReport($json, $filter) + public function summaryBySection($eventKey) { - $mapper = SeatsioJsonMapper::create(); - $result = []; - foreach ($json as $status => $reportItems) { - $result[$status] = $mapper->mapArray($reportItems, array(), EventReportItem::class); - } - if ($filter === null) { - return $result; - } - return $result[$filter]; + $res = $this->client->get(self::summaryReportUrl('bySection', $eventKey)); + return \GuzzleHttp\json_decode($res->getBody(), true); } /** @@ -112,12 +135,12 @@ private static function mapMultiValuedReport($json, $filter) * @param $filter string * @return array */ - private static function mapSingleValuedReport($json, $filter) + private static function mapMultiValuedReport($json, $filter) { $mapper = SeatsioJsonMapper::create(); $result = []; - foreach ($json as $status => $reportItem) { - $result[$status] = $mapper->map($reportItem, new EventReportItem()); + foreach ($json as $status => $reportItems) { + $result[$status] = $mapper->mapArray($reportItems, array(), EventReportItem::class); } if ($filter === null) { return $result; @@ -133,4 +156,9 @@ private static function reportUrl($reportType, $eventKey, $filter) return \GuzzleHttp\uri_template('/reports/events/{key}/{reportType}/{filter}', array("key" => $eventKey, "reportType" => $reportType, "filter" => $filter)); } + private static function summaryReportUrl($reportType, $eventKey) + { + return \GuzzleHttp\uri_template('/reports/events/{key}/{reportType}/summary', array("key" => $eventKey, "reportType" => $reportType)); + } + } \ No newline at end of file diff --git a/tests/Events/EventReportSummaryTest.php b/tests/Events/EventReportSummaryTest.php new file mode 100644 index 0000000..8a4fae1 --- /dev/null +++ b/tests/Events/EventReportSummaryTest.php @@ -0,0 +1,84 @@ +createTestChart(); + $event = $this->seatsioClient->events()->create($chartKey); + $this->seatsioClient->events()->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1"), null, "order1"); + + $report = $this->seatsioClient->events()->reports()->summaryByStatus($event->key); + + self::assertEquals(1, $report[ObjectStatus::$BOOKED]['count']); + self::assertEquals(1, $report[ObjectStatus::$BOOKED]['bySection']['NO_SECTION']); + self::assertEquals(1, $report[ObjectStatus::$BOOKED]['byCategoryKey']['9']); + self::assertEquals(1, $report[ObjectStatus::$BOOKED]['byCategoryLabel']['Cat1']); + + self::assertEquals(33, $report[ObjectStatus::$FREE]['count']); + self::assertEquals(33, $report[ObjectStatus::$FREE]['bySection']['NO_SECTION']); + self::assertEquals(16, $report[ObjectStatus::$FREE]['byCategoryKey']['9']); + self::assertEquals(17, $report[ObjectStatus::$FREE]['byCategoryKey']['10']); + self::assertEquals(16, $report[ObjectStatus::$FREE]['byCategoryLabel']['Cat1']); + self::assertEquals(17, $report[ObjectStatus::$FREE]['byCategoryLabel']['Cat2']); + } + + public function testSummaryByCategoryKey() + { + $chartKey = $this->createTestChart(); + $event = $this->seatsioClient->events()->create($chartKey); + $this->seatsioClient->events()->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1"), null, "order1"); + + $report = $this->seatsioClient->events()->reports()->summaryByCategoryKey($event->key); + + self::assertEquals(17, $report['9']['count']); + self::assertEquals(17, $report['9']['bySection']['NO_SECTION']); + self::assertEquals(1, $report['9']['byStatus'][ObjectStatus::$BOOKED]); + self::assertEquals(16, $report['9']['byStatus'][ObjectStatus::$FREE]); + + self::assertEquals(17, $report['10']['count']); + self::assertEquals(17, $report['10']['bySection']['NO_SECTION']); + self::assertEquals(17, $report['10']['byStatus'][ObjectStatus::$FREE]); + } + + public function testSummaryByCategoryLabel() + { + $chartKey = $this->createTestChart(); + $event = $this->seatsioClient->events()->create($chartKey); + $this->seatsioClient->events()->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1"), null, "order1"); + + $report = $this->seatsioClient->events()->reports()->summaryByCategoryLabel($event->key); + + self::assertEquals(17, $report['Cat1']['count']); + self::assertEquals(17, $report['Cat1']['bySection']['NO_SECTION']); + self::assertEquals(1, $report['Cat1']['byStatus'][ObjectStatus::$BOOKED]); + self::assertEquals(16, $report['Cat1']['byStatus'][ObjectStatus::$FREE]); + + self::assertEquals(17, $report['Cat2']['count']); + self::assertEquals(17, $report['Cat2']['bySection']['NO_SECTION']); + self::assertEquals(17, $report['Cat2']['byStatus'][ObjectStatus::$FREE]); + } + + public function testSummaryBySection() + { + $chartKey = $this->createTestChart(); + $event = $this->seatsioClient->events()->create($chartKey); + $this->seatsioClient->events()->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1"), null, "order1"); + + $report = $this->seatsioClient->events()->reports()->summaryBySection($event->key); + + self::assertEquals(34, $report['NO_SECTION']['count']); + self::assertEquals(1, $report['NO_SECTION']['byStatus'][ObjectStatus::$BOOKED]); + self::assertEquals(33, $report['NO_SECTION']['byStatus'][ObjectStatus::$FREE]); + self::assertEquals(17, $report['NO_SECTION']['byCategoryKey']['9']); + self::assertEquals(17, $report['NO_SECTION']['byCategoryKey']['10']); + self::assertEquals(17, $report['NO_SECTION']['byCategoryLabel']['Cat1']); + self::assertEquals(17, $report['NO_SECTION']['byCategoryLabel']['Cat2']); + } + +} \ No newline at end of file