From 1289101f6e4b729018dba64e92b4c9397db67f2d Mon Sep 17 00:00:00 2001 From: msquare Date: Wed, 20 Dec 2017 00:42:58 +0100 Subject: rewrite controller for creating shift entries --- includes/view/ShiftCalendarShiftRenderer.php | 7 +- includes/view/ShiftEntry_view.php | 154 +++++++++++++++++---------- includes/view/Shifts_view.php | 71 ++++++------ includes/view/User_view.php | 2 +- 4 files changed, 144 insertions(+), 90 deletions(-) (limited to 'includes/view') diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php index 3e59d61a..74b36bc3 100644 --- a/includes/view/ShiftCalendarShiftRenderer.php +++ b/includes/view/ShiftCalendarShiftRenderer.php @@ -125,8 +125,7 @@ class ShiftCalendarShiftRenderer if (in_array('user_shifts_admin', $privileges)) { $html .= '
  • '; - $html .= button( - page_link_to('user_shifts', ['shift_id' => $shift['SID']]), + $html .= button(shift_entry_create_link_admin($shift), glyph('plus') . _('Add more angels'), 'btn-xs' ); @@ -172,12 +171,12 @@ class ShiftCalendarShiftRenderer case ShiftSignupState::FREE: // When admin or free display a link + button for sign up $entry_list[] = '' . $inner_text . ' ' . button( - page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']]), + shift_entry_create_link($shift, $angeltype), _('Sign up'), 'btn-xs btn-primary' ); break; diff --git a/includes/view/ShiftEntry_view.php b/includes/view/ShiftEntry_view.php index 6dceac10..da99e9d8 100644 --- a/includes/view/ShiftEntry_view.php +++ b/includes/view/ShiftEntry_view.php @@ -10,92 +10,138 @@ * * @return string HTML */ -function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_user) { +function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_user) +{ return page_with_title(ShiftEntry_delete_title(), [ - info(sprintf( - _('Do you want to sign off %s from shift %s from %s to %s as %s?'), - User_Nick_render($signoff_user), - $shift['name'], - date('Y-m-d H:i', $shift['start']), - date('Y-m-d H:i', $shift['end']), - $angeltype['name'] - ), true), + info(sprintf(_('Do you want to sign off %s from shift %s from %s to %s as %s?'), User_Nick_render($signoff_user), $shift['name'], date('Y-m-d H:i', $shift['start']), date('Y-m-d H:i', $shift['end']), $angeltype['name']), true), buttons([ button(user_link($signoff_user), glyph('remove') . _('cancel')), - button(ShiftEntry_delete_link($shiftEntry, ['continue' => 1]), glyph('ok') . _('delete'), 'btn-danger') + button(shift_entry_delete_link($shiftEntry, [ + 'continue' => 1 + ]), glyph('ok') . _('delete'), 'btn-danger') ]) ]); } /** * Sign off from a shift, asking for ack. - * - * @param array $shiftEntry - * @param array $shift - * @param array $angeltype - * @param array $signoff_user - * + * + * @param array $shiftEntry + * @param array $shift + * @param array $angeltype + * @param array $signoff_user + * * @return string HTML */ -function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user) { +function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user) +{ return page_with_title(ShiftEntry_delete_title(), [ - info(sprintf( - _('Do you want to sign off from your shift %s from %s to %s as %s?'), - $shift['name'], - date('Y-m-d H:i', $shift['start']), - date('Y-m-d H:i', $shift['end']), - $angeltype['name'] - ), true), + info(sprintf(_('Do you want to sign off from your shift %s from %s to %s as %s?'), $shift['name'], date('Y-m-d H:i', $shift['start']), date('Y-m-d H:i', $shift['end']), $angeltype['name']), true), buttons([ button(user_link($signoff_user), glyph('remove') . _('cancel')), - button(ShiftEntry_delete_link($shiftEntry, ['continue' => 1]), glyph('ok') . _('delete'), 'btn-danger') + button(shift_entry_delete_link($shiftEntry, [ + 'continue' => 1 + ]), glyph('ok') . _('delete'), 'btn-danger') ]) ]); } /** - * Link to delete a shift entry. - * @param array $shiftEntry + * Title for deleting a shift entry. + */ +function ShiftEntry_delete_title() +{ + return _('Shift sign off'); +} + +/** + * Admin puts user into shift. + * + * @param array $shift + * @param array $room + * @param array $angeltype + * @param array $angeltypes_select + * @param array $signup_user + * @param array $users_select + */ +function ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_select, $signup_user, $users_select) +{ + return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] . ' %c', [ + Shift_view_header($shift, $room), + info(_('Do you want to sign up the following user for this shift?'), true), + form([ + form_select('angeltype_id', _('Angeltype'), $angeltypes_select, $angeltype['id']), + form_select('user_id', _('User'), $users_select, $signup_user['UID']), + form_submit('submit', glyph('ok') . _('Save')) + ]) + ]); +} + +/** + * Supporter puts user into shift. + * + * @param array $shift + * @param array $room + * @param array $angeltype + * @param array $signup_user + * @param array $users_select + */ +function ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_user, $users_select) +{ + return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] . ' %c', [ + Shift_view_header($shift, $room), + info(sprintf(_('Do you want to sign up the following user for this shift as %s?'), AngelType_name_render($angeltype)), true), + form([ + form_select('user_id', _('User'), $users_select, $signup_user['UID']), + form_submit('submit', glyph('ok') . _('Save')) + ]) + ]); +} + +/** + * User joining a shift. * - * @return string URL + * @param array $shift + * @param array $room + * @param array $angeltype + * @param string $comment */ -function ShiftEntry_delete_link($shiftEntry, $params = []) { - $params = array_merge(['entry_id' => $shiftEntry['id']], $params); - return page_link_to('user_shifts', $params); +function ShiftEntry_create_view_user($shift, $room, $angeltype, $comment) +{ + return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] . ' %c', [ + Shift_view_header($shift, $room), + info(sprintf(_('Do you want to sign up for this shift as %s?'), AngelType_name_render($angeltype)), true), + form([ + form_textarea('comment', _('Comment (for your eyes only):'), $comment), + form_submit('submit', glyph('ok') . _('Save')) + ]) + ]); } /** - * Title for deleting a shift entry. + * Title for creating a shift entry. */ -function ShiftEntry_delete_title() { - return _('Shift sign off'); +function ShiftEntry_create_title() +{ + return _('Shift signup'); } /** * Display form for adding/editing a shift entry. * - * @param string $angel - * @param string $date - * @param string $location - * @param string $title - * @param string $type - * @param string $comment - * @param bool $freeloaded - * @param string $freeload_comment - * @param bool $user_admin_shifts + * @param string $angel + * @param string $date + * @param string $location + * @param string $title + * @param string $type + * @param string $comment + * @param bool $freeloaded + * @param string $freeload_comment + * @param bool $user_admin_shifts * @return string */ -function ShiftEntry_edit_view( - $angel, - $date, - $location, - $title, - $type, - $comment, - $freeloaded, - $freeload_comment, - $user_admin_shifts = false -) { +function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment, $freeloaded, $freeload_comment, $user_admin_shifts = false) +{ $freeload_form = []; if ($user_admin_shifts) { $freeload_form = [ diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index bc905f39..083477e6 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -2,6 +2,43 @@ use Engelsystem\ShiftSignupState; +/** + * Renders the basic shift view header. + * + * @param array $shift + * @param array $room + * + * @return string HTML + */ +function Shift_view_header($shift, $room) { + return div('row', [ + div('col-sm-3 col-xs-6', [ + '

    ' . _('Title') . '

    ', + '

    ' . ($shift['URL'] != '' ? '' . $shift['title'] . '' : $shift['title']) . '

    ' + ]), + div('col-sm-3 col-xs-6', [ + '

    ' . _('Start') . '

    ', + '

    ', + glyph('calendar') . date(_('Y-m-d'), $shift['start']), + '
    ', + glyph('time') . date('H:i', $shift['start']), + '

    ' + ]), + div('col-sm-3 col-xs-6', [ + '

    ' . _('End') . '

    ', + '

    ', + glyph('calendar') . date(_('Y-m-d'), $shift['end']), + '
    ', + glyph('time') . date('H:i', $shift['end']), + '

    ' + ]), + div('col-sm-3 col-xs-6', [ + '

    ' . _('Location') . '

    ', + '

    ' . Room_name_render($room) . '

    ' + ]) + ]); +} + /** * @param array $shift * @return string @@ -41,10 +78,7 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null) } if ($angeltype['shift_signup_state']->isSignupAllowed()) { - return button( - page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']]), - _('Sign up') - ); + return button(shift_entry_create_link($shift, $angeltype), _('Sign up')); } elseif ($user_angeltype == null) { return button( page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]), @@ -100,32 +134,7 @@ function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupSt $admin_shifttypes ? button(shifttype_link($shifttype), $shifttype['name']) : '', $admin_rooms ? button(room_link($room), glyph('map-marker') . $room['Name']) : '' ]) : '', - div('row', [ - div('col-sm-3 col-xs-6', [ - '

    ' . _('Title') . '

    ', - '

    ' . ($shift['URL'] != '' ? '' . $shift['title'] . '' : $shift['title']) . '

    ' - ]), - div('col-sm-3 col-xs-6', [ - '

    ' . _('Start') . '

    ', - '

    ', - glyph('calendar') . date(_('Y-m-d'), $shift['start']), - '
    ', - glyph('time') . date('H:i', $shift['start']), - '

    ' - ]), - div('col-sm-3 col-xs-6', [ - '

    ' . _('End') . '

    ', - '

    ', - glyph('calendar') . date(_('Y-m-d'), $shift['end']), - '
    ', - glyph('time') . date('H:i', $shift['end']), - '

    ' - ]), - div('col-sm-3 col-xs-6', [ - '

    ' . _('Location') . '

    ', - '

    ' . Room_name_render($room) . '

    ' - ]) - ]), + Shift_view_header($shift, $room), div('row', [ div('col-sm-6', [ '

    ' . _('Needed angels') . '

    ', @@ -213,7 +222,7 @@ function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angelty 'btn-xs' ); } - $entry .= button_glyph(page_link_to('user_shifts', ['entry_id' => $shift_entry['id']]), 'trash', 'btn-xs'); + $entry .= button_glyph(shift_entry_delete_link($shift_entry), 'trash', 'btn-xs'); $entry .= ''; } return $entry; diff --git a/includes/view/User_view.php b/includes/view/User_view.php index e47603fb..dbc86724 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -365,7 +365,7 @@ function User_view_myshift($shift, $user_source, $its_me) } if (Shift_signout_allowed($shift, ['id' => $shift['TID']], $user_source)) { $myshift['actions'][] = button( - ShiftEntry_delete_link($shift), + shift_entry_delete_link($shift), glyph('trash') . _('sign off'), 'btn-xs' ); -- cgit v1.2.3-54-g00ecf