engelsystem/includes/view/ShiftsFilterRenderer.php

93 lines
2.2 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-03 03:22:48 +01:00
/**
* ShiftsFilterRenderer constructor.
*
* @param ShiftsFilter $shiftsFilter
*/
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.
*
2017-11-24 12:01:19 +01:00
* @param string $page_link Link pointing to the actual page.
2020-11-24 01:18:05 +01:00
* @param array $dashboardFilter
*
2017-01-03 03:22:48 +01:00
* @return string Generated HTML
2017-01-02 15:43:36 +01:00
*/
2020-11-24 01:18:05 +01:00
public function render($page_link, $dashboardFilter = [])
2017-01-02 15:43:36 +01:00
{
$toolbar = [];
if ($this->daySelectionEnabled && !empty($this->days)) {
2017-01-03 14:12:17 +01:00
$selected_day = date('Y-m-d', $this->shiftsFilter->getStartTime());
2017-01-02 15:43:36 +01:00
$day_dropdown_items = [];
foreach ($this->days as $day) {
2017-11-24 12:01:19 +01:00
$link = $page_link . '&shifts_filter_day=' . $day;
2017-08-30 14:59:27 +02:00
$day_dropdown_items[] = toolbar_item_link($link, '', $day);
2017-01-02 15:43:36 +01:00
}
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
2020-11-24 01:18:05 +01:00
if ($dashboardFilter) {
$toolbar[] = sprintf(
'<li role="presentation"><a class="nav-link" href="%s">%s</a></li>',
2020-11-24 01:18:05 +01:00
url('/public-dashboard', ['filtered' => true] + $dashboardFilter),
icon('speedometer2') . __('Dashboard')
2020-11-24 01:18:05 +01:00
);
}
2017-01-02 15:43:36 +01:00
}
2021-07-24 18:19:53 +02:00
return div('mb-3', [
2017-01-02 15:43:36 +01:00
toolbar_pills($toolbar)
]);
}
2017-01-02 15:43:36 +01:00
/**
* Should the filter display a day selection.
2017-01-03 03:22:48 +01:00
*
* @param string[] $days
2017-01-02 15:43:36 +01:00
*/
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.
2017-01-03 03:22:48 +01:00
*
* @return bool
2017-01-02 15:43:36 +01:00
*/
public function isDaySelectionEnabled()
{
return $this->daySelectionEnabled;
}
}