2016-10-05 18:56:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem;
|
|
|
|
|
|
|
|
class ShiftsFilterRenderer {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The shiftFilter to render.
|
|
|
|
*
|
|
|
|
* @var ShiftsFilter
|
|
|
|
*/
|
|
|
|
private $shiftsFilter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should the filter display a day selection.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
private $daySelectionEnabled = false;
|
|
|
|
|
2016-10-05 22:28:39 +02:00
|
|
|
/**
|
|
|
|
* Days that can be selected.
|
|
|
|
* Format Y-m-d
|
|
|
|
*
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2016-10-05 18:56:50 +02:00
|
|
|
private $days = [];
|
|
|
|
|
|
|
|
public function __construct(ShiftsFilter $shiftsFilter) {
|
|
|
|
$this->shiftsFilter = $shiftsFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the filter.
|
|
|
|
*
|
|
|
|
* @return Generated HTML
|
|
|
|
*/
|
2016-10-05 22:28:39 +02:00
|
|
|
public function render($link_base) {
|
2016-10-05 18:56:50 +02:00
|
|
|
$toolbar = [];
|
|
|
|
if ($this->daySelectionEnabled && ! empty($this->days)) {
|
|
|
|
$today = date("Y-m-d");
|
|
|
|
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
|
|
|
|
$day_dropdown_items = [];
|
|
|
|
foreach ($this->days as $day) {
|
2016-10-05 22:28:39 +02:00
|
|
|
$day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day);
|
2016-10-05 18:56:50 +02:00
|
|
|
}
|
|
|
|
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
|
|
|
|
}
|
|
|
|
return toolbar_pills($toolbar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should the filter display a day selection.
|
|
|
|
*/
|
2016-10-05 22:28:39 +02:00
|
|
|
public function enableDaySelection($days) {
|
2016-10-05 18:56:50 +02:00
|
|
|
$this->daySelectionEnabled = true;
|
|
|
|
$this->days = $days;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should the filter display a day selection.
|
|
|
|
*/
|
|
|
|
public function isDaySelectionEnabled() {
|
|
|
|
return $this->daySelectionEnabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|