diff options
author | msquare <msquare@notrademark.de> | 2017-12-26 10:29:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-26 10:29:16 +0100 |
commit | de61c88d6de67d12d5de5b6dd0ab6b8c82e5a290 (patch) | |
tree | aac6a43cb88e3d803da5809ab37885b41bc811c6 /includes/controller | |
parent | 879918864a9c6da0fe9be1aca6c443ec8df0afc3 (diff) | |
parent | f8d0a7c5b00a58c646871e355b5876dcc5890be5 (diff) |
Merge pull request #388 from MyIgel/master
Formatting, Docstrings, and fixup
Diffstat (limited to 'includes/controller')
-rw-r--r-- | includes/controller/angeltypes_controller.php | 34 | ||||
-rw-r--r-- | includes/controller/event_config_controller.php | 7 | ||||
-rw-r--r-- | includes/controller/public_dashboard_controller.php | 47 | ||||
-rw-r--r-- | includes/controller/shift_entries_controller.php | 185 | ||||
-rw-r--r-- | includes/controller/shifts_controller.php | 16 | ||||
-rw-r--r-- | includes/controller/user_angeltypes_controller.php | 12 | ||||
-rw-r--r-- | includes/controller/users_controller.php | 7 |
7 files changed, 184 insertions, 124 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 48b81b9f..399930c2 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -2,6 +2,7 @@ use Engelsystem\ShiftsFilter; use Engelsystem\ShiftsFilterRenderer; + /** * Text for Angeltype related links. * @@ -39,8 +40,8 @@ function angeltypes_controller() /** * Path to angeltype view. * - * @param int $angeltype_id AngelType id - * @param array $params additional params + * @param int $angeltype_id AngelType id + * @param array $params additional params * @return string */ function angeltype_link($angeltype_id, $params = []) @@ -187,17 +188,18 @@ function angeltype_controller() $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_driver_license = UserDriverLicense($user['UID']); $members = Users_by_angeltype($angeltype); - + $days = angeltype_controller_shiftsFilterDays($angeltype); $shiftsFilter = angeltype_controller_shiftsFilter($angeltype, $days); - + $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter); $shiftsFilterRenderer->enableDaySelection($days); - + $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter); $request = request(); $tab = 0; - if($request->has('shifts_filter_day')) { + + if ($request->has('shifts_filter_day')) { $tab = 1; } @@ -221,11 +223,12 @@ function angeltype_controller() /** * On which days do shifts for this angeltype occur? Needed for shiftCalendar. - * - * @param Angeltype $angeltype + * + * @param array $angeltype * @return array */ -function angeltype_controller_shiftsFilterDays($angeltype) { +function angeltype_controller_shiftsFilterDays($angeltype) +{ $all_shifts = Shifts_by_angeltype($angeltype); $days = []; foreach ($all_shifts as $shift) { @@ -239,20 +242,21 @@ function angeltype_controller_shiftsFilterDays($angeltype) { /** * Sets up the shift filter for the angeltype. - * - * @param Angeltype $angeltype + * + * @param array $angeltype * @param array $days * @return ShiftsFilter */ -function angeltype_controller_shiftsFilter($angeltype, $days) { +function angeltype_controller_shiftsFilter($angeltype, $days) +{ global $privileges; - + $request = request(); $shiftsFilter = new ShiftsFilter( in_array('user_shifts_admin', $privileges), Room_ids(), [$angeltype['id']] - ); + ); $selected_day = date('Y-m-d'); if (!empty($days)) { $selected_day = $days[0]; @@ -262,7 +266,7 @@ function angeltype_controller_shiftsFilter($angeltype, $days) { } $shiftsFilter->setStartTime(parse_date('Y-m-d H:i', $selected_day . ' 00:00')); $shiftsFilter->setEndTime(parse_date('Y-m-d H:i', $selected_day . ' 23:59')); - + return $shiftsFilter; } diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php index aa328802..4422f046 100644 --- a/includes/controller/event_config_controller.php +++ b/includes/controller/event_config_controller.php @@ -101,9 +101,10 @@ function event_config_edit_controller() ); engelsystem_log( - sprintf('Changed event config: %s, %s, %s, %s, %s, %s', - $event_name, - $event_welcome_msg, + sprintf( + 'Changed event config: %s, %s, %s, %s, %s, %s', + $event_name, + $event_welcome_msg, date('Y-m-d', $buildup_start_date), date('Y-m-d', $event_start_date), date('Y-m-d', $event_end_date), diff --git a/includes/controller/public_dashboard_controller.php b/includes/controller/public_dashboard_controller.php index 7d652a64..23d5a4d6 100644 --- a/includes/controller/public_dashboard_controller.php +++ b/includes/controller/public_dashboard_controller.php @@ -2,25 +2,27 @@ /** * Loads all data for the public dashboard + * + * @return array */ function public_dashboard_controller() { $stats = [ 'needed-3-hours' => stats_angels_needed_three_hours(), - 'needed-night' => stats_angels_needed_for_nightshifts(), + 'needed-night' => stats_angels_needed_for_nightshifts(), 'angels-working' => stats_currently_working(), - 'hours-to-work' => stats_hours_to_work() + 'hours-to-work' => stats_hours_to_work() ]; - + $free_shifts_source = Shifts_free(time(), time() + 12 * 60 * 60); $free_shifts = []; foreach ($free_shifts_source as $shift) { $free_shift = public_dashboard_controller_free_shift($shift); - if(count($free_shift['needed_angels']) > 0) { + if (count($free_shift['needed_angels']) > 0) { $free_shifts[] = $free_shift; } } - + return [ _('Public Dashboard'), public_dashboard_view($stats, $free_shifts) @@ -30,41 +32,43 @@ function public_dashboard_controller() /** * Gathers information for free shifts to display. * - * @param array $shift + * @param array $shift + * @return array */ function public_dashboard_controller_free_shift($shift) { $shifttype = ShiftType($shift['shifttype_id']); $room = Room($shift['RID']); - + $free_shift = [ - 'SID' => $shift['SID'], - 'style' => 'default', - 'start' => date('H:i', $shift['start']), - 'end' => date('H:i', $shift['end']), - 'duration' => round(($shift['end'] - $shift['start']) / 3600), + 'SID' => $shift['SID'], + 'style' => 'default', + 'start' => date('H:i', $shift['start']), + 'end' => date('H:i', $shift['end']), + 'duration' => round(($shift['end'] - $shift['start']) / 3600), 'shifttype_name' => $shifttype['name'], - 'title' => $shift['title'], - 'room_name' => $room['Name'], - 'needed_angels' => [] + 'title' => $shift['title'], + 'room_name' => $room['Name'], + 'needed_angels' => [] ]; - + if (time() + 3 * 60 * 60 > $shift['start']) { $free_shift['style'] = 'warning'; } if (time() > $shift['start']) { $free_shift['style'] = 'danger'; } - + $free_shift['needed_angels'] = public_dashboard_needed_angels($shift['NeedAngels']); - + return $free_shift; } /** * Gathers information for needed angels on dashboard * - * @param array $needed_angels + * @param array $needed_angels + * @return array */ function public_dashboard_needed_angels($needed_angels) { @@ -75,7 +79,7 @@ function public_dashboard_needed_angels($needed_angels) $angeltype = AngelType($needed_angel['TID']); if ($angeltype['show_on_dashboard']) { $result[] = [ - 'need' => $need, + 'need' => $need, 'angeltype_name' => $angeltype['name'] ]; } @@ -86,9 +90,10 @@ function public_dashboard_needed_angels($needed_angels) /** * Returns url to public dashboard + * + * @return string */ function public_dashboard_link() { return page_link_to('public-dashboard'); } -?>
\ No newline at end of file diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index 8dbf03ef..fcd911de 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -1,23 +1,24 @@ <?php + use Engelsystem\ShiftSignupState; /** * Route shift entry actions. + * + * @return array */ function shift_entries_controller() { global $user; - + $action = strip_request_item('action'); if ($action == null) { redirect(user_link($user)); } - + switch ($action) { case 'create': return shift_entry_create_controller(); - case 'edit': - return shift_entry_edit_controller(); case 'delete': return shift_entry_delete_controller(); } @@ -25,35 +26,37 @@ function shift_entries_controller() /** * Sign up for a shift. + * + * @return array */ function shift_entry_create_controller() { global $privileges, $user; $request = request(); - + if (User_is_freeloader($user)) { redirect(page_link_to('user_myshifts')); } - + $shift = Shift($request->input('shift_id')); if ($shift == null) { redirect(user_link($user)); } - + $angeltype = AngelType($request->input('angeltype_id')); - + if (in_array('user_shifts_admin', $privileges)) { return shift_entry_create_controller_admin($shift, $angeltype); } - + if ($angeltype == null) { redirect(user_link($user)); } - + if (User_is_AngelType_supporter($user, $angeltype)) { return shift_entry_create_controller_supporter($shift, $angeltype); } - + return shift_entry_create_controller_user($shift, $angeltype); } @@ -61,58 +64,59 @@ function shift_entry_create_controller() * Sign up for a shift. * Case: Admin * - * @param array $shift - * @param array $angeltype + * @param array $shift + * @param array $angeltype + * @return array */ function shift_entry_create_controller_admin($shift, $angeltype) { global $user; $request = request(); - + $signup_user = $user; if ($request->has('user_id')) { $signup_user = User($request->input('user_id')); } - if($signup_user == null) { + if ($signup_user == null) { redirect(shift_link($shift)); } - + $angeltypes = AngelTypes(); - if($request->has('angeltype_id')) { + if ($request->has('angeltype_id')) { $angeltype = AngelType($request->input('angeltype_id')); } - if($angeltype == null) { - if(count($angeltypes) == 0) { + if ($angeltype == null) { + if (count($angeltypes) == 0) { redirect(shift_link($shift)); } $angeltype = $angeltypes[0]; } - + if ($request->has('submit')) { ShiftEntry_create([ - 'SID' => $shift['SID'], - 'TID' => $angeltype['id'], - 'UID' => $signup_user['UID'], - 'Comment' => '', - 'freeloaded' => false, + 'SID' => $shift['SID'], + 'TID' => $angeltype['id'], + 'UID' => $signup_user['UID'], + 'Comment' => '', + 'freeloaded' => false, 'freeload_comment' => '' ]); - + success(sprintf(_('%s has been subscribed to the shift.'), User_Nick_render($signup_user))); redirect(shift_link($shift)); } - + $users = Users(); $users_select = []; foreach ($users as $u) { $users_select[$u['UID']] = $u['Nick']; } - + $angeltypes_select = []; - foreach($angeltypes as $a) { + foreach ($angeltypes as $a) { $angeltypes_select[$a['id']] = $a['name']; } - + $room = Room($shift['RID']); return [ ShiftEntry_create_title(), @@ -124,53 +128,62 @@ function shift_entry_create_controller_admin($shift, $angeltype) * Sign up for a shift. * Case: Supporter * - * @param array $shift - * @param array $angeltype + * @param array $shift + * @param array $angeltype + * @return array */ function shift_entry_create_controller_supporter($shift, $angeltype) { global $user; $request = request(); - + $signup_user = $user; if ($request->has('user_id')) { $signup_user = User($request->input('user_id')); } - if (! UserAngelType_exists($signup_user, $angeltype)) { + if (!UserAngelType_exists($signup_user, $angeltype)) { error(_('User is not in angeltype.')); redirect(shift_link($shift)); } - + $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); - $shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries); - if (! $shift_signup_state->isSignupAllowed()) { + $shift_signup_state = Shift_signup_allowed( + $signup_user, + $shift, + $angeltype, + null, + null, + $needed_angeltype, + $shift_entries + ); + if (!$shift_signup_state->isSignupAllowed()) { if ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) { error(_('This shift is already occupied.')); } redirect(shift_link($shift)); } - + if ($request->has('submit')) { ShiftEntry_create([ - 'SID' => $shift['SID'], - 'TID' => $angeltype['id'], - 'UID' => $signup_user['UID'], - 'Comment' => '', - 'freeloaded' => false, + 'SID' => $shift['SID'], + 'TID' => $angeltype['id'], + 'UID' => $signup_user['UID'], + 'Comment' => '', + 'freeloaded' => false, 'freeload_comment' => '' ]); - + success(sprintf(_('%s has been subscribed to the shift.'), User_Nick_render($signup_user))); redirect(shift_link($shift)); } - + $users = Users_by_angeltype($angeltype); $users_select = []; foreach ($users as $u) { $users_select[$u['UID']] = $u['Nick']; } - + $room = Room($shift['RID']); return [ ShiftEntry_create_title(), @@ -180,9 +193,11 @@ function shift_entry_create_controller_supporter($shift, $angeltype) /** * Generates an error message for the given shift signup state. + * * @param ShiftSignupState $shift_signup_state */ -function shift_entry_error_message(ShiftSignupState $shift_signup_state) { +function shift_entry_error_message(ShiftSignupState $shift_signup_state) +{ if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) { error(_('You need be accepted member of the angeltype.')); } elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) { @@ -202,43 +217,52 @@ function shift_entry_error_message(ShiftSignupState $shift_signup_state) { * Sign up for a shift. * Case: User * - * @param array $shift - * @param array $angeltype + * @param array $shift + * @param array $angeltype + * @return array */ function shift_entry_create_controller_user($shift, $angeltype) { global $user; $request = request(); - + $signup_user = $user; $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); - $shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries); - if (! $shift_signup_state->isSignupAllowed()) { + $shift_signup_state = Shift_signup_allowed( + $signup_user, + $shift, + $angeltype, + null, + null, + $needed_angeltype, + $shift_entries + ); + if (!$shift_signup_state->isSignupAllowed()) { shift_entry_error_message($shift_signup_state); redirect(shift_link($shift)); } - + $comment = ''; if ($request->has('submit')) { $comment = strip_request_item_nl('comment'); ShiftEntry_create([ - 'SID' => $shift['SID'], - 'TID' => $angeltype['id'], - 'UID' => $signup_user['UID'], - 'Comment' => $comment, - 'freeloaded' => false, + 'SID' => $shift['SID'], + 'TID' => $angeltype['id'], + 'UID' => $signup_user['UID'], + 'Comment' => $comment, + 'freeloaded' => false, 'freeload_comment' => '' ]); - - if ($angeltype['restricted'] == false && ! UserAngelType_exists($signup_user, $angeltype)) { + + if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user, $angeltype)) { UserAngelType_create($signup_user, $angeltype); } - + success(_('You are subscribed. Thank you!')); redirect(shift_link($shift)); } - + $room = Room($shift['RID']); return [ ShiftEntry_create_title(), @@ -249,13 +273,16 @@ function shift_entry_create_controller_user($shift, $angeltype) /** * Link to create a shift entry. * + * @param array $shift + * @param array $angeltype + * @param array $params * @return string URL */ function shift_entry_create_link($shift, $angeltype, $params = []) { $params = array_merge([ - 'action' => 'create', - 'shift_id' => $shift['SID'], + 'action' => 'create', + 'shift_id' => $shift['SID'], 'angeltype_id' => $angeltype['id'] ], $params); return page_link_to('shift_entries', $params); @@ -264,12 +291,14 @@ function shift_entry_create_link($shift, $angeltype, $params = []) /** * Link to create a shift entry as admin. * + * @param array $shift + * @param array $params * @return string URL */ function shift_entry_create_link_admin($shift, $params = []) { $params = array_merge([ - 'action' => 'create', + 'action' => 'create', 'shift_id' => $shift['SID'] ], $params); return page_link_to('shift_entries', $params); @@ -277,12 +306,14 @@ function shift_entry_create_link_admin($shift, $params = []) /** * Load a shift entry from get parameter shift_entry_id. + * + * @return array */ function shift_entry_load() { $request = request(); - - if (! $request->has('shift_entry_id') || ! test_request_int('shift_entry_id')) { + + if (!$request->has('shift_entry_id') || !test_request_int('shift_entry_id')) { redirect(page_link_to('user_shifts')); } $shiftEntry = ShiftEntry($request->input('shift_entry_id')); @@ -290,40 +321,42 @@ function shift_entry_load() error(_('Shift entry not found.')); redirect(page_link_to('user_shifts')); } - + return $shiftEntry; } /** * Remove somebody from a shift. + * + * @return array */ function shift_entry_delete_controller() { global $user; $request = request(); $shiftEntry = shift_entry_load(); - + $shift = Shift($shiftEntry['SID']); $angeltype = AngelType($shiftEntry['TID']); $signout_user = User($shiftEntry['UID']); - if (! Shift_signout_allowed($shift, $angeltype, $signout_user)) { + if (!Shift_signout_allowed($shift, $angeltype, $signout_user)) { error(_('You are not allowed to remove this shift entry. If necessary, ask your supporter or heaven to do so.')); redirect(user_link($signout_user)); } - + if ($request->has('continue')) { ShiftEntry_delete($shiftEntry); success(_('Shift entry removed.')); redirect(shift_link($shift)); } - + if ($user['UID'] == $signout_user['UID']) { return [ ShiftEntry_delete_title(), ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user) ]; } - + return [ ShiftEntry_delete_title(), ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signout_user) @@ -333,14 +366,14 @@ function shift_entry_delete_controller() /** * Link to delete a shift entry. * - * @param array $shiftEntry - * + * @param array $shiftEntry + * @param array $params * @return string URL */ function shift_entry_delete_link($shiftEntry, $params = []) { $params = array_merge([ - 'action' => 'delete', + 'action' => 'delete', 'shift_entry_id' => $shiftEntry['id'] ], $params); return page_link_to('shift_entries', $params); diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 28e35a1a..5930595e 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -45,7 +45,6 @@ function shift_edit_controller() { global $privileges; - // Schicht bearbeiten $msg = ''; $valid = true; $request = request(); @@ -65,7 +64,11 @@ function shift_edit_controller() $angeltypes = select_array(AngelTypes(), 'id', 'name'); $shifttypes = select_array(ShiftTypes(), 'id', 'name'); - $needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'angel_type_id', 'count'); + $needed_angel_types = select_array( + NeededAngelTypes_by_shift($shift_id), + 'angel_type_id', + 'count' + ); foreach (array_keys($angeltypes) as $angeltype_id) { if (!isset($needed_angel_types[$angeltype_id])) { $needed_angel_types[$angeltype_id] = 0; @@ -149,7 +152,7 @@ function shift_edit_controller() $needed_angel_types_info = []; foreach ($needed_angel_types as $type_id => $count) { NeededAngelType_add($shift_id, $type_id, null, $count); - if($count > 0) { + if ($count > 0) { $needed_angel_types_info[] = $angeltypes[$type_id] . ': ' . $count; } } @@ -178,7 +181,9 @@ function shift_edit_controller() shifts_title(), [ msg(), - '<noscript>' . info(_('This page is much more comfortable with javascript.'), true) . '</noscript>', + '<noscript>' + . info(_('This page is much more comfortable with javascript.'), true) + . '</noscript>', form([ form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), form_text('title', _('Title'), $title), @@ -310,8 +315,9 @@ function shifts_controller() switch ($request->input('action')) { case 'view': return shift_controller(); + /** @noinspection PhpMissingBreakStatementInspection */ case 'next': - return shift_next_controller(); + shift_next_controller(); default: redirect(page_link_to('/')); } diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 543ba150..340de2a4 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -273,7 +273,9 @@ function user_angeltype_update_controller() UserAngelType_update($user_angeltype['id'], $supporter); $success_message = sprintf( - $supporter ? _('Added supporter rights for %s to %s.') : _('Removed supporter rights for %s from %s.'), + $supporter + ? _('Added supporter rights for %s to %s.') + : _('Removed supporter rights for %s from %s.'), AngelType_name_render($angeltype), User_Nick_render($user_source) ); @@ -291,6 +293,8 @@ function user_angeltype_update_controller() /** * User joining an Angeltype (Or supporter doing this for him). + * + * @return array */ function user_angeltype_add_controller() { @@ -364,7 +368,11 @@ function user_angeltype_join_controller($angeltype) $user_angeltype_id = UserAngelType_create($user, $angeltype); $success_message = sprintf(_('You joined %s.'), $angeltype['name']); - engelsystem_log(sprintf('User %s joined %s.', User_Nick_render($user), AngelType_name_render($angeltype))); + engelsystem_log(sprintf( + 'User %s joined %s.', + User_Nick_render($user), + AngelType_name_render($angeltype) + )); success($success_message); if (in_array('admin_user_angeltypes', $privileges)) { diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index b1ef517e..e206176f 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -271,7 +271,7 @@ function users_list_controller() User_arrived_count(), User_active_count(), User_force_active_count(), - ShiftEntries_freeleaded_count(), + ShiftEntries_freeloaded_count(), User_tshirts_count(), User_got_voucher_count() ) @@ -464,7 +464,10 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) { $filtered_shifts[] = $shift; } - if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) { + if ( + in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) + && $taken >= $needed_angels_count + ) { $filtered_shifts[] = $shift; } } |