Skip to content

Commit

Permalink
Added summary report calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Mar 29, 2018
1 parent 80f2943 commit b3431a2
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 15 deletions.
58 changes: 43 additions & 15 deletions src/Events/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -90,34 +121,26 @@ 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);
}

/**
* @param $json mixed
* @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;
Expand All @@ -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));
}

}
84 changes: 84 additions & 0 deletions tests/Events/EventReportSummaryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Seatsio\Events;

use Seatsio\SeatsioClientTest;

class EventReportsSummaryTest extends SeatsioClientTest
{

public function testSummaryByStatus()
{
$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()->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']);
}

}

0 comments on commit b3431a2

Please sign in to comment.