From 952c7892f3ac7bfadf8419062e44ff1af66ecc57 Mon Sep 17 00:00:00 2001 From: Bot Date: Mon, 25 Dec 2017 23:12:52 +0100 Subject: Formatting & Docstrings --- includes/controller/shift_entries_controller.php | 181 ++++++++++++++--------- 1 file changed, 108 insertions(+), 73 deletions(-) (limited to 'includes/controller/shift_entries_controller.php') diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index 8dbf03ef..c20e48b4 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -1,18 +1,21 @@ 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 +66,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 +130,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 +195,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 +219,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 +275,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 +293,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 +308,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,19 +323,21 @@ 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']); @@ -310,20 +345,20 @@ function shift_entry_delete_controller() 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 +368,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); -- cgit v1.2.3-70-g09d2 From 75eea1681eb75af40cfc5eaffe85338a93871ff0 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 25 Dec 2017 23:17:17 +0100 Subject: Removed dead function call --- includes/controller/shift_entries_controller.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'includes/controller/shift_entries_controller.php') diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index c20e48b4..f53b1300 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -19,8 +19,6 @@ function shift_entries_controller() switch ($action) { case 'create': return shift_entry_create_controller(); - case 'edit': - return shift_entry_edit_controller(); case 'delete': return shift_entry_delete_controller(); } -- cgit v1.2.3-70-g09d2 From f8d0a7c5b00a58c646871e355b5876dcc5890be5 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 25 Dec 2017 23:52:31 +0100 Subject: Updated translation / Formatting / Test --- includes/controller/shift_entries_controller.php | 2 +- includes/controller/user_angeltypes_controller.php | 3 +-- locale/de_DE.UTF-8/LC_MESSAGES/default.mo | Bin 43369 -> 43368 bytes locale/de_DE.UTF-8/LC_MESSAGES/default.po | 4 ++-- tests/Unit/ServiceProviderTest.php | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) (limited to 'includes/controller/shift_entries_controller.php') diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index f53b1300..fcd911de 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -339,7 +339,7 @@ function shift_entry_delete_controller() $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)); } diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index fb63cda8..340de2a4 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -275,8 +275,7 @@ function user_angeltype_update_controller() $success_message = sprintf( $supporter ? _('Added supporter rights for %s to %s.') - : _('Removed supporter rights for %s from %s.') - , + : _('Removed supporter rights for %s from %s.'), AngelType_name_render($angeltype), User_Nick_render($user_source) ); diff --git a/locale/de_DE.UTF-8/LC_MESSAGES/default.mo b/locale/de_DE.UTF-8/LC_MESSAGES/default.mo index 4fd86d87..be300c32 100644 Binary files a/locale/de_DE.UTF-8/LC_MESSAGES/default.mo and b/locale/de_DE.UTF-8/LC_MESSAGES/default.mo differ diff --git a/locale/de_DE.UTF-8/LC_MESSAGES/default.po b/locale/de_DE.UTF-8/LC_MESSAGES/default.po index f3404930..4c324348 100644 --- a/locale/de_DE.UTF-8/LC_MESSAGES/default.po +++ b/locale/de_DE.UTF-8/LC_MESSAGES/default.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Engelsystem 2.0\n" "POT-Creation-Date: 2017-12-23 11:35+0100\n" -"PO-Revision-Date: 2017-12-23 22:31+0100\n" +"PO-Revision-Date: 2017-12-25 23:55+0100\n" "Last-Translator: msquare \n" "Language-Team: \n" "Language: de_DE\n" @@ -211,7 +211,7 @@ msgstr "Schichteintrag nicht gefunden." #: /Users/msquare/workspace/projects/engelsystem/includes/controller/shift_entries_controller.php:310 msgid "" -"You are not allowed to remove this shift entry. If neccessary, ask your " +"You are not allowed to remove this shift entry. If necessary, ask your " "supporter or heaven to do so." msgstr "" "Du darfst diesen Schichteintrag nicht entfernen. Falls notwendig, frage " diff --git a/tests/Unit/ServiceProviderTest.php b/tests/Unit/ServiceProviderTest.php index dc58a65e..149e28f8 100644 --- a/tests/Unit/ServiceProviderTest.php +++ b/tests/Unit/ServiceProviderTest.php @@ -3,8 +3,8 @@ namespace Engelsystem\Test\Unit; use Engelsystem\Application; +use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_Matcher_InvokedRecorder as InvokedRecorder; use PHPUnit_Framework_MockObject_MockObject as MockObject; abstract class ServiceProviderTest extends TestCase -- cgit v1.2.3-70-g09d2