-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from seatsio/add-chart-reports
Add chart reports
- Loading branch information
Showing
7 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/.idea | ||
/vendor/* | ||
/composer.phar | ||
*.iml | ||
*.iml | ||
.DS_store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Seatsio\Reports; | ||
|
||
|
||
class ChartReportItem | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $label; | ||
/** | ||
* @var string | ||
*/ | ||
public $categoryLabel; | ||
/** | ||
* @var string | ||
*/ | ||
public $categoryKey; | ||
/** | ||
* @var string | ||
*/ | ||
public $entrance; | ||
/** | ||
* @var string | ||
*/ | ||
public $objectType; | ||
/** | ||
* @var string | ||
*/ | ||
public $section; | ||
/** | ||
* @var int | ||
*/ | ||
public $capacity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Seatsio\Reports; | ||
|
||
use Seatsio\SeatsioJsonMapper; | ||
|
||
class ChartReports | ||
{ | ||
|
||
/** | ||
* @var \GuzzleHttp\Client | ||
*/ | ||
private $client; | ||
|
||
public function __construct($client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
|
||
/** | ||
* @param $chartKey string | ||
* @param $label string | ||
* @return array | ||
*/ | ||
public function byLabel($chartKey) | ||
{ | ||
$res = $this->client->get(self::reportUrl('byLabel', $chartKey)); | ||
$json = \GuzzleHttp\json_decode($res->getBody()); | ||
return $this->mapMultiValuedReport($json); | ||
} | ||
|
||
private static function reportUrl($reportType, $eventKey) | ||
{ | ||
return \GuzzleHttp\uri_template('/reports/charts/{key}/{reportType}', array("key" => $eventKey, "reportType" => $reportType)); | ||
} | ||
|
||
/** | ||
* @param $json mixed | ||
* @return array | ||
*/ | ||
private static function mapMultiValuedReport($json) | ||
{ | ||
$mapper = SeatsioJsonMapper::create(); | ||
$result = []; | ||
foreach ($json as $status => $reportItems) { | ||
$result[$status] = $mapper->mapArray($reportItems, array(), ChartReportItem::class); | ||
} | ||
return $result; | ||
} | ||
|
||
|
||
} |
2 changes: 1 addition & 1 deletion
2
src/EventReports/EventReportItem.php → src/Reports/EventReportItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace Seatsio\EventReports; | ||
namespace Seatsio\Reports; | ||
|
||
|
||
class EventReportItem | ||
|
2 changes: 1 addition & 1 deletion
2
src/EventReports/EventReports.php → src/Reports/EventReports.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace Seatsio\EventReports; | ||
namespace Seatsio\Reports; | ||
|
||
use Seatsio\SeatsioJsonMapper; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Seatsio\ChartReports; | ||
|
||
use Seatsio\SeatsioClientTest; | ||
|
||
class ChartReportsTest extends SeatsioClientTest | ||
{ | ||
|
||
public function testReportItemProperties() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
|
||
$report = $this->seatsioClient->chartReports->byLabel($chartKey); | ||
|
||
$reportItem = $report["A-1"][0]; | ||
self::assertEquals("A-1", $reportItem->label); | ||
self::assertEquals("Cat1", $reportItem->categoryLabel); | ||
self::assertEquals(9, $reportItem->categoryKey); | ||
self::assertEquals("seat", $reportItem->objectType); | ||
self::assertNull($reportItem->section); | ||
self::assertNull($reportItem->entrance); | ||
} | ||
|
||
public function testReportItemPropertiesForGA() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
|
||
$report = $this->seatsioClient->chartReports->byLabel($chartKey); | ||
|
||
$reportItem = $report["GA1"][0]; | ||
self::assertEquals(100, $reportItem->capacity); | ||
self::assertEquals("generalAdmission", $reportItem->objectType); | ||
} | ||
|
||
public function testByLabel() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
|
||
$report = $this->seatsioClient->chartReports->byLabel($chartKey); | ||
self::assertCount(1, $report["A-1"]); | ||
self::assertCount(1, $report["A-2"]); | ||
} | ||
|
||
} |