2016-10-05 18:56:50 +02:00
|
|
|
<?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;
|
2016-10-05 18:56:50 +02:00
|
|
|
|
2017-01-02 15:43:36 +01:00
|
|
|
/**
|
|
|
|
* Should the filter display a day selection.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
private $daySelectionEnabled = false;
|
2016-10-05 18:56:50 +02:00
|
|
|
|
2017-01-02 15:43:36 +01:00
|
|
|
/**
|
|
|
|
* Days that can be selected.
|
|
|
|
* Format Y-m-d
|
|
|
|
*
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
private $days = [];
|
2016-10-05 18:56:50 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2016-10-05 18:56:50 +02:00
|
|
|
|
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());
|
2023-02-04 02:43:47 +01:00
|
|
|
$selected_day_formatted = date(__('Y-m-d'), $this->shiftsFilter->getStartTime());
|
2017-01-02 15:43:36 +01:00
|
|
|
$day_dropdown_items = [];
|
2023-02-04 02:43:47 +01:00
|
|
|
foreach ($this->days as $value => $day) {
|
|
|
|
$link = $page_link . '&shifts_filter_day=' . $value;
|
2017-08-30 14:59:27 +02:00
|
|
|
$day_dropdown_items[] = toolbar_item_link($link, '', $day);
|
2017-01-02 15:43:36 +01:00
|
|
|
}
|
2023-02-04 02:43:47 +01:00
|
|
|
$toolbar[] = toolbar_dropdown($selected_day_formatted, $day_dropdown_items, true);
|
2020-11-24 01:18:05 +01:00
|
|
|
|
|
|
|
if ($dashboardFilter) {
|
|
|
|
$toolbar[] = sprintf(
|
2021-07-25 23:47:16 +02:00
|
|
|
'<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),
|
2021-07-22 21:22:21 +02:00
|
|
|
icon('speedometer2') . __('Dashboard')
|
2020-11-24 01:18:05 +01:00
|
|
|
);
|
|
|
|
}
|
2023-01-17 20:01:29 +01:00
|
|
|
if (!request('showFilledShifts') && !auth()->can('user_shifts_admin')) {
|
|
|
|
$toolbar[] = sprintf(
|
|
|
|
'<li role="presentation"><a class="nav-link" href="%s">%s</a></li>',
|
|
|
|
$page_link . '&showFilledShifts=1&showShiftsTab=1&shifts_filter_day=' . request('shifts_filter_day', $selected_day),
|
|
|
|
icon('eye') . __('All')
|
|
|
|
);
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
}
|
2021-07-24 18:19:53 +02:00
|
|
|
return div('mb-3', [
|
2023-02-05 18:03:00 +01:00
|
|
|
toolbar_pills($toolbar),
|
2017-01-02 15:43:36 +01:00
|
|
|
]);
|
|
|
|
}
|
2016-10-05 18:56:50 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2016-10-05 18:56:50 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2016-10-05 18:56:50 +02:00
|
|
|
}
|