summaryrefslogtreecommitdiff
path: root/includes/view/ShiftsFilterRenderer.php
blob: 9b7df7cd3e075fa99f115501dadbe0fc86f12081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?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;

  /**
   * Days that can be selected.
   * Format Y-m-d
   *
   * @var string[]
   */
  private $days = [];

    public function __construct(ShiftsFilter $shiftsFilter)
    {
        $this->shiftsFilter = $shiftsFilter;
    }

  /**
   * 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)
    ]);
  }

  /**
   * Should the filter display a day selection.
   */
  public function enableDaySelection($days)
  {
      $this->daySelectionEnabled = true;
      $this->days = $days;
  }

  /**
   * Should the filter display a day selection.
   */
  public function isDaySelectionEnabled()
  {
      return $this->daySelectionEnabled;
  }
}