From 39829eb6515da428c8b3aa0468033046d158f5ec Mon Sep 17 00:00:00 2001 From: George Date: Fri, 26 Jul 2019 13:29:24 +0500 Subject: [PATCH] Fix report definition serializing --- .../reports/models/ReportDefinition.php | 48 +++++++++++++++---- src/services/reports/models/ReportPage.php | 6 +-- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/services/reports/models/ReportDefinition.php b/src/services/reports/models/ReportDefinition.php index 14624a6..925a404 100644 --- a/src/services/reports/models/ReportDefinition.php +++ b/src/services/reports/models/ReportDefinition.php @@ -8,8 +8,9 @@ use directapi\services\reports\enum\ReportFieldsEnum; use directapi\services\reports\enum\ReportFormatsEnum; use directapi\services\reports\enum\ReportTypesEnum; +use JsonSerializable; -class ReportDefinition +class ReportDefinition implements JsonSerializable { /** * @var ReportSelectionCriteria Критерии отбора данных для отчета @@ -52,11 +53,11 @@ class ReportDefinition /** * @var ReportPage Ограничение на количество строк в отчете. Если не задано, используется ограничение 1 000 000. */ - private $Page; + private $page; /** * @var ReportOrderBy[] */ - private $Order = []; + private $orderBy = []; /** * ReportDefinition constructor. @@ -78,7 +79,8 @@ public function __construct( $format, $includeVAT, $includeDiscount - ) { + ) + { $this->SelectionCriteria = $selectionCriteria; $this->FieldNames = $fieldNames; $this->ReportName = $reportName; @@ -91,7 +93,7 @@ public function __construct( public function addOrderBy(ReportOrderBy $orderBy): void { - $this->Order[] = $orderBy; + $this->orderBy[] = $orderBy; } /** @@ -99,7 +101,7 @@ public function addOrderBy(ReportOrderBy $orderBy): void */ public function getOrderBy(): array { - return $this->Order; + return $this->orderBy; } /** @@ -107,11 +109,39 @@ public function getOrderBy(): array */ public function getPage(): ReportPage { - return $this->Page; + return $this->page; } public function setPage(ReportPage $page): void { - $this->Page = $page; + $this->page = $page; + } + + /** + * Specify data which should be serialized to JSON + * @link https://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + public function jsonSerialize() + { + $data = [ + 'SelectionCriteria' => $this->SelectionCriteria, + 'FieldNames' => $this->FieldNames, + 'ReportName' => $this->ReportName, + 'ReportType' => $this->ReportType, + 'DateRangeType' => $this->DateRangeType, + 'Format' => $this->Format, + 'IncludeVAT' => $this->IncludeVAT, + 'IncludeDiscount' => $this->IncludeDiscount + ]; + if ($this->page) { + $data['Page'] = $this->page; + } + if ($this->orderBy) { + $data['OrderBy'] = $this->orderBy; + } + return $data; } -} \ No newline at end of file +} diff --git a/src/services/reports/models/ReportPage.php b/src/services/reports/models/ReportPage.php index 1fd1778..4114d93 100644 --- a/src/services/reports/models/ReportPage.php +++ b/src/services/reports/models/ReportPage.php @@ -8,7 +8,7 @@ class ReportPage /** * @var int Максимальное количество строк в отчете. */ - public $limit; + public $Limit; /** * ReportPage constructor. @@ -16,6 +16,6 @@ class ReportPage */ public function __construct($limit) { - $this->limit = $limit; + $this->Limit = $limit; } -} \ No newline at end of file +}