Skip to content

Commit

Permalink
Load export type ids dynamically. (kimai#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-gasparini committed Apr 12, 2019
1 parent 3a4aa5a commit aad2700
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/Controller/ExportController.php
Expand Up @@ -36,6 +36,11 @@ class ExportController extends AbstractController
*/
protected $export;

/**
* @var ExportQuery
*/
protected $query;

/**
* @param TimesheetRepository $timesheet
* @param ServiceExport $export
Expand All @@ -44,6 +49,21 @@ public function __construct(TimesheetRepository $timesheet, ServiceExport $expor
{
$this->timesheetRepository = $timesheet;
$this->export = $export;
$this->query = $this->createExportQueryWithExports();
}

/**
* @return ExportQuery
*/
protected function createExportQueryWithExports()
{
$query = new ExportQuery();

foreach ($this->export->getRenderer() as $export) {
$query->addType($export->getId());
}

return $query;
}

/**
Expand All @@ -55,7 +75,7 @@ protected function getDefaultQuery()
$begin = new \DateTime('first day of this month');
$end = new \DateTime('last day of this month');

$query = new ExportQuery();
$query = (clone $this->query);
$query->setOrder(ExportQuery::ORDER_ASC);
$query->setBegin($begin);
$query->setEnd($end);
Expand Down
22 changes: 16 additions & 6 deletions src/Repository/Query/ExportQuery.php
Expand Up @@ -14,17 +14,27 @@
*/
class ExportQuery extends TimesheetQuery
{
public const TYPE_HTML = 'html';
public const TYPE_CSV = 'csv';
public const TYPE_PDF = 'pdf';
public const TYPE_XLSX = 'xlsx';
public const TYPE_ODS = 'ods';
/**
* @var array
*/
protected $typeArray = [];

/**
* @var string
*/
protected $type;

/**
* @var string $type
* @return ExportQuery
*/
public function addType(string $type)
{
$this->typeArray[] = $type;

return $this;
}

/**
* @return string
*/
Expand All @@ -39,7 +49,7 @@ public function getType(): ?string
*/
public function setType(string $type)
{
if (in_array($type, [self::TYPE_PDF, self::TYPE_CSV, self::TYPE_HTML, self::TYPE_XLSX, self::TYPE_ODS])) {
if (in_array($type, $this->typeArray)) {
$this->type = $type;
}

Expand Down

0 comments on commit aad2700

Please sign in to comment.