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 .= '
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 | ' . ' |
" . ' | |
Name | ' . ' |
Vorname | ' . ' |
Handy | ' . ' |
DECT | ' . ' |
" . ' | |
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 | ' . ' |