aboutsummaryrefslogtreecommitdiff
path: root/templates/dates/seminar_html_roomplanning.php
blob: decc8c025d5e5ab5c3726ecec81fa9e2e5b69255 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?
if (!isset($show_room)) :
    // show rooms only if there is more than one
    if (empty($dates['rooms']) || count($dates['rooms']) === 1) :
        $show_room = false;
    else :
        $show_room = true;
    endif;
endif;

$now = time();

if (!empty($dates['regular']['turnus_data']) || !empty($dates['irregular'])) :
  $output = [];
  if (is_array($dates['regular']['turnus_data'])) foreach ($dates['regular']['turnus_data'] as $cycle) :
    $first_date = sprintf(_("ab %s"), strftime('%x', $cycle['first_date']['date']));
    $last_date = $cycle['last_date']['date'];
    if (empty($with_past_intervals) && $last_date < $now) {
        continue;
    }
    if ($cycle['cycle'] == 1) :
        $cycle_output = $cycle['tostring_short'] . ' (' . sprintf(_("zweiwöchentlich, %s"), $first_date) . ')';
    elseif ($cycle['cycle'] == 2) :
        $cycle_output = $cycle['tostring_short'] . ' (' . sprintf(_("dreiwöchentlich, %s"), $first_date) . ')';
    else :
      $cycle_output = $cycle['tostring_short'] . ' (' . _("wöchentlich") . ')';
    endif;
    if ($cycle['desc'])
      $cycle_output .= ' - '. $cycle['desc'];

    if ($show_room) :
        $cycle_output .= $this->render_partial('dates/_seminar_rooms',
            [
                'assigned' => $cycle['assigned_rooms'],
                'freetext' => $cycle['freetext_rooms'],
                'link'     => true
            ]
        );
    endif;

    $output[] = $cycle_output;
  endforeach;

  echo implode(", <br>", $output);

  $freetext_rooms = [];
  $irregular_rooms = [];
  $irregular = [];

  if (isset($dates['irregular']) && is_array($dates['irregular'])):
    foreach ($dates['irregular'] as $date) :
        if (empty($with_past_intervals) && $date['end_time'] < $now) {
            continue;
        }
        $irregular[] = $date;
        $irregular_strings[] = $date['tostring'];
        if (!empty($date['resource_id'])) :
            if (!isset($irregular_rooms[$date['resource_id']])) :
                $irregular_rooms[$date['resource_id']] = 0;
            endif;
            $irregular_rooms[$date['resource_id']]++;
        elseif (!empty($date['raum'])) :
            if (!isset($freetext_rooms['('. $date['raum'] .')'])) :
                $freetext_rooms['('. $date['raum'] .')'] = 0;
            endif;
            $freetext_rooms['('. $date['raum'] .')']++;
        endif;
    endforeach;
    unset($irregular_rooms['']);
    echo count($output) ? ", <br>" : '';

    $rooms = array_merge(getPlainRooms($irregular_rooms), array_keys($freetext_rooms));

    if (is_array($irregular) && count($irregular)) :
        if (isset($shrink) && !$shrink && count($irregular) < 20) :
            foreach ($irregular as $date) :
                if (empty($with_past_intervals) && $date->end_time < $now) {
                    continue;
                }
                echo $date['tostring'] ?? '';

                if ($show_room && !empty($date['resource_id'])) :
                    echo ', '. _('Ort:') . ' ';
                    $room_obj = Room::find($date['resource_id']);
                    echo '<a href="' . $room_obj->getActionLink('show') . '" target="_blank">'
                    . htmlReady($room_obj->name) . '</a>';
                endif;
                echo "<br>";
            endforeach;
        else :
            echo _("Termine am") . implode(', ', shrink_dates($irregular));
            if (count($rooms) > 0) :
                if (count($rooms) > 3) :
                    $rooms = array_slice($rooms, count($rooms) - 3, count($rooms));
                endif;

                if ($show_room) :
                    echo ', ' . _("Ort:") . ' ';
                    echo implode(', ', $rooms);
                endif;
            endif;
            echo "<br>";
        endif;
    endif;
  endif;
endif;