Skip to content

Commit

Permalink
Chart summary reports take bookWholeTables parameter (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Feb 1, 2022
1 parent b4a68d2 commit d92d4f2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/Reports/Charts/ChartReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Seatsio\SeatsioJsonMapper;
use GuzzleHttp\UriTemplate\UriTemplate;
use Seatsio\Charts\ChartObjectInfo;
use function Symfony\Component\String\b;

class ChartReports
{
Expand Down Expand Up @@ -42,12 +43,12 @@ public function byObjectType($chartKey, $bookWholeTables = null)

/**
* @param $chartKey string
* @param $bookWholeTables string
* @return array
*/
public function summaryByObjectType($chartKey)
public function summaryByObjectType($chartKey, $bookWholeTables = null)
{
$res = $this->client->get(self::summaryReportUrl('byObjectType', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
return $this->getChartSummaryReport('byObjectType', $chartKey, $bookWholeTables);
}

/**
Expand All @@ -62,12 +63,12 @@ public function byCategoryKey($chartKey, $bookWholeTables = null)

/**
* @param $chartKey string
* @param $bookWholeTables string
* @return array
*/
public function summaryByCategoryKey($chartKey)
public function summaryByCategoryKey($chartKey, $bookWholeTables = null)
{
$res = $this->client->get(self::summaryReportUrl('byCategoryKey', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
return $this->getChartSummaryReport('byCategoryKey', $chartKey, $bookWholeTables);
}

/**
Expand All @@ -82,17 +83,17 @@ public function byCategoryLabel($chartKey, $bookWholeTables = null)

/**
* @param $chartKey string
* @param $bookWholeTables string
* @return array
*/
public function summaryByCategoryLabel($chartKey)
public function summaryByCategoryLabel($chartKey, $bookWholeTables = null)
{
$res = $this->client->get(self::summaryReportUrl('byCategoryLabel', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
return $this->getChartSummaryReport('byCategoryLabel', $chartKey, $bookWholeTables);
}

/**
* @param $chartKey string
* @param $objectType string
* @param $bookWholeTables string
* @return array
*/
public function bySection($chartKey, $bookWholeTables = null)
Expand All @@ -102,17 +103,17 @@ public function bySection($chartKey, $bookWholeTables = null)

/**
* @param $chartKey string
* @param $bookWholeTables string
* @return array
*/
public function summaryBySection($chartKey)
public function summaryBySection($chartKey, $bookWholeTables = null)
{
$res = $this->client->get(self::summaryReportUrl('bySection', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
return $this->getChartSummaryReport('bySection', $chartKey, $bookWholeTables);
}

private static function reportUrl($reportType, $eventKey)
private static function reportUrl($reportType, $chartKey)
{
return UriTemplate::expand('/reports/charts/{key}/{reportType}', array("key" => $eventKey, "reportType" => $reportType));
return UriTemplate::expand('/reports/charts/{key}/{reportType}', array("key" => $chartKey, "reportType" => $reportType));
}

private static function summaryReportUrl($reportType, $chartKey)
Expand All @@ -127,6 +128,12 @@ private function getChartReport($reportType, $chartKey, $bookWholeTables)
return $this->mapMultiValuedReport($json);
}

private function getChartSummaryReport($reportType, $chartKey, $bookWholeTables)
{
$res = $this->client->get(self::summaryReportUrl($reportType, $chartKey), ["query" => ["bookWholeTables" => $bookWholeTables]]);
return \GuzzleHttp\json_decode($res->getBody(), true);
}

private static function mapMultiValuedReport($json)
{
$mapper = SeatsioJsonMapper::create();
Expand Down
35 changes: 35 additions & 0 deletions tests/Reports/ChartReportsSummaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@ public function testSummaryByObjectType()
self::assertEquals($expectedReport, $report);
}

public function testSummaryByObjectType_bookWholeTablesTrue()
{
$chartKey = $this->createTestChartWithTables();

$report = $this->seatsioClient->chartReports->summaryByObjectType($chartKey, 'true');

$expectedReport = [
'seat' => [
'count' => 0,
'byCategoryKey' => [],
'byCategoryLabel' => [],
'bySection' => []
],
'generalAdmission' => [
'count' => 0,
'byCategoryKey' => [],
'byCategoryLabel' => [],
'bySection' => []
],
'table' => [
'count' => 2,
'byCategoryKey' => [9 => 2],
'byCategoryLabel' => ['Cat1' => 2],
'bySection' => ['NO_SECTION' => 2]
],
'booth' => [
'count' => 0,
'byCategoryKey' => [],
'byCategoryLabel' => [],
'bySection' => []
]
];
self::assertEquals($expectedReport, $report);
}

public function testSummaryByCategoryKey()
{
$chartKey = $this->createTestChart();
Expand Down

0 comments on commit d92d4f2

Please sign in to comment.