Skip to content

Commit

Permalink
Fix report definition serializing
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Jul 26, 2019
1 parent 7f458e6 commit 39829eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
48 changes: 39 additions & 9 deletions src/services/reports/models/ReportDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 Критерии отбора данных для отчета
Expand Down Expand Up @@ -52,11 +53,11 @@ class ReportDefinition
/**
* @var ReportPage Ограничение на количество строк в отчете. Если не задано, используется ограничение 1 000 000.
*/
private $Page;
private $page;
/**
* @var ReportOrderBy[]
*/
private $Order = [];
private $orderBy = [];

/**
* ReportDefinition constructor.
Expand All @@ -78,7 +79,8 @@ public function __construct(
$format,
$includeVAT,
$includeDiscount
) {
)
{
$this->SelectionCriteria = $selectionCriteria;
$this->FieldNames = $fieldNames;
$this->ReportName = $reportName;
Expand All @@ -91,27 +93,55 @@ public function __construct(

public function addOrderBy(ReportOrderBy $orderBy): void
{
$this->Order[] = $orderBy;
$this->orderBy[] = $orderBy;
}

/**
* @return ReportOrderBy[]
*/
public function getOrderBy(): array
{
return $this->Order;
return $this->orderBy;
}

/**
* @return ReportPage
*/
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 <b>json_encode</b>,
* 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;
}
}
}
6 changes: 3 additions & 3 deletions src/services/reports/models/ReportPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class ReportPage
/**
* @var int Максимальное количество строк в отчете.
*/
public $limit;
public $Limit;

/**
* ReportPage constructor.
* @param int $limit
*/
public function __construct($limit)
{
$this->limit = $limit;
$this->Limit = $limit;
}
}
}

0 comments on commit 39829eb

Please sign in to comment.