engelsystem/includes/view/ShiftsFilterRenderer.php

73 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace Engelsystem;
2017-01-02 03:57:23 +01:00
class ShiftsFilterRenderer
{
2017-01-02 15:43:36 +01:00
/**
* The shiftFilter to render.
*
* @var ShiftsFilter
*/
private $shiftsFilter;
2017-01-02 15:43:36 +01:00
/**
* Should the filter display a day selection.
*
* @var boolean
*/
private $daySelectionEnabled = false;
2017-01-02 15:43:36 +01:00
/**
* Days that can be selected.
* Format Y-m-d
*
* @var string[]
*/
private $days = [];
2017-01-02 03:57:23 +01:00
public function __construct(ShiftsFilter $shiftsFilter)
{
$this->shiftsFilter = $shiftsFilter;
}
2017-01-02 15:43:36 +01:00
/**
* Renders the filter.
*
* @return Generated HTML
*/
public function render($link_base)
{
$toolbar = [];
if ($this->daySelectionEnabled && !empty($this->days)) {
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
$day_dropdown_items = [];
foreach ($this->days as $day) {
$day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day);
}
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
}
return div('form-group', [
toolbar_pills($toolbar)
]);
}
2017-01-02 15:43:36 +01:00
/**
* Should the filter display a day selection.
*/
public function enableDaySelection($days)
{
$this->daySelectionEnabled = true;
$this->days = $days;
}
2017-01-02 15:43:36 +01:00
/**
* Should the filter display a day selection.
*/
public function isDaySelectionEnabled()
{
return $this->daySelectionEnabled;
}
}