summaryrefslogtreecommitdiff
path: root/includes/view/Shifts_view.php
blob: c796b13ecc833fe1a0df1ea8f9749ca75709924c (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
<?php

function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin) {
  $parsedown = new Parsedown();
  
  $angeltypes = [];
  foreach ($angeltypes_source as $angeltype)
    $angeltypes[$angeltype['id']] = $angeltype;
  
  $needed_angels = '';
  foreach ($shift['NeedAngels'] as $needed_angeltype) {
    $class = 'progress-bar-warning';
    if ($needed_angeltype['taken'] == 0)
      $class = 'progress-bar-danger';
    if ($needed_angeltype['taken'] >= $needed_angeltype['count'])
      $class = 'progress-bar-success';
    $needed_angels .= '<div class="list-group-item">';
    $needed_angels .= '<div class="pull-right">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $needed_angeltype['TID'], _('Sign up')) . '</div>';
    $needed_angels .= '<h3>' . AngelType_name_render($angeltypes[$needed_angeltype['TID']]) . '</h3>';
    $needed_angels .= progress_bar(0, $needed_angeltype['count'], $needed_angeltype['taken'], $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']);
    
    $angels = [];
    foreach ($shift['ShiftEntry'] as $shift_entry) {
      if ($shift_entry['TID'] == $needed_angeltype['TID']) {
        $entry = User_Nick_render(User($shift_entry['UID']));
        if ($shift_entry['freeloaded'])
          $entry = '<strike>' . $entry . '</strike>';
        if ($user_shift_admin) {
          $entry .= ' <div class="btn-group">';
          $entry .= button_glyph(page_link_to('user_myshifts') . '&edit=' . $shift['SID'] . '&id=' . $shift_entry['UID'], 'pencil', 'btn-xs');
          $entry .= button_glyph(page_link_to('user_shifts') . '&entry_id=' . $shift_entry['id'], 'trash', 'btn-xs');
          $entry .= '</div>';
        }
        $angels[] = $entry;
      }
    }
    
    $needed_angels .= join(', ', $angels);
    
    $needed_angels .= '</div>';
  }
  
  return page_with_title($shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
      msg(),
      $shift_admin ? buttons([
          button(shift_edit_link($shift), glyph('pencil') . _('edit')),
          button(shift_delete_link($shift), glyph('trash') . _('delete')) 
      ]) : '',
      div('row', [
          div('col-sm-3 col-xs-6', [
              '<h4>' . _('Start') . '</h4>',
              '<p class="lead">',
              date('y-m-d', $shift['start']),
              '<br />',
              date('H:i', $shift['start']),
              '</p>' 
          ]),
          div('col-sm-3 col-xs-6', [
              '<h4>' . _('End') . '</h4>',
              '<p class="lead">',
              date('y-m-d', $shift['end']),
              '<br />',
              date('H:i', $shift['end']),
              '</p>' 
          ]),
          div('col-sm-3 col-xs-6', [
              '<h4>' . _('Location') . '</h4>',
              '<p class="lead">' . $room['Name'] . '</p>' 
          ]),
          div('col-sm-3 col-xs-6', [
              '<h4>' . _('More info') . '</h4>',
              $shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['URL'] . '</a>' : '' 
          ]) 
      ]),
      div('row', [
          div('col-sm-6', [
              '<h2>' . _('Needed angels') . '</h2>',
              '<div class="list-group">' . $needed_angels . '</div>' 
          ]),
          div('col-sm-6', [
              '<h2>' . _('Description') . '</h2>',
              $parsedown->parse($shifttype['description']) 
          ]) 
      ]) 
  ]);
}

/**
 * Calc shift length in format 12:23h.
 *
 * @param Shift $shift          
 */
function shift_length($shift) {
  $length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ":";
  $length .= str_pad((($shift['end'] - $shift['start']) % (60 * 60)) / 60, 2, "0", STR_PAD_LEFT) . "h";
  return $length;
}
?>