summaryrefslogtreecommitdiff
path: root/includes/view
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-12-20 00:42:58 +0100
committermsquare <msquare@notrademark.de>2017-12-20 00:42:58 +0100
commit1289101f6e4b729018dba64e92b4c9397db67f2d (patch)
tree9b63d1174807af762050275062a20dbaf7d761d7 /includes/view
parentafd7c59d1d1e07c61099e3cf6a4c66af883c3302 (diff)
rewrite controller for creating shift entries
Diffstat (limited to 'includes/view')
-rw-r--r--includes/view/ShiftCalendarShiftRenderer.php7
-rw-r--r--includes/view/ShiftEntry_view.php154
-rw-r--r--includes/view/Shifts_view.php71
-rw-r--r--includes/view/User_view.php2
4 files changed, 144 insertions, 90 deletions
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 .= '<li class="list-group-item">';
- $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[] = '<a href="'
- . page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']])
+ . shift_entry_create_link($shift, $angeltype)
. '">'
. $inner_text
. '</a> '
. 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'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
+ 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'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
+ 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'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
+ 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
@@ -3,6 +3,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', [
+ '<h4>' . _('Title') . '</h4>',
+ '<p class="lead">' . ($shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>' : $shift['title']) . '</p>'
+ ]),
+ div('col-sm-3 col-xs-6', [
+ '<h4>' . _('Start') . '</h4>',
+ '<p class="lead' . (time() >= $shift['start'] ? ' text-success' : '') . '">',
+ glyph('calendar') . date(_('Y-m-d'), $shift['start']),
+ '<br />',
+ glyph('time') . date('H:i', $shift['start']),
+ '</p>'
+ ]),
+ div('col-sm-3 col-xs-6', [
+ '<h4>' . _('End') . '</h4>',
+ '<p class="lead' . (time() >= $shift['end'] ? ' text-success' : '') . '">',
+ glyph('calendar') . date(_('Y-m-d'), $shift['end']),
+ '<br />',
+ glyph('time') . date('H:i', $shift['end']),
+ '</p>'
+ ]),
+ div('col-sm-3 col-xs-6', [
+ '<h4>' . _('Location') . '</h4>',
+ '<p class="lead">' . Room_name_render($room) . '</p>'
+ ])
+ ]);
+}
+
+/**
* @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', [
- '<h4>' . _('Title') . '</h4>',
- '<p class="lead">' . ($shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>' : $shift['title']) . '</p>'
- ]),
- div('col-sm-3 col-xs-6', [
- '<h4>' . _('Start') . '</h4>',
- '<p class="lead' . (time() >= $shift['start'] ? ' text-success' : '') . '">',
- glyph('calendar') . date(_('Y-m-d'), $shift['start']),
- '<br />',
- glyph('time') . date('H:i', $shift['start']),
- '</p>'
- ]),
- div('col-sm-3 col-xs-6', [
- '<h4>' . _('End') . '</h4>',
- '<p class="lead' . (time() >= $shift['end'] ? ' text-success' : '') . '">',
- glyph('calendar') . date(_('Y-m-d'), $shift['end']),
- '<br />',
- glyph('time') . date('H:i', $shift['end']),
- '</p>'
- ]),
- div('col-sm-3 col-xs-6', [
- '<h4>' . _('Location') . '</h4>',
- '<p class="lead">' . Room_name_render($room) . '</p>'
- ])
- ]),
+ Shift_view_header($shift, $room),
div('row', [
div('col-sm-6', [
'<h2>' . _('Needed angels') . '</h2>',
@@ -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 .= '</div>';
}
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'
);