shift signup improvements for shift view
This commit is contained in:
parent
74b98b8c3e
commit
34e2f49875
|
@ -41,11 +41,20 @@ function shift_controller() {
|
||||||
if ($angeltypes === false)
|
if ($angeltypes === false)
|
||||||
engelsystem_error('Unable to load angeltypes.');
|
engelsystem_error('Unable to load angeltypes.');
|
||||||
|
|
||||||
User_angeltypes($user);
|
$user_shifts = Shifts_by_user($user);
|
||||||
|
if ($user_shifts === false)
|
||||||
|
engelsystem_error('Unable to load users shifts.');
|
||||||
|
|
||||||
|
$signed_up = false;
|
||||||
|
foreach ($user_shifts as $user_shift)
|
||||||
|
if ($user_shift['SID'] == $shift['SID']) {
|
||||||
|
$signed_up = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
$shift['name'],
|
$shift['name'],
|
||||||
Shift_view($shift, $shifttype, $room, in_array('admin_shifts', $privileges), $angeltypes, in_array('user_shifts_admin', $privileges), in_array('admin_rooms', $privileges), in_array('shifttypes', $privileges))
|
Shift_view($shift, $shifttype, $room, in_array('admin_shifts', $privileges), $angeltypes, in_array('user_shifts_admin', $privileges), in_array('admin_rooms', $privileges), in_array('shifttypes', $privileges), $user_shifts, $signed_up)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,74 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a shift collides with other shifts (in time).
|
||||||
|
* @param Shift $shift
|
||||||
|
* @param array<Shift> $shifts
|
||||||
|
*/
|
||||||
|
function Shift_collides($shift, $shifts) {
|
||||||
|
foreach ($shifts as $other_shift)
|
||||||
|
if ($shift['SID'] != $other_shift['SID'])
|
||||||
|
if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start']))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an angel can sign up for given shift.
|
||||||
|
*
|
||||||
|
* @param Shift $shift
|
||||||
|
* @param AngelType $angeltype
|
||||||
|
* @param array<Shift> $user_shifts
|
||||||
|
*/
|
||||||
|
function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_shifts = null) {
|
||||||
|
global $user, $privileges;
|
||||||
|
|
||||||
|
if ($user_shifts == null) {
|
||||||
|
$user_shifts = Shifts_by_user($user);
|
||||||
|
if ($user_shifts === false)
|
||||||
|
engelsystem_error('Unable to load users shifts.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$collides = Shift_collides($shift, $user_shifts);
|
||||||
|
|
||||||
|
if ($user_angeltype == null) {
|
||||||
|
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||||
|
if ($user_angeltype === false)
|
||||||
|
engelsystem_error('Unable to load user angeltype.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$signed_up = false;
|
||||||
|
foreach ($user_shifts as $user_shift)
|
||||||
|
if ($user_shift['SID'] == $shift['SID']) {
|
||||||
|
$signed_up = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// is the shift still running or alternatively is the user shift admin?
|
||||||
|
$user_may_join_shift = true;
|
||||||
|
|
||||||
|
// you cannot join if user alread joined a parallel or this shift
|
||||||
|
$user_may_join_shift &= ! $collides;
|
||||||
|
|
||||||
|
// you cannot join if you already singed up for this shift
|
||||||
|
$user_may_join_shift &= ! $signed_up;
|
||||||
|
|
||||||
|
// you cannot join if user is not of this angel type
|
||||||
|
$user_may_join_shift &= $user_angeltype != null;
|
||||||
|
|
||||||
|
// you cannot join if you are not confirmed
|
||||||
|
if ($angeltype['restricted'] == 1 && $user_angeltype != null)
|
||||||
|
$user_may_join_shift &= isset($user_angeltype['confirm_user_id']);
|
||||||
|
|
||||||
|
// you can only join if the shift is in future
|
||||||
|
$user_may_join_shift &= time() < $shift['start'];
|
||||||
|
|
||||||
|
// User shift admins may join anybody in every shift
|
||||||
|
$user_may_join_shift |= in_array('user_shifts_admin', $privileges);
|
||||||
|
|
||||||
|
return $user_may_join_shift;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a shift by its external id.
|
* Delete a shift by its external id.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,7 +10,7 @@ function user_shifts() {
|
||||||
if (User_is_freeloader($user))
|
if (User_is_freeloader($user))
|
||||||
redirect(page_link_to('user_myshifts'));
|
redirect(page_link_to('user_myshifts'));
|
||||||
|
|
||||||
// Locations laden
|
// Locations laden
|
||||||
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
||||||
$room_array = array();
|
$room_array = array();
|
||||||
foreach ($rooms as $room)
|
foreach ($rooms as $room)
|
||||||
|
@ -63,7 +63,7 @@ function user_shifts() {
|
||||||
redirect(page_link_to('user_shifts'));
|
redirect(page_link_to('user_shifts'));
|
||||||
$shift = $shift[0];
|
$shift = $shift[0];
|
||||||
|
|
||||||
// Engeltypen laden
|
// Engeltypen laden
|
||||||
$types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
$types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||||
$angel_types = array();
|
$angel_types = array();
|
||||||
$needed_angel_types = array();
|
$needed_angel_types = array();
|
||||||
|
@ -543,14 +543,16 @@ function view_user_shifts() {
|
||||||
|
|
||||||
// qqqqqq
|
// qqqqqq
|
||||||
$is_free = false;
|
$is_free = false;
|
||||||
$shifts_row = date('d.m. H:i', $shift['start']);
|
$shifts_row = '<a href="' . shift_link($shift) . '">' . date('d.m. H:i', $shift['start']);
|
||||||
$shifts_row .= " – ";
|
$shifts_row .= " – ";
|
||||||
$shifts_row .= date('H:i', $shift['end']);
|
$shifts_row .= date('H:i', $shift['end']);
|
||||||
$shifts_row .= "<br /><b>";
|
$shifts_row .= "<br /><b>";
|
||||||
$shifts_row .= '<a href="' . shift_link($shift) . '">' . ShiftType($shift['shifttype_id'])['name'] . '</a>';
|
$shifts_row .= ShiftType($shift['shifttype_id'])['name'];
|
||||||
$shifts_row .= "</b><br />";
|
$shifts_row .= "</b><br />";
|
||||||
$shifts_row .= '<a href="' . shift_link($shift) . '">' . $shift['title'] . '</a>';
|
if ($shift['title'] != '') {
|
||||||
$shifts_row .= "<br />";
|
$shifts_row .= $shift['title'];
|
||||||
|
$shifts_row .= "<br />";
|
||||||
|
}
|
||||||
if (in_array('admin_shifts', $privileges))
|
if (in_array('admin_shifts', $privileges))
|
||||||
$shifts_row .= ' ' . table_buttons(array(
|
$shifts_row .= ' ' . table_buttons(array(
|
||||||
button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
|
button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin, $admin_rooms, $admin_shifttypes) {
|
function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null, $user_shifts = null) {
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
if ($user_angeltype == null) {
|
||||||
|
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||||
|
if ($user_angeltype === false)
|
||||||
|
engelsystem_error('Unable to load user angeltype.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Shift_signup_allowed($shift, $angeltype, $user_angeltype, $user_shifts))
|
||||||
|
return button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'));
|
||||||
|
elseif ($user_angeltype == null)
|
||||||
|
return button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], sprintf('Become %s', $angeltype['name']));
|
||||||
|
else
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin, $admin_rooms, $admin_shifttypes, $user_shifts, $signed_up) {
|
||||||
$parsedown = new Parsedown();
|
$parsedown = new Parsedown();
|
||||||
|
|
||||||
$angeltypes = [];
|
$angeltypes = [];
|
||||||
|
@ -15,7 +32,9 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source,
|
||||||
if ($needed_angeltype['taken'] >= $needed_angeltype['count'])
|
if ($needed_angeltype['taken'] >= $needed_angeltype['count'])
|
||||||
$class = 'progress-bar-success';
|
$class = 'progress-bar-success';
|
||||||
$needed_angels .= '<div class="list-group-item">';
|
$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 .= '<div class="pull-right">' . Shift_signup_button_render($shift, $angeltypes[$needed_angeltype['TID']]) . '</div>';
|
||||||
|
|
||||||
$needed_angels .= '<h3>' . AngelType_name_render($angeltypes[$needed_angeltype['TID']]) . '</h3>';
|
$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']);
|
$needed_angels .= progress_bar(0, $needed_angeltype['count'], $needed_angeltype['taken'], $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']);
|
||||||
|
|
||||||
|
@ -42,6 +61,8 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source,
|
||||||
|
|
||||||
return page_with_title($shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
|
return page_with_title($shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
|
||||||
msg(),
|
msg(),
|
||||||
|
Shift_collides($shift, $user_shifts) ? info(_('This shift collides with one of your shifts.'), true) : '',
|
||||||
|
$signed_up ? info(_('You are signed up for this shift.'), true) : '',
|
||||||
($shift_admin || $admin_shifttypes || $admin_rooms) ? buttons([
|
($shift_admin || $admin_shifttypes || $admin_rooms) ? buttons([
|
||||||
$shift_admin ? button(shift_edit_link($shift), glyph('pencil') . _('edit')) : '',
|
$shift_admin ? button(shift_edit_link($shift), glyph('pencil') . _('edit')) : '',
|
||||||
$shift_admin ? button(shift_delete_link($shift), glyph('trash') . _('delete')) : '',
|
$shift_admin ? button(shift_delete_link($shift), glyph('trash') . _('delete')) : '',
|
||||||
|
@ -55,7 +76,7 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source,
|
||||||
]),
|
]),
|
||||||
div('col-sm-3 col-xs-6', [
|
div('col-sm-3 col-xs-6', [
|
||||||
'<h4>' . _('Start') . '</h4>',
|
'<h4>' . _('Start') . '</h4>',
|
||||||
'<p class="lead">',
|
'<p class="lead' . (time() >= $shift['start'] ? ' text-success' : '') . '">',
|
||||||
glyph('calendar') . date('y-m-d', $shift['start']),
|
glyph('calendar') . date('y-m-d', $shift['start']),
|
||||||
'<br />',
|
'<br />',
|
||||||
glyph('time') . date('H:i', $shift['start']),
|
glyph('time') . date('H:i', $shift['start']),
|
||||||
|
@ -63,7 +84,7 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source,
|
||||||
]),
|
]),
|
||||||
div('col-sm-3 col-xs-6', [
|
div('col-sm-3 col-xs-6', [
|
||||||
'<h4>' . _('End') . '</h4>',
|
'<h4>' . _('End') . '</h4>',
|
||||||
'<p class="lead">',
|
'<p class="lead' . (time() >= $shift['end'] ? ' text-success' : '') . '">',
|
||||||
glyph('calendar') . date('y-m-d', $shift['end']),
|
glyph('calendar') . date('y-m-d', $shift['end']),
|
||||||
'<br />',
|
'<br />',
|
||||||
glyph('time') . date('H:i', $shift['end']),
|
glyph('time') . date('H:i', $shift['end']),
|
||||||
|
|
Loading…
Reference in New Issue