You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
engelsystem/includes/view/ShiftsFilterRenderer.php

93 lines
2.2 KiB
PHTML

<?php
namespace Engelsystem;
8 years ago
class ShiftsFilterRenderer
{
8 years ago
/**
* The shiftFilter to render.
*
* @var ShiftsFilter
*/
private $shiftsFilter;
8 years ago
/**
* Should the filter display a day selection.
*
* @var boolean
*/
private $daySelectionEnabled = false;
8 years ago
/**
* Days that can be selected.
* Format Y-m-d
*
* @var string[]
*/
private $days = [];
/**
* ShiftsFilterRenderer constructor.
*
* @param ShiftsFilter $shiftsFilter
*/
8 years ago
public function __construct(ShiftsFilter $shiftsFilter)
{
$this->shiftsFilter = $shiftsFilter;
}
8 years ago
/**
* Renders the filter.
*
* @param string $page_link Link pointing to the actual page.
* @param array $dashboardFilter
*
* @return string Generated HTML
8 years ago
*/
public function render($page_link, $dashboardFilter = [])
8 years ago
{
$toolbar = [];
if ($this->daySelectionEnabled && !empty($this->days)) {
$selected_day = date('Y-m-d', $this->shiftsFilter->getStartTime());
8 years ago
$day_dropdown_items = [];
foreach ($this->days as $day) {
$link = $page_link . '&shifts_filter_day=' . $day;
7 years ago
$day_dropdown_items[] = toolbar_item_link($link, '', $day);
8 years ago
}
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
if ($dashboardFilter) {
$toolbar[] = sprintf(
'<li role="presentation"><a href="%s">%s</a></li>',
url('/public-dashboard', ['filtered' => true] + $dashboardFilter),
icon('speedometer2') . __('Dashboard')
);
}
8 years ago
}
return div('mb-3', [
8 years ago
toolbar_pills($toolbar)
]);
}
8 years ago
/**
* Should the filter display a day selection.
*
* @param string[] $days
8 years ago
*/
public function enableDaySelection($days)
{
$this->daySelectionEnabled = true;
$this->days = $days;
}
8 years ago
/**
* Should the filter display a day selection.
*
* @return bool
8 years ago
*/
public function isDaySelectionEnabled()
{
return $this->daySelectionEnabled;
}
}