From 89e62c95a7ffd71a8e860f59378ecd13d6cbb196 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 9 Oct 2018 21:47:31 +0200 Subject: [PATCH] Changed more functions :tada: --- includes/controller/angeltypes_controller.php | 15 ++--- .../controller/shift_entries_controller.php | 22 +++---- includes/controller/shifts_controller.php | 15 +++-- .../controller/user_angeltypes_controller.php | 34 +++++------ .../user_driver_licenses_controller.php | 8 +-- .../controller/user_worklog_controller.php | 27 +++++---- includes/controller/users_controller.php | 36 ++++++------ includes/helper/email_helper.php | 31 +++++++--- includes/mailer/shifts_mailer.php | 10 ++-- includes/mailer/users_mailer.php | 4 +- includes/model/AngelType_model.php | 6 +- includes/model/ShiftEntry_model.php | 25 ++++---- includes/model/Shifts_model.php | 14 ++--- includes/model/UserAngelTypes_model.php | 52 ++++++++--------- includes/model/UserDriverLicenses_model.php | 6 +- includes/model/UserGroups_model.php | 6 +- includes/model/UserWorkLog_model.php | 12 ++-- includes/model/User_model.php | 14 ++--- includes/pages/admin_active.php | 17 +++--- includes/pages/admin_arrive.php | 13 +++-- includes/pages/admin_news.php | 3 +- includes/pages/admin_questions.php | 5 +- includes/pages/admin_user.php | 57 ++++++++----------- includes/pages/guest_login.php | 15 ++--- includes/pages/user_messages.php | 19 ++++--- includes/pages/user_myshifts.php | 13 +++-- includes/pages/user_news.php | 7 +-- includes/pages/user_questions.php | 3 +- includes/pages/user_shifts.php | 2 +- includes/sys_log.php | 4 +- includes/view/Shifts_view.php | 9 +-- includes/view/UserAngelTypes_view.php | 8 ++- includes/view/UserWorkLog_view.php | 6 +- includes/view/User_view.php | 42 ++++++++------ src/Models/User/HasUserModel.php | 4 +- 35 files changed, 301 insertions(+), 263 deletions(-) diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 027e63ed..b161266d 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -57,17 +57,17 @@ function angeltype_link($angeltype_id, $params = []) */ function angeltypes_about_controller() { - global $user; + $user = auth()->user(); - if (isset($user)) { - $angeltypes = AngelTypes_with_user($user); + if ($user) { + $angeltypes = AngelTypes_with_user($user->id); } else { $angeltypes = AngelTypes(); } return [ __('Teams/Job description'), - AngelTypes_about_view($angeltypes, isset($user)) + AngelTypes_about_view($angeltypes, (bool)$user) ]; } @@ -185,7 +185,7 @@ function angeltype_controller() } $angeltype = load_angeltype(); - $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + $user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype); $user_driver_license = UserDriverLicense($user['UID']); $members = Users_by_angeltype($angeltype); @@ -277,13 +277,14 @@ function angeltype_controller_shiftsFilter($angeltype, $days) */ function angeltypes_list_controller() { - global $privileges, $user; + global $privileges; + $user = auth()->user(); if (!in_array('angeltypes', $privileges)) { redirect(page_link_to('/')); } - $angeltypes = AngelTypes_with_user($user); + $angeltypes = AngelTypes_with_user($user->id); foreach ($angeltypes as &$angeltype) { $actions = [ diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index 356a9db8..8fbee96e 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -1,5 +1,6 @@ user(); + if ($user) { redirect(page_link_to('login')); } $action = strip_request_item('action'); if (empty($action)) { - redirect(user_link($user['UID'])); + redirect(user_link($user->id)); } switch ($action) { @@ -74,14 +74,14 @@ function shift_entry_create_controller() */ function shift_entry_create_controller_admin($shift, $angeltype) { - global $user; + $user = auth()->user(); $request = request(); $signup_user = $user; if ($request->has('user_id')) { - $signup_user = User($request->input('user_id')); + $signup_user = User::find($request->input('user_id')); } - if (empty($signup_user)) { + if (!$signup_user) { redirect(shift_link($shift)); } @@ -100,7 +100,7 @@ function shift_entry_create_controller_admin($shift, $angeltype) ShiftEntry_create([ 'SID' => $shift['SID'], 'TID' => $angeltype['id'], - 'UID' => $signup_user['UID'], + 'UID' => $signup_user->id, 'Comment' => '', 'freeloaded' => false, 'freeload_comment' => '' @@ -145,7 +145,7 @@ function shift_entry_create_controller_supporter($shift, $angeltype) if ($request->has('user_id')) { $signup_user = User($request->input('user_id')); } - if (!UserAngelType_exists($signup_user, $angeltype)) { + if (!UserAngelType_exists($signup_user['UID'], $angeltype)) { error(__('User is not in angeltype.')); redirect(shift_link($shift)); } @@ -259,8 +259,8 @@ function shift_entry_create_controller_user($shift, $angeltype) 'freeload_comment' => '' ]); - if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user, $angeltype)) { - UserAngelType_create($signup_user, $angeltype); + if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user['UID'], $angeltype)) { + UserAngelType_create($signup_user['UID'], $angeltype); } success(__('You are subscribed. Thank you!')); diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 63d2d4c7..5454c648 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -272,15 +272,15 @@ function shift_controller() $shifttype = ShiftType($shift['shifttype_id']); $room = Room($shift['RID']); $angeltypes = AngelTypes(); - $user_shifts = Shifts_by_user($user); + $user_shifts = Shifts_by_user($user['UID']); $shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0); foreach ($angeltypes as &$angeltype) { $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); - if(empty($needed_angeltype)) { + if (empty($needed_angeltype)) { continue; } - + $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); $angeltype_signup_state = Shift_signup_allowed( @@ -330,13 +330,14 @@ function shifts_controller() */ function shift_next_controller() { - global $user, $privileges; + global $privileges; + $user = auth()->user(); if (!in_array('user_shifts', $privileges)) { redirect(page_link_to('/')); } - $upcoming_shifts = ShiftEntries_upcoming_for_user($user); + $upcoming_shifts = ShiftEntries_upcoming_for_user($user->id); if (!empty($upcoming_shifts)) { redirect(shift_link($upcoming_shifts[0])); @@ -381,7 +382,5 @@ function shifts_json_export_controller() */ function load_ical_shifts() { - global $user; - - return Shifts_by_user($user); + return Shifts_by_user(auth()->user()->id); } diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 734bd1e9..ee1f93ee 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -1,5 +1,7 @@ user(); - $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user); + $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user->id); if (count($unconfirmed_user_angeltypes) == 0) { return null; } @@ -101,7 +103,7 @@ function user_angeltypes_confirm_all_controller() } if ($request->has('confirmed')) { - UserAngelTypes_confirm_all($angeltype['id'], $user); + UserAngelTypes_confirm_all($angeltype['id'], $user['UID']); engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype))); success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype))); @@ -146,14 +148,14 @@ function user_angeltype_confirm_controller() redirect(page_link_to('angeltypes')); } - $user_source = User($user_angeltype['user_id']); - if (empty($user_source)) { + $user_source = User::find($user_angeltype['user_id']); + if (!$user_source) { error(__('User doesn\'t exist.')); redirect(page_link_to('angeltypes')); } if ($request->has('confirmed')) { - UserAngelType_confirm($user_angeltype['id'], $user); + UserAngelType_confirm($user_angeltype['id'], $user['UID']); engelsystem_log(sprintf( '%s confirmed for angeltype %s', @@ -201,8 +203,8 @@ function user_angeltype_delete_controller() redirect(page_link_to('angeltypes')); } - $user_source = User($user_angeltype['user_id']); - if (empty($user_source)) { + $user_source = User::find($user_angeltype['user_id']); + if (!$user_source) { error(__('User doesn\'t exist.')); redirect(page_link_to('angeltypes')); } @@ -268,8 +270,8 @@ function user_angeltype_update_controller() redirect(page_link_to('angeltypes')); } - $user_source = User($user_angeltype['user_id']); - if (empty($user_source)) { + $user_source = User::find($user_angeltype['user_id']); + if (!$user_source) { error(__('User doesn\'t exist.')); redirect(page_link_to('angeltypes')); } @@ -322,8 +324,8 @@ function user_angeltype_add_controller() if (request()->has('submit')) { $user_source = load_user(); - if (!UserAngelType_exists($user_source, $angeltype)) { - $user_angeltype_id = UserAngelType_create($user_source, $angeltype); + if (!UserAngelType_exists($user_source['UID'], $angeltype)) { + $user_angeltype_id = UserAngelType_create($user_source['UID'], $angeltype); engelsystem_log(sprintf( 'User %s added to %s.', @@ -336,7 +338,7 @@ function user_angeltype_add_controller() AngelType_name_render($angeltype) )); - UserAngelType_confirm($user_angeltype_id, $user_source); + UserAngelType_confirm($user_angeltype_id, $user_source['UID']); engelsystem_log(sprintf( 'User %s confirmed as %s.', User_Nick_render($user_source), @@ -363,14 +365,14 @@ function user_angeltype_join_controller($angeltype) { global $user, $privileges; - $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + $user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype); if (!empty($user_angeltype)) { error(sprintf(__('You are already a %s.'), $angeltype['name'])); redirect(page_link_to('angeltypes')); } if (request()->has('confirmed')) { - $user_angeltype_id = UserAngelType_create($user, $angeltype); + $user_angeltype_id = UserAngelType_create($user['UID'], $angeltype); $success_message = sprintf(__('You joined %s.'), $angeltype['name']); engelsystem_log(sprintf( @@ -381,7 +383,7 @@ function user_angeltype_join_controller($angeltype) success($success_message); if (in_array('admin_user_angeltypes', $privileges)) { - UserAngelType_confirm($user_angeltype_id, $user); + UserAngelType_confirm($user_angeltype_id, $user['UID']); engelsystem_log(sprintf( 'User %s confirmed as %s.', User_Nick_render($user), diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 2a3f7023..4c7c7fff 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -8,10 +8,10 @@ */ function user_driver_license_required_hint() { - global $user; + $user = auth()->user(); - $angeltypes = User_angeltypes($user); - $user_driver_license = UserDriverLicense($user['UID']); + $angeltypes = User_angeltypes($user->id); + $user_driver_license = UserDriverLicense($user->id); // User has already entered data, no hint needed. if (!empty($user_driver_license)) { @@ -124,7 +124,7 @@ function user_driver_license_edit_controller() if (UserDriverLicense_valid($user_driver_license)) { if (empty($user_driver_license['user_id'])) { - $user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source); + $user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source['UID']); } else { UserDriverLicenses_update($user_driver_license); } diff --git a/includes/controller/user_worklog_controller.php b/includes/controller/user_worklog_controller.php index a431643f..e1b3ee86 100644 --- a/includes/controller/user_worklog_controller.php +++ b/includes/controller/user_worklog_controller.php @@ -1,5 +1,7 @@ user(); $request = request(); $userWorkLog = UserWorkLog($request->input('user_worklog_id')); if (empty($userWorkLog)) { - redirect(user_link($user['UID'])); + redirect(user_link($user->id)); } - $user_source = User($userWorkLog['user_id']); + $user_source = User::find($userWorkLog['user_id']); if ($request->has('confirmed')) { UserWorkLog_delete($userWorkLog); success(__('Work log entry deleted.')); - redirect(user_link($user_source['UID'])); + redirect(user_link($user_source->id)); } return [ @@ -36,12 +38,12 @@ function user_worklog_delete_controller() */ function user_worklog_edit_controller() { - global $user; + $user = auth()->user(); $request = request(); $userWorkLog = UserWorkLog($request->input('user_worklog_id')); if (empty($userWorkLog)) { - redirect(user_link($user['UID'])); + redirect(user_link($user->id)); } $user_source = User($userWorkLog['user_id']); @@ -108,15 +110,15 @@ function user_worklog_from_request($userWorkLog) */ function user_worklog_add_controller() { - global $user; + $user = auth()->user(); $request = request(); $user_source = User($request->input('user_id')); if (empty($user_source)) { - redirect(user_link($user['UID'])); + redirect(user_link($user->id)); } - $userWorkLog = UserWorkLog_new($user_source); + $userWorkLog = UserWorkLog_new($user_source['UID']); if ($request->has('submit')) { list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog); @@ -186,16 +188,17 @@ function user_worklog_delete_link($userWorkLog, $parameters = []) */ function user_worklog_controller() { - global $user, $privileges; + global $privileges; + $user = auth()->user(); if (!in_array('admin_user_worklog', $privileges)) { - redirect(user_link($user['UID'])); + redirect(user_link($user->id)); } $request = request(); $action = $request->input('action'); if (!$request->has('action')) { - redirect(user_link($user['UID'])); + redirect(user_link($user->id)); } switch ($action) { diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index f49439da..be78c1d7 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -1,6 +1,8 @@ user(); $request = request(); if ($request->has('user_id')) { - $user_source = User($request->query->get('user_id')); + $user_source = User::find($request->query->get('user_id')); } else { $user_source = $user; } @@ -57,9 +60,9 @@ function user_delete_controller() } // You cannot delete yourself - if ($user['UID'] == $user_source['UID']) { + if ($user->id == $user_source->id) { error(__('You cannot delete yourself.')); - redirect(user_link($user['UID'])); + redirect(user_link($user->id)); } if ($request->has('submit')) { @@ -68,7 +71,7 @@ function user_delete_controller() if ( !( $request->has('password') - && verify_password($request->postData('password'), $user['Passwort'], $user['UID']) + && verify_password($request->postData('password'), $user->password, $user->id) ) ) { $valid = false; @@ -76,7 +79,7 @@ function user_delete_controller() } if ($valid) { - User_delete($user_source['UID']); + User_delete($user_source->id); mail_user_delete($user_source); success(__('User deleted.')); @@ -87,7 +90,7 @@ function user_delete_controller() } return [ - sprintf(__('Delete %s'), $user_source['Nick']), + sprintf(__('Delete %s'), $user_source->name), User_delete_view($user_source) ]; } @@ -196,7 +199,7 @@ function user_controller() } } - $shifts = Shifts_by_user($user_source, in_array('user_shifts_admin', $privileges)); + $shifts = Shifts_by_user($user_source['UID'], in_array('user_shifts_admin', $privileges)); foreach ($shifts as &$shift) { // TODO: Move queries to model $shift['needed_angeltypes'] = DB::select(' @@ -228,7 +231,7 @@ function user_controller() if ($user_source['force_active']) { $tshirt_score = __('Enough'); } else { - $tshirt_score = sprintf('%.2f', User_tshirt_score($user_source)) . ' h'; + $tshirt_score = sprintf('%.2f', User_tshirt_score($user_source['UID'])) . ' h'; } return [ @@ -237,14 +240,14 @@ function user_controller() $user_source, in_array('admin_user', $privileges), User_is_freeloader($user_source), - User_angeltypes($user_source), - User_groups($user_source), + User_angeltypes($user_source['UID']), + User_groups($user_source['UID']), $shifts, $user['UID'] == $user_source['UID'], $tshirt_score, in_array('admin_active', $privileges), in_array('admin_user_worklog', $privileges), - UserWorkLogsForUser($user_source) + UserWorkLogsForUser($user_source['UID']) ) ]; } @@ -270,7 +273,7 @@ function users_list_controller() $users = Users($order_by); foreach ($users as &$user) { - $user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user)); + $user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user['UID'])); } return [ @@ -296,8 +299,8 @@ function users_list_controller() function user_password_recovery_set_new_controller() { $request = request(); - $user_source = User_by_password_recovery_token($request->input('token')); - if (empty($user_source)) { + $passwordReset = PasswordReset::whereToken($request->input('token')); + if (!$passwordReset) { error(__('Token is not correct.')); redirect(page_link_to('login')); } @@ -319,8 +322,9 @@ function user_password_recovery_set_new_controller() } if ($valid) { - set_password($user_source['UID'], $request->postData('password')); + set_password($passwordReset->user->id, $request->postData('password')); success(__('Password saved.')); + $passwordReset->delete(); redirect(page_link_to('login')); } } diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php index 8668cab0..4fc10226 100644 --- a/includes/helper/email_helper.php +++ b/includes/helper/email_helper.php @@ -1,19 +1,32 @@ user(); - if ($not_if_its_me && $user->id == $recipient_user['UID']) { + if ($recipientUser instanceof User) { + $id = $user->id; + $lang = $user->settings->language; + $email = $user->contact->email ? $user->contact->email : $user->email; + $username = $user->name; + } else { + $id = $recipientUser['UID']; + $lang = $recipientUser['Sprache']; + $email = $recipientUser['email']; + $username = $recipientUser['Nick']; + } + + if ($notIfItsMe && $user->id == $id) { return true; } @@ -23,12 +36,12 @@ function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_it /** @var EngelsystemMailer $mailer */ $mailer = app('mailer'); - $translator->setLocale($recipient_user['Sprache']); + $translator->setLocale($lang); $status = $mailer->sendView( - $recipient_user['email'], + $email, $title, 'emails/mail', - ['username' => $recipient_user['Nick'], 'message' => $message] + ['username' => $username, 'message' => $message] ); $translator->setLocale($locale); diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php index 0c4e381c..90153146 100644 --- a/includes/mailer/shifts_mailer.php +++ b/includes/mailer/shifts_mailer.php @@ -1,5 +1,7 @@ settings->email_shiftinfo) { return; } @@ -117,12 +119,12 @@ function mail_shift_assign($user, $shift) } /** - * @param array $user + * @param User $user * @param array $shift */ function mail_shift_removed($user, $shift) { - if (!$user['email_shiftinfo']) { + if (!$user->settings->email_shiftinfo) { return; } diff --git a/includes/mailer/users_mailer.php b/includes/mailer/users_mailer.php index 23a13806..6135bcf7 100644 --- a/includes/mailer/users_mailer.php +++ b/includes/mailer/users_mailer.php @@ -1,7 +1,9 @@ user(); DB::insert(' INSERT INTO `Shifts` ( `shifttype_id`, @@ -601,7 +601,7 @@ function Shift_create($shift) $shift['title'], $shift['URL'], $shift['PSID'], - $user['UID'], + $user->id, time(), time(), ] @@ -613,11 +613,11 @@ function Shift_create($shift) /** * Return users shifts. * - * @param array $user + * @param int $userId * @param bool $include_freeload_comments * @return array[] */ -function Shifts_by_user($user, $include_freeload_comments = false) +function Shifts_by_user($userId, $include_freeload_comments = false) { return DB::select(' SELECT @@ -640,7 +640,7 @@ function Shifts_by_user($user, $include_freeload_comments = false) ORDER BY `start` ', [ - $user['UID'] + $userId ] ); } diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index b1005095..943dbb5b 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -9,43 +9,43 @@ use Engelsystem\Database\DB; /** * Checks if a user joined an angeltype. * - * @param array $user The user to be checked + * @param int $userId The user to be checked * @param array $angeltype The angeltype to be checked * @return boolean */ -function UserAngelType_exists($user, $angeltype) +function UserAngelType_exists($userId, $angeltype) { return count(DB::select(' SELECT `id` FROM `UserAngelTypes` WHERE `UserAngelTypes`.`user_id`=? AND `angeltype_id`=? - ', [$user['UID'], $angeltype['id']])) > 0; + ', [$userId, $angeltype['id']])) > 0; } /** * List users angeltypes. * - * @param array $user + * @param int $userId * @return array[] */ -function User_angeltypes($user) +function User_angeltypes($userId) { return DB::select(' SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter` FROM `UserAngelTypes` JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id` WHERE `UserAngelTypes`.`user_id`=? - ', [$user['UID']]); + ', [$userId]); } /** * Gets unconfirmed user angeltypes for angeltypes of which the given user is a supporter. * - * @param array $user + * @param int $userId * @return array[] */ -function User_unconfirmed_AngelTypes($user) +function User_unconfirmed_AngelTypes($userId) { return DB::select(' SELECT @@ -61,7 +61,7 @@ function User_unconfirmed_AngelTypes($user) AND `UnconfirmedMembers`.`confirm_user_id` IS NULL GROUP BY `UserAngelTypes`.`angeltype_id`, `UserAngelTypes`.`id` ORDER BY `AngelTypes`.`name` - ', [$user['UID']]); + ', [$userId]); } /** @@ -126,32 +126,32 @@ function UserAngelTypes_delete_all($angeltype_id) /** * Confirm all unconfirmed UserAngelTypes for given Angeltype. * - * @param int $angeltype_id - * @param array $confirm_user + * @param int $angeltype_id + * @param int $confirm_user_id */ -function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) +function UserAngelTypes_confirm_all($angeltype_id, $confirm_user_id) { DB::update(' UPDATE `UserAngelTypes` SET `confirm_user_id`=? WHERE `angeltype_id`=? AND `confirm_user_id` IS NULL - ', [$confirm_user['UID'], $angeltype_id]); + ', [$confirm_user_id, $angeltype_id]); } /** * Confirm an UserAngelType with confirming user. * - * @param int $user_angeltype_id - * @param array $confirm_user + * @param int $user_angeltype_id + * @param int $confirm_user_id */ -function UserAngelType_confirm($user_angeltype_id, $confirm_user) +function UserAngelType_confirm($user_angeltype_id, $confirm_user_id) { DB::update(' UPDATE `UserAngelTypes` SET `confirm_user_id`=? WHERE `id`=? - LIMIT 1', [$confirm_user['UID'], $user_angeltype_id]); + LIMIT 1', [$confirm_user_id, $user_angeltype_id]); } /** @@ -170,18 +170,18 @@ function UserAngelType_delete($user_angeltype) /** * Create an UserAngelType. * - * @param array $user + * @param int $userId * @param array $angeltype * @return int */ -function UserAngelType_create($user, $angeltype) +function UserAngelType_create($userId, $angeltype) { DB::insert(' INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`, `supporter`) VALUES (?, ?, FALSE) ', [ - $user['UID'], + $userId, $angeltype['id'] ] ); @@ -209,11 +209,11 @@ function UserAngelType($user_angeltype_id) /** * Get an UserAngelType by user and angeltype. * - * @param array $user + * @param int $userId * @param array $angeltype * @return array|null */ -function UserAngelType_by_User_and_AngelType($user, $angeltype) +function UserAngelType_by_User_and_AngelType($userId, $angeltype) { $angelType = DB::selectOne(' SELECT * @@ -223,7 +223,7 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) LIMIT 1 ', [ - $user['UID'], + $userId, $angeltype['id'] ] ); @@ -234,16 +234,16 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) /** * Get an UserAngelTypes by user * - * @param array $user + * @param int $userId * @return array[]|null */ -function UserAngelTypes_by_User($user) +function UserAngelTypes_by_User($userId) { return DB::select(' SELECT * FROM `UserAngelTypes` WHERE `user_id`=? ', - [$user['UID']] + [$userId] ); } diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php index 2c251d66..1be6d4d2 100644 --- a/includes/model/UserDriverLicenses_model.php +++ b/includes/model/UserDriverLicenses_model.php @@ -57,12 +57,12 @@ function UserDriverLicense($user_id) * Create a user's driver license entry * * @param array $user_driver_license The UserDriverLicense to create - * @param array $user + * @param int $userId * @return array */ -function UserDriverLicenses_create($user_driver_license, $user) +function UserDriverLicenses_create($user_driver_license, $userId) { - $user_driver_license['user_id'] = $user['UID']; + $user_driver_license['user_id'] = $userId; DB::insert(' INSERT INTO `UserDriverLicenses` ( `user_id`, diff --git a/includes/model/UserGroups_model.php b/includes/model/UserGroups_model.php index 9d67770c..769871e9 100644 --- a/includes/model/UserGroups_model.php +++ b/includes/model/UserGroups_model.php @@ -5,10 +5,10 @@ use Engelsystem\Database\DB; /** * Returns users groups * - * @param array $user + * @param int $userId * @return array[] */ -function User_groups($user) +function User_groups($userId) { return DB::select(' SELECT `Groups`.* @@ -17,6 +17,6 @@ function User_groups($user) WHERE `UserGroups`.`uid`=? ORDER BY `UserGroups`.`group_id` ', - [$user['UID']] + [$userId] ); } diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index 46ab891e..c7de3f9e 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -21,13 +21,13 @@ function UserWorkLog($user_worklog_id) /** * Returns all work log entries for a user. * - * @param array $user + * @param int $userId * @return array[] */ -function UserWorkLogsForUser($user) +function UserWorkLogsForUser($userId) { return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [ - $user['UID'] + $userId ]); } @@ -123,10 +123,10 @@ function UserWorkLog_create($userWorkLog) /** * New user work log entry * - * @param array[] $user + * @param int $userId * @return array */ -function UserWorkLog_new($user) +function UserWorkLog_new($userId) { $work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', time())); @@ -137,7 +137,7 @@ function UserWorkLog_new($user) } return [ - 'user_id' => $user['UID'], + 'user_id' => $userId, 'work_timestamp' => $work_date, 'work_hours' => 0, 'comment' => '' diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 051f8ff6..bed6bf47 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -22,10 +22,10 @@ function User_delete($user_id) * Returns the tshirt score (number of hours counted for tshirt). * Accounts only ended shifts. * - * @param array[] $user + * @param int $userId * @return int */ -function User_tshirt_score($user) +function User_tshirt_score($userId) { $shift_sum_formula = User_get_shifts_sum_query(); $result_shifts = DB::selectOne(' @@ -36,7 +36,7 @@ function User_tshirt_score($user) AND `Shifts`.`end` < ? GROUP BY `User`.`UID` ', [ - $user['UID'], + $userId, time() ]); if (!isset($result_shifts['tshirt_score'])) { @@ -50,7 +50,7 @@ function User_tshirt_score($user) WHERE `User`.`UID` = ? AND `UserWorkLog`.`work_timestamp` < ? ', [ - $user['UID'], + $userId, time() ]); if (!isset($result_worklog['tshirt_score'])) { @@ -245,7 +245,7 @@ function User_is_freeloader($user) { global $user; - return count(ShiftEntries_freeloaded_by_user($user)) >= config('max_freeloadable_shifts'); + return count(ShiftEntries_freeloaded_by_user($user['UID'])) >= config('max_freeloadable_shifts'); } /** @@ -526,10 +526,10 @@ function User_generate_password_recovery_token(&$user) * @param array $user * @return float */ -function User_get_eligable_voucher_count(&$user) +function User_get_eligable_voucher_count($user) { $voucher_settings = config('voucher_settings'); - $shifts_done = count(ShiftEntries_finished_by_user($user)); + $shifts_done = count(ShiftEntries_finished_by_user($user['UID'])); $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers']; $eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 3a9ba8c4..33c7459d 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -1,6 +1,7 @@ has('active') && preg_match('/^\d+$/', $request->input('active'))) { $user_id = $request->input('active'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if ($user_source) { DB::update('UPDATE `User` SET `Aktiv`=1 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' is active now.'); $msg = success(__('Angel has been marked as active.'), true); @@ -110,8 +111,8 @@ function admin_active() } } elseif ($request->has('not_active') && preg_match('/^\d+$/', $request->input('not_active'))) { $user_id = $request->input('not_active'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { DB::update('UPDATE `User` SET `Aktiv`=0 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.'); $msg = success(__('Angel has been marked as not active.'), true); @@ -120,8 +121,8 @@ function admin_active() } } elseif ($request->has('tshirt') && preg_match('/^\d+$/', $request->input('tshirt'))) { $user_id = $request->input('tshirt'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { DB::update('UPDATE `User` SET `Tshirt`=1 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.'); $msg = success(__('Angel has got a t-shirt.'), true); @@ -130,8 +131,8 @@ function admin_active() } } elseif ($request->has('not_tshirt') && preg_match('/^\d+$/', $request->input('not_tshirt'))) { $user_id = $request->input('not_tshirt'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { DB::update('UPDATE `User` SET `Tshirt`=0 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.'); $msg = success(__('Angel has got no t-shirt.'), true); diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index 4f29b85d..62d74290 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -1,6 +1,7 @@ has('reset') && preg_match('/^\d+$/', $request->input('reset'))) { $user_id = $request->input('reset'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if ($user_source) { DB::update(' UPDATE `User` SET `Gekommen`=0, `arrival_date` = NULL @@ -36,14 +37,14 @@ function admin_arrive() ', [$user_id]); engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source)); success(__('Reset done. Angel has not arrived.')); - redirect(user_link($user_source['UID'])); + redirect(user_link($user_source->id)); } else { $msg = error(__('Angel not found.'), true); } } elseif ($request->has('arrived') && preg_match('/^\d+$/', $request->input('arrived'))) { $user_id = $request->input('arrived'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if ($user_source) { DB::update(' UPDATE `User` SET `Gekommen`=1, `arrival_date`=? @@ -52,7 +53,7 @@ function admin_arrive() ', [time(), $user_id]); engelsystem_log('User set has arrived: ' . User_Nick_render($user_source)); success(__('Angel has been marked as arrived.')); - redirect(user_link($user_source['UID'])); + redirect(user_link($user_source->id)); } else { $msg = error(__('Angel not found.'), true); } diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php index d387e06b..2e951dde 100644 --- a/includes/pages/admin_news.php +++ b/includes/pages/admin_news.php @@ -1,6 +1,7 @@ input('action')) { case 'edit': - $user_source = User($news['UID']); + $user_source = User::find($news['UID']); if ( !in_array('admin_news_html', $privileges) && strip_tags($news['Text']) != $news['Text'] diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index fc84ff9e..02f53d93 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -1,6 +1,7 @@ User_Nick_render($user_source), @@ -66,7 +67,7 @@ function admin_questions() $answered_questions_table = []; $questions = DB::select('SELECT * FROM `Questions` WHERE NOT `AID` IS NULL'); foreach ($questions as $question) { - $user_source = User($question['UID']); + $user_source = User::find($question['UID']); $answer_user_source = User($question['AID']); $answered_questions_table[] = [ 'from' => User_Nick_render($user_source), diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index b4dd9c1b..961d59a2 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -1,6 +1,7 @@ input('id'); if (!$request->has('action')) { - $user_source = User($user_id); - if (empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { error(__('This user does not exist.')); redirect(users_link()); } @@ -47,22 +48,20 @@ function admin_user() $html .= '' . "\n"; $html .= '' . "\n"; $html .= '' . "\n"; - $html .= ' ' . "\n"; + $html .= ' ' . "\n"; $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - if ($user_source['email_by_human_allowed']) { - $html .= " ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + if ($user_source->settings->email_human) { + $html .= " ' . "\n"; } - $html .= " ' . "\n"; $html .= ' ' . "\n"; + . html_select_key('size', 'eSize', $tshirt_sizes, $user_source->personalData->shirt_size, + __('Please select...')) . '' . "\n"; $options = [ '1' => __('Yes'), @@ -71,23 +70,21 @@ function admin_user() // Gekommen? $html .= ' ' . "\n"; + $html .= html_options('eGekommen', $options, $user_source->state->arrived) . '' . "\n"; // Aktiv? $html .= ' ' . "\n"; + $html .= html_options('eAktiv', $options, $user_source->state->active) . '' . "\n"; // Aktiv erzwingen if (in_array('admin_active', $privileges)) { $html .= ' ' . "\n"; + $html .= html_options('force_active', $options, $user_source->state->force_active) . '' . "\n"; } // T-Shirt bekommen? $html .= ' ' . "\n"; - - $html .= ' ' . "\n"; + $html .= html_options('eTshirt', $options, $user_source->personalData->shirt_size) . '' . "\n"; $html .= '
Nick' . '
Nick' . '
Last login

' - . date('Y-m-d H:i', $user_source['lastLogIn']) + . $user_source->last_login_at->format('Y-m-d H:i') . '

Name' . '
Vorname' . '
Alter' . '
Telefon' . '
Handy' . '
DECT' . '
email" . '
Name' . '
Vorname' . '
Handy' . '
DECT' . '
email" . '
jabber" . '
Size' - . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size'], __('Please select...')) . '
Gekommen' . "\n"; - $html .= html_options('eGekommen', $options, $user_source['Gekommen']) . '
Aktiv' . "\n"; - $html .= html_options('eAktiv', $options, $user_source['Aktiv']) . '
' . __('Force active') . '' . "\n"; - $html .= html_options('force_active', $options, $user_source['force_active']) . '
T-Shirt' . "\n"; - $html .= html_options('eTshirt', $options, $user_source['Tshirt']) . '
Hometown' . '
' . "\n" . ''; @@ -165,7 +162,7 @@ function admin_user() } $html .= buttons([ - button(user_delete_link($user_source['UID']), glyph('lock') . __('delete'), 'btn-danger') + button(user_delete_link($user_source->id), glyph('lock') . __('delete'), 'btn-danger') ]); $html .= "
"; @@ -227,7 +224,7 @@ function admin_user() $user_groups_info[] = $groups[$group]['Name']; } } - $user_source = User($user_id); + $user_source = User::find($user_id); engelsystem_log( 'Set groups of ' . User_Nick_render($user_source) . ' to: ' . join(', ', $user_groups_info) @@ -243,7 +240,7 @@ function admin_user() case 'save': $force_active = $user->state->force_active; - $user_source = User($user_id); + $user_source = User::find($user_id); if (in_array('admin_active', $privileges)) { $force_active = $request->input('force_active'); } @@ -252,37 +249,29 @@ function admin_user() `Nick` = ?, `Name` = ?, `Vorname` = ?, - `Telefon` = ?, `Handy` = ?, - `Alter` =?, `DECT` = ?, - ' . ($user_source['email_by_human_allowed'] + ' . ($user_source->settings->email_human ? '`email` = ' . DB::getPdo()->quote($request->postData('eemail')) . ',' : '') . ' - `jabber` = ?, `Size` = ?, `Gekommen`= ?, `Aktiv`= ?, `force_active`= ?, - `Tshirt` = ?, - `Hometown` = ? + `Tshirt` = ? WHERE `UID` = ? LIMIT 1'; DB::update($sql, [ User_validate_Nick($request->postData('eNick')), $request->postData('eName'), $request->postData('eVorname'), - $request->postData('eTelefon'), $request->postData('eHandy'), - $request->postData('eAlter'), $request->postData('eDECT'), - $request->postData('ejabber'), $request->postData('eSize'), $request->postData('eGekommen'), $request->postData('eAktiv'), $force_active, $request->postData('eTshirt'), - $request->postData('Hometown'), $user_id, ]); engelsystem_log( @@ -300,7 +289,7 @@ function admin_user() && $request->postData('new_pw') == $request->postData('new_pw2') ) { set_password($user_id, $request->postData('new_pw')); - $user_source = User($user_id); + $user_source = User::find($user_id); engelsystem_log('Set new password for ' . User_Nick_render($user_source)); $html .= success('Passwort neu gesetzt.', true); } else { diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 1bb39d01..32532c6f 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -2,6 +2,7 @@ use Carbon\Carbon; use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -264,7 +265,7 @@ function guest_register() } engelsystem_log( - 'User ' . User_Nick_render(User($user_id)) + 'User ' . User_Nick_render(User::find($user_id)) . ' signed up as: ' . join(', ', $user_angel_types_info) ); success(__('Angel registration successful!')); @@ -430,10 +431,10 @@ function guest_login() if ($request->has('submit')) { if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 0) { $nick = User_validate_Nick($request->input('nick')); - $login_user = DB::selectOne('SELECT * FROM `User` WHERE `Nick`=?', [$nick]); - if (!empty($login_user)) { + $login_user = User::whereName($nick); + if ($login_user) { if ($request->has('password')) { - if (!verify_password($request->postData('password'), $login_user['Passwort'], $login_user['UID'])) { + if (!verify_password($request->postData('password'), $login_user->password, $login_user->id)) { $valid = false; error(__('Your password is incorrect. Please try it again.')); } @@ -450,9 +451,9 @@ function guest_login() error(__('Please enter a nickname.')); } - if ($valid && !empty($login_user)) { - $session->set('uid', $login_user['UID']); - $session->set('locale', $login_user['Sprache']); + if ($valid && $login_user) { + $session->set('uid', $login_user->id); + $session->set('locale', $login_user->settings->language); redirect(page_link_to('news')); } diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php index d2034dc0..4431133e 100644 --- a/includes/pages/user_messages.php +++ b/includes/pages/user_messages.php @@ -1,6 +1,7 @@ user(); $request = request(); if (!$request->has('action')) { $users = DB::select( 'SELECT `UID`, `Nick` FROM `User` WHERE NOT `UID`=? ORDER BY `Nick`', - [$user['UID']] + [$user->id] ); $to_select_data = [ @@ -61,8 +62,8 @@ function user_messages() ORDER BY `isRead`,`Datum` DESC ', [ - $user['UID'], - $user['UID'], + $user->id, + $user->id, ] ); @@ -78,8 +79,8 @@ function user_messages() ]; foreach ($messages as $message) { - $sender_user_source = User($message['SUID']); - $receiver_user_source = User($message['RUID']); + $sender_user_source = User::find($message['SUID']); + $receiver_user_source = User::find($message['RUID']); $messages_table_entry = [ 'new' => $message['isRead'] == 'N' ? '' : '', @@ -89,7 +90,7 @@ function user_messages() 'text' => str_replace("\n", '
', $message['Text']) ]; - if ($message['RUID'] == $user['UID']) { + if ($message['RUID'] == $user->id) { if ($message['isRead'] == 'N') { $messages_table_entry['actions'] = button( page_link_to('user_messages', ['action' => 'read', 'id' => $message['id']]), @@ -134,7 +135,7 @@ function user_messages() 'SELECT `RUID` FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id] ); - if (!empty($message) && $message['RUID'] == $user['UID']) { + if (!empty($message) && $message['RUID'] == $user->id) { DB::update( 'UPDATE `Messages` SET `isRead`=\'Y\' WHERE `id`=? LIMIT 1', [$message_id] @@ -156,7 +157,7 @@ function user_messages() 'SELECT `SUID` FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id] ); - if (!empty($message) && $message['SUID'] == $user['UID']) { + if (!empty($message) && $message['SUID'] == $user->id) { DB::delete('DELETE FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]); redirect(page_link_to('user_messages')); } else { diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 2a8a5d5a..ab4b00b6 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -1,6 +1,7 @@ has('reset')) { if ($request->input('reset') == 'ack') { User_reset_api_key($user); success(__('Key changed.')); - redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id])); } return page_with_title(__('Reset API key'), [ error( @@ -68,7 +69,7 @@ function user_myshifts() ', [ $shift_entry_id, - $shifts_user['UID'], + $shifts_user->id, ] ); if (!empty($shift)) { @@ -87,7 +88,7 @@ function user_myshifts() } $comment = strip_request_item_nl('comment'); - $user_source = User($shift['UID']); + $user_source = User::find($shift['UID']); if ($valid) { ShiftEntry_update([ @@ -105,7 +106,7 @@ function user_myshifts() . '. Freeloaded: ' . ($freeloaded ? 'YES Comment: ' . $freeload_comment : 'NO') ); success(__('Shift saved.')); - redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id])); } } @@ -125,6 +126,6 @@ function user_myshifts() } } - redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id])); return ''; } diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index ac1f8b80..266018a0 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -1,6 +1,7 @@ ' . date('Y-m-d H:i', $news['Datum']) . ' '; - $user_source = User($news['UID']); - - $html .= User_Nick_render($user_source); + $html .= User_Nick_render(User::find($news['UID'])); if ($page != 'news_comments') { $html .= ' ' . ' ' @@ -171,7 +170,7 @@ function user_news_comments() [$nid] ); foreach ($comments as $comment) { - $user_source = User($comment['UID']); + $user_source = User::find($comment['UID']); $html .= '
'; $html .= '
' . nl2br(htmlspecialchars($comment['Text'])) . '
'; diff --git a/includes/pages/user_questions.php b/includes/pages/user_questions.php index 94922141..c269dbb1 100644 --- a/includes/pages/user_questions.php +++ b/includes/pages/user_questions.php @@ -1,6 +1,7 @@ id] ); foreach ($answered_questions as &$question) { - $answer_user_source = User($question['AID']); + $answer_user_source = User::find($question['AID']); $question['answer_user'] = User_Nick_render($answer_user_source); } diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index dc33d078..350394be 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -217,7 +217,7 @@ function view_user_shifts() } $ownTypes = []; - foreach (UserAngelTypes_by_User($user) as $type) { + foreach (UserAngelTypes_by_User($user['UID']) as $type) { $ownTypes[] = (int)$type['angeltype_id']; } diff --git a/includes/sys_log.php b/includes/sys_log.php index 513586e6..595e8b55 100644 --- a/includes/sys_log.php +++ b/includes/sys_log.php @@ -8,11 +8,11 @@ */ function engelsystem_log($message) { - global $user; $nick = "Guest"; $logger = app('logger'); + $user = auth()->user(); - if (isset($user)) { + if ($user) { $nick = User_Nick_render($user); } diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index 92447efd..bd13a390 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -75,10 +75,10 @@ function Shift_editor_info_render($shift) */ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null) { - global $user; + $user = auth()->user(); if (empty($user_angeltype)) { - $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + $user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype); } if ($angeltype['shift_signup_state']->isSignupAllowed()) { @@ -103,7 +103,8 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null) */ function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupState $shift_signup_state) { - global $user, $privileges; + global $privileges; + $user = auth()->user(); $shift_admin = in_array('admin_shifts', $privileges); $user_shift_admin = in_array('user_shifts_admin', $privileges); @@ -141,7 +142,7 @@ function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupSt $admin_rooms ? button(room_link($room), glyph('map-marker') . $room['Name']) : '', ]; } - $buttons[] = button(user_link($user['UID']), ' ' . __('My shifts')); + $buttons[] = button(user_link($user->id), ' ' . __('My shifts')); $content[] = buttons($buttons); $content[] = Shift_view_header($shift, $room); diff --git a/includes/view/UserAngelTypes_view.php b/includes/view/UserAngelTypes_view.php index 965a353a..0702a2b3 100644 --- a/includes/view/UserAngelTypes_view.php +++ b/includes/view/UserAngelTypes_view.php @@ -1,8 +1,10 @@ id), glyph('remove') . __('cancel')), button(user_worklog_delete_link($userWorkLog, [ 'confirmed' => 1 ]), glyph('ok') . __('delete'), 'btn-danger') diff --git a/includes/view/User_view.php b/includes/view/User_view.php index ccd5e5d2..6243d26e 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -145,7 +145,7 @@ function User_registration_success_view($event_welcome_message) /** * Gui for deleting user with password field. * - * @param array $user + * @param User $user * @return string */ function User_delete_view($user) @@ -153,7 +153,7 @@ function User_delete_view($user) return page_with_title(sprintf(__('Delete %s'), User_Nick_render($user)), [ msg(), buttons([ - button(user_edit_link($user['UID']), glyph('chevron-left') . __('back')) + button(user_edit_link($user->id), glyph('chevron-left') . __('back')) ]), error( __('Do you really want to delete the user including all his shifts and every other piece of his data?'), @@ -292,7 +292,7 @@ function User_shift_state_render($user) return ''; } - $upcoming_shifts = ShiftEntries_upcoming_for_user($user); + $upcoming_shifts = ShiftEntries_upcoming_for_user($user['UID']); if (empty($upcoming_shifts)) { return '' . __('Free') . ''; @@ -823,15 +823,25 @@ function User_groups_render($user_groups) /** * Render a user nickname. * - * @param array $user_source + * @param array|User $user * @return string */ -function User_Nick_render($user_source) +function User_Nick_render($user) { + if ($user instanceof User) { + $id = $user->id; + $name = $user->name; + $arrived = $user->state->arrived; + } else { + $id = $user['UID']; + $name = $user['Nick']; + $arrived = $user['Gekommen']; + } + return render_profile_link( - ' ' . htmlspecialchars($user_source['Nick']) . '
', - $user_source['UID'], - ($user_source['Gekommen'] ? '' : 'text-muted') + ' ' . htmlspecialchars($name) . '', + $id, + ($arrived ? '' : 'text-muted') ); } @@ -861,9 +871,7 @@ function render_profile_link($text, $user_id = null, $class = '') */ function render_user_departure_date_hint() { - global $user; - - if (!isset($user['planned_departure_date']) || empty($user['planned_departure_date'])) { + if (!auth()->user()->personalData->planned_departure_date) { $text = __('Please enter your planned date of departure on your settings page to give us a feeling for teardown capacities.'); return render_profile_link($text, null, 'alert-link'); } @@ -895,9 +903,9 @@ function render_user_freeloader_hint() */ function render_user_arrived_hint() { - global $user; + $user = auth()->user(); - if ($user['Gekommen'] == 0) { + if (!$user->state->arrived) { /** @var Carbon $buildup */ $buildup = config('buildup_start'); if (!empty($buildup) && $buildup->lessThan(new Carbon())) { @@ -913,9 +921,9 @@ function render_user_arrived_hint() */ function render_user_tshirt_hint() { - global $user; + $user = auth()->user(); - if (config('enable_tshirt_size') && $user['Size'] == '') { + if (config('enable_tshirt_size') && !$user->personalData->shirt_size) { $text = __('You need to specify a tshirt size in your settings!'); return render_profile_link($text, null, 'alert-link'); } @@ -928,9 +936,9 @@ function render_user_tshirt_hint() */ function render_user_dect_hint() { - global $user; + $user = auth()->user(); - if ($user['Gekommen'] == 1 && $user['DECT'] == '') { + if ($user->state->arrived && !$user->contact->dect) { $text = __('You need to specify a DECT phone number in your settings! If you don\'t have a DECT phone, just enter \'-\'.'); return render_profile_link($text, null, 'alert-link'); } diff --git a/src/Models/User/HasUserModel.php b/src/Models/User/HasUserModel.php index 89dbd642..d627e50d 100644 --- a/src/Models/User/HasUserModel.php +++ b/src/Models/User/HasUserModel.php @@ -6,7 +6,9 @@ use Engelsystem\Models\BaseModel; use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * @property integer $user_id + * @property integer $user_id + * + * @property-read \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User $user * * @method static \Illuminate\Database\Query\Builder|static whereUserId($value) */