summaryrefslogtreecommitdiff
path: root/includes/view/ShiftsFilterRenderer.php
blob: 94d53bb3511318a7faab51e4db46834a26ddbcea (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
<?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;

  private $days = [];

  private $event_config = null;

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

  /**
   * Renders the filter.
   *
   * @return Generated HTML
   */
  public function render() {
    $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) {
        $day_dropdown_items[] = toolbar_item_link('', '', $day);
      }
      $toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
    }
    return toolbar_pills($toolbar);
  }

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

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

?>