Removed `User($id)` function 🎉

main
Igor Scheller 6 years ago committed by msquare
parent 89e62c95a7
commit 7c6afc2bfe

@ -105,7 +105,7 @@ function angeltype_delete_controller()
*/ */
function angeltype_edit_controller() function angeltype_edit_controller()
{ {
global $privileges, $user; global $privileges;
// In supporter mode only allow to modify description // In supporter mode only allow to modify description
$supporter_mode = !in_array('admin_angel_types', $privileges); $supporter_mode = !in_array('admin_angel_types', $privileges);
@ -115,7 +115,7 @@ function angeltype_edit_controller()
// Edit existing angeltype // Edit existing angeltype
$angeltype = load_angeltype(); $angeltype = load_angeltype();
if (!User_is_AngelType_supporter($user, $angeltype)) { if (!User_is_AngelType_supporter(auth()->user(), $angeltype)) {
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
} else { } else {
@ -178,15 +178,16 @@ function angeltype_edit_controller()
*/ */
function angeltype_controller() function angeltype_controller()
{ {
global $privileges, $user; global $privileges;
$user = auth()->user();
if (!in_array('angeltypes', $privileges)) { if (!in_array('angeltypes', $privileges)) {
redirect(page_link_to('/')); redirect(page_link_to('/'));
} }
$angeltype = load_angeltype(); $angeltype = load_angeltype();
$user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype);
$user_driver_license = UserDriverLicense($user['UID']); $user_driver_license = UserDriverLicense($user->id);
$members = Users_by_angeltype($angeltype); $members = Users_by_angeltype($angeltype);
$days = angeltype_controller_shiftsFilterDays($angeltype); $days = angeltype_controller_shiftsFilterDays($angeltype);

@ -35,7 +35,8 @@ function shift_entries_controller()
*/ */
function shift_entry_create_controller() function shift_entry_create_controller()
{ {
global $privileges, $user; global $privileges;
$user = auth()->user();
$request = request(); $request = request();
if (User_is_freeloader($user)) { if (User_is_freeloader($user)) {
@ -44,7 +45,7 @@ function shift_entry_create_controller()
$shift = Shift($request->input('shift_id')); $shift = Shift($request->input('shift_id'));
if (empty($shift)) { if (empty($shift)) {
redirect(user_link($user['UID'])); redirect(user_link($user->id));
} }
$angeltype = AngelType($request->input('angeltype_id')); $angeltype = AngelType($request->input('angeltype_id'));
@ -54,7 +55,7 @@ function shift_entry_create_controller()
} }
if (empty($angeltype)) { if (empty($angeltype)) {
redirect(user_link($user['UID'])); redirect(user_link($user->id));
} }
if (User_is_AngelType_supporter($user, $angeltype)) { if (User_is_AngelType_supporter($user, $angeltype)) {
@ -138,14 +139,13 @@ function shift_entry_create_controller_admin($shift, $angeltype)
*/ */
function shift_entry_create_controller_supporter($shift, $angeltype) function shift_entry_create_controller_supporter($shift, $angeltype)
{ {
global $user;
$request = request(); $request = request();
$signup_user = auth()->user();
$signup_user = $user;
if ($request->has('user_id')) { if ($request->has('user_id')) {
$signup_user = User($request->input('user_id')); $signup_user = User::find($request->input('user_id'));
} }
if (!UserAngelType_exists($signup_user['UID'], $angeltype)) { if (!UserAngelType_exists($signup_user->id, $angeltype)) {
error(__('User is not in angeltype.')); error(__('User is not in angeltype.'));
redirect(shift_link($shift)); redirect(shift_link($shift));
} }
@ -172,7 +172,7 @@ function shift_entry_create_controller_supporter($shift, $angeltype)
ShiftEntry_create([ ShiftEntry_create([
'SID' => $shift['SID'], 'SID' => $shift['SID'],
'TID' => $angeltype['id'], 'TID' => $angeltype['id'],
'UID' => $signup_user['UID'], 'UID' => $signup_user->id,
'Comment' => '', 'Comment' => '',
'freeloaded' => false, 'freeloaded' => false,
'freeload_comment' => '' 'freeload_comment' => ''
@ -227,10 +227,9 @@ function shift_entry_error_message(ShiftSignupState $shift_signup_state)
*/ */
function shift_entry_create_controller_user($shift, $angeltype) function shift_entry_create_controller_user($shift, $angeltype)
{ {
global $user;
$request = request(); $request = request();
$signup_user = $user; $signup_user = auth()->user();
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
$shift_signup_state = Shift_signup_allowed( $shift_signup_state = Shift_signup_allowed(
@ -253,14 +252,14 @@ function shift_entry_create_controller_user($shift, $angeltype)
ShiftEntry_create([ ShiftEntry_create([
'SID' => $shift['SID'], 'SID' => $shift['SID'],
'TID' => $angeltype['id'], 'TID' => $angeltype['id'],
'UID' => $signup_user['UID'], 'UID' => $signup_user->id,
'Comment' => $comment, 'Comment' => $comment,
'freeloaded' => false, 'freeloaded' => false,
'freeload_comment' => '' 'freeload_comment' => ''
]); ]);
if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user['UID'], $angeltype)) { if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user->id, $angeltype)) {
UserAngelType_create($signup_user['UID'], $angeltype); UserAngelType_create($signup_user->id, $angeltype);
} }
success(__('You are subscribed. Thank you!')); success(__('You are subscribed. Thank you!'));
@ -342,10 +341,10 @@ function shift_entry_delete_controller()
$shift = Shift($shiftEntry['SID']); $shift = Shift($shiftEntry['SID']);
$angeltype = AngelType($shiftEntry['TID']); $angeltype = AngelType($shiftEntry['TID']);
$signout_user = User($shiftEntry['UID']); $signout_user = User::find($shiftEntry['UID']);
if (!Shift_signout_allowed($shift, $angeltype, $signout_user)) { if (!Shift_signout_allowed($shift, $angeltype, $signout_user->id)) {
error(__('You are not allowed to remove this shift entry. If necessary, ask your supporter or heaven to do so.')); 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['UID'])); redirect(user_link($signout_user->id));
} }
if ($request->has('continue')) { if ($request->has('continue')) {
@ -354,10 +353,10 @@ function shift_entry_delete_controller()
redirect(shift_link($shift)); redirect(shift_link($shift));
} }
if ($user->id == $signout_user['UID']) { if ($user->id == $signout_user->id) {
return [ return [
ShiftEntry_delete_title(), ShiftEntry_delete_title(),
ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user) ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user->id)
]; ];
} }

@ -252,7 +252,8 @@ function shift_delete_controller()
*/ */
function shift_controller() function shift_controller()
{ {
global $user, $privileges; global $privileges;
$user = auth()->user();
$request = request(); $request = request();
if (!in_array('user_shifts', $privileges)) { if (!in_array('user_shifts', $privileges)) {
@ -272,7 +273,7 @@ function shift_controller()
$shifttype = ShiftType($shift['shifttype_id']); $shifttype = ShiftType($shift['shifttype_id']);
$room = Room($shift['RID']); $room = Room($shift['RID']);
$angeltypes = AngelTypes(); $angeltypes = AngelTypes();
$user_shifts = Shifts_by_user($user['UID']); $user_shifts = Shifts_by_user($user->id);
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0); $shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
foreach ($angeltypes as &$angeltype) { foreach ($angeltypes as &$angeltype) {

@ -43,7 +43,6 @@ function user_angeltypes_unconfirmed_hint()
*/ */
function user_angeltypes_delete_all_controller() function user_angeltypes_delete_all_controller()
{ {
global $user;
$request = request(); $request = request();
if (!$request->has('angeltype_id')) { if (!$request->has('angeltype_id')) {
@ -57,7 +56,7 @@ function user_angeltypes_delete_all_controller()
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
if (!User_is_AngelType_supporter($user, $angeltype)) { if (!User_is_AngelType_supporter(auth()->user(), $angeltype)) {
error(__('You are not allowed to delete all users for this angeltype.')); error(__('You are not allowed to delete all users for this angeltype.'));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
@ -83,7 +82,8 @@ function user_angeltypes_delete_all_controller()
*/ */
function user_angeltypes_confirm_all_controller() function user_angeltypes_confirm_all_controller()
{ {
global $user, $privileges; global $privileges;
$user = auth()->user();
$request = request(); $request = request();
if (!$request->has('angeltype_id')) { if (!$request->has('angeltype_id')) {
@ -103,7 +103,7 @@ function user_angeltypes_confirm_all_controller()
} }
if ($request->has('confirmed')) { if ($request->has('confirmed')) {
UserAngelTypes_confirm_all($angeltype['id'], $user['UID']); UserAngelTypes_confirm_all($angeltype['id'], $user->id);
engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype))); 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))); success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype)));
@ -123,7 +123,7 @@ function user_angeltypes_confirm_all_controller()
*/ */
function user_angeltype_confirm_controller() function user_angeltype_confirm_controller()
{ {
global $user; $user = auth()->user();
$request = request(); $request = request();
if (!$request->has('user_angeltype_id')) { if (!$request->has('user_angeltype_id')) {
@ -155,7 +155,7 @@ function user_angeltype_confirm_controller()
} }
if ($request->has('confirmed')) { if ($request->has('confirmed')) {
UserAngelType_confirm($user_angeltype['id'], $user['UID']); UserAngelType_confirm($user_angeltype['id'], $user->id);
engelsystem_log(sprintf( engelsystem_log(sprintf(
'%s confirmed for angeltype %s', '%s confirmed for angeltype %s',
@ -183,8 +183,8 @@ function user_angeltype_confirm_controller()
*/ */
function user_angeltype_delete_controller() function user_angeltype_delete_controller()
{ {
global $user;
$request = request(); $request = request();
$user = auth()->user();
if (!$request->has('user_angeltype_id')) { if (!$request->has('user_angeltype_id')) {
error(__('User angeltype doesn\'t exist.')); error(__('User angeltype doesn\'t exist.'));
@ -209,7 +209,7 @@ function user_angeltype_delete_controller()
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
if ($user['UID'] != $user_angeltype['user_id'] && !User_is_AngelType_supporter($user, $angeltype)) { if ($user->id != $user_angeltype['user_id'] && !User_is_AngelType_supporter($user, $angeltype)) {
error(__('You are not allowed to delete this users angeltype.')); error(__('You are not allowed to delete this users angeltype.'));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
@ -305,18 +305,17 @@ function user_angeltype_update_controller()
*/ */
function user_angeltype_add_controller() function user_angeltype_add_controller()
{ {
global $user;
$angeltype = load_angeltype(); $angeltype = load_angeltype();
// User is joining by itself // User is joining by itself
if (!User_is_AngelType_supporter($user, $angeltype)) { if (!User_is_AngelType_supporter(auth()->user(), $angeltype)) {
return user_angeltype_join_controller($angeltype); return user_angeltype_join_controller($angeltype);
} }
// Allow to add any user // Allow to add any user
// Default selection // Default selection
$user_source = $user; $user_source = auth()->user();
// Load possible users, that are not in the angeltype already // Load possible users, that are not in the angeltype already
$users_source = Users_by_angeltype_inverted($angeltype); $users_source = Users_by_angeltype_inverted($angeltype);
@ -324,8 +323,8 @@ function user_angeltype_add_controller()
if (request()->has('submit')) { if (request()->has('submit')) {
$user_source = load_user(); $user_source = load_user();
if (!UserAngelType_exists($user_source['UID'], $angeltype)) { if (!UserAngelType_exists($user_source->id, $angeltype)) {
$user_angeltype_id = UserAngelType_create($user_source['UID'], $angeltype); $user_angeltype_id = UserAngelType_create($user_source->id, $angeltype);
engelsystem_log(sprintf( engelsystem_log(sprintf(
'User %s added to %s.', 'User %s added to %s.',
@ -338,7 +337,7 @@ function user_angeltype_add_controller()
AngelType_name_render($angeltype) AngelType_name_render($angeltype)
)); ));
UserAngelType_confirm($user_angeltype_id, $user_source['UID']); UserAngelType_confirm($user_angeltype_id, $user_source->id);
engelsystem_log(sprintf( engelsystem_log(sprintf(
'User %s confirmed as %s.', 'User %s confirmed as %s.',
User_Nick_render($user_source), User_Nick_render($user_source),
@ -351,7 +350,7 @@ function user_angeltype_add_controller()
return [ return [
__('Add user to angeltype'), __('Add user to angeltype'),
UserAngelType_add_view($angeltype, $users_source, $user_source['UID']) UserAngelType_add_view($angeltype, $users_source, $user_source->id)
]; ];
} }

@ -1,5 +1,7 @@
<?php <?php
use Engelsystem\Models\User\User;
/** /**
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license * Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license
* information provided. * information provided.
@ -55,30 +57,31 @@ function user_driver_licenses_controller()
/** /**
* Link to user driver license edit page for given user. * Link to user driver license edit page for given user.
* *
* @param array $user * @param User $user
* @return string * @return string
*/ */
function user_driver_license_edit_link($user = null) function user_driver_license_edit_link($user = null)
{ {
if (empty($user)) { if (!$user) {
return page_link_to('user_driver_licenses'); return page_link_to('user_driver_licenses');
} }
return page_link_to('user_driver_licenses', ['user_id' => $user['UID']]);
return page_link_to('user_driver_licenses', ['user_id' => $user->id]);
} }
/** /**
* Loads the user for the driver license. * Loads the user for the driver license.
* *
* @return array * @return User
*/ */
function user_driver_license_load_user() function user_driver_license_load_user()
{ {
global $user; $user = auth()->user();
$request = request(); $request = request();
$user_source = $user; $user_source = $user;
if ($request->has('user_id')) { if ($request->has('user_id')) {
$user_source = User($request->input('user_id')); $user_source = User::find($request->input('user_id'));
if (empty($user_source)) { if (empty($user_source)) {
redirect(user_driver_license_edit_link()); redirect(user_driver_license_edit_link());
} }
@ -100,11 +103,11 @@ function user_driver_license_edit_controller()
$user_source = user_driver_license_load_user(); $user_source = user_driver_license_load_user();
// only privilege admin_user can edit other users driver license information // only privilege admin_user can edit other users driver license information
if ($user->id != $user_source['UID'] && !in_array('admin_user', $privileges)) { if ($user->id != $user_source->id && !in_array('admin_user', $privileges)) {
redirect(user_driver_license_edit_link()); redirect(user_driver_license_edit_link());
} }
$user_driver_license = UserDriverLicense($user_source['UID']); $user_driver_license = UserDriverLicense($user_source->id);
if (empty($user_driver_license)) { if (empty($user_driver_license)) {
$wants_to_drive = false; $wants_to_drive = false;
$user_driver_license = UserDriverLicense_new(); $user_driver_license = UserDriverLicense_new();
@ -124,26 +127,26 @@ function user_driver_license_edit_controller()
if (UserDriverLicense_valid($user_driver_license)) { if (UserDriverLicense_valid($user_driver_license)) {
if (empty($user_driver_license['user_id'])) { if (empty($user_driver_license['user_id'])) {
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source['UID']); $user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source->id);
} else { } else {
UserDriverLicenses_update($user_driver_license); UserDriverLicenses_update($user_driver_license);
} }
engelsystem_log('Driver license information updated.'); engelsystem_log('Driver license information updated.');
success(__('Your driver license information has been saved.')); success(__('Your driver license information has been saved.'));
redirect(user_link($user_source['UID'])); redirect(user_link($user_source->id));
} else { } else {
error(__('Please select at least one driving license.')); error(__('Please select at least one driving license.'));
} }
} elseif (!empty($user_driver_license['user_id'])) { } elseif (!empty($user_driver_license['user_id'])) {
UserDriverLicenses_delete($user_source['UID']); UserDriverLicenses_delete($user_source->id);
engelsystem_log('Driver license information removed.'); engelsystem_log('Driver license information removed.');
success(__('Your driver license information has been removed.')); success(__('Your driver license information has been removed.'));
redirect(user_link($user_source['UID'])); redirect(user_link($user_source->id));
} }
} }
return [ return [
sprintf(__('Edit %s driving license information'), $user_source['Nick']), sprintf(__('Edit %s driving license information'), $user_source->name),
UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license) UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
]; ];
} }

@ -45,7 +45,7 @@ function user_worklog_edit_controller()
if (empty($userWorkLog)) { if (empty($userWorkLog)) {
redirect(user_link($user->id)); redirect(user_link($user->id));
} }
$user_source = User($userWorkLog['user_id']); $user_source = User::find($userWorkLog['user_id']);
if ($request->has('submit')) { if ($request->has('submit')) {
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog); list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
@ -54,7 +54,7 @@ function user_worklog_edit_controller()
UserWorkLog_update($userWorkLog); UserWorkLog_update($userWorkLog);
success(__('Work log entry updated.')); success(__('Work log entry updated.'));
redirect(user_link($user_source['UID'])); redirect(user_link($user_source->id));
} }
} }
@ -113,12 +113,12 @@ function user_worklog_add_controller()
$user = auth()->user(); $user = auth()->user();
$request = request(); $request = request();
$user_source = User($request->input('user_id')); $user_source = User::find($request->input('user_id'));
if (empty($user_source)) { if (!$user_source) {
redirect(user_link($user->id)); redirect(user_link($user->id));
} }
$userWorkLog = UserWorkLog_new($user_source['UID']); $userWorkLog = UserWorkLog_new($user_source->id);
if ($request->has('submit')) { if ($request->has('submit')) {
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog); list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
@ -127,7 +127,7 @@ function user_worklog_add_controller()
UserWorkLog_create($userWorkLog); UserWorkLog_create($userWorkLog);
success(__('Work log entry created.')); success(__('Work log entry created.'));
redirect(user_link($user_source['UID'])); redirect(user_link($user_source->id));
} }
} }
@ -140,7 +140,7 @@ function user_worklog_add_controller()
/** /**
* Link to work log entry add for given user. * Link to work log entry add for given user.
* *
* @param array $user * @param User $user
* *
* @return string * @return string
*/ */
@ -148,7 +148,7 @@ function user_worklog_add_link($user)
{ {
return page_link_to('user_worklog', [ return page_link_to('user_worklog', [
'action' => 'add', 'action' => 'add',
'user_id' => $user['UID'] 'user_id' => $user->id,
]); ]);
} }

@ -135,11 +135,12 @@ function user_link($userId)
*/ */
function user_edit_vouchers_controller() function user_edit_vouchers_controller()
{ {
global $privileges, $user; global $privileges;
$user = auth()->user();
$request = request(); $request = request();
if ($request->has('user_id')) { if ($request->has('user_id')) {
$user_source = User($request->input('user_id')); $user_source = User::find($request->input('user_id'));
} else { } else {
$user_source = $user; $user_source = $user;
} }
@ -164,20 +165,19 @@ function user_edit_vouchers_controller()
} }
if ($valid) { if ($valid) {
$user_source['got_voucher'] = $vouchers; $user_source->state->got_voucher = $vouchers;
$user->state->save();
User_update($user_source);
success(__('Saved the number of vouchers.')); success(__('Saved the number of vouchers.'));
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers', engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers',
$user_source['got_voucher'])); $user_source->state->got_voucher));
redirect(user_link($user_source['UID'])); redirect(user_link($user_source->id));
} }
} }
return [ return [
sprintf(__('%s\'s vouchers'), $user_source['Nick']), sprintf(__('%s\'s vouchers'), $user_source->name),
User_edit_vouchers_view($user_source) User_edit_vouchers_view($user_source)
]; ];
} }
@ -187,19 +187,20 @@ function user_edit_vouchers_controller()
*/ */
function user_controller() function user_controller()
{ {
global $privileges, $user; global $privileges;
$user = auth()->user();
$request = request(); $request = request();
$user_source = $user; $user_source = $user;
if ($request->has('user_id')) { if ($request->has('user_id')) {
$user_source = User($request->input('user_id')); $user_source = User::find($request->input('user_id'));
if (empty($user_source)) { if (!$user_source) {
error(__('User not found.')); error(__('User not found.'));
redirect(page_link_to('/')); redirect(page_link_to('/'));
} }
} }
$shifts = Shifts_by_user($user_source['UID'], in_array('user_shifts_admin', $privileges)); $shifts = Shifts_by_user($user_source->id, in_array('user_shifts_admin', $privileges));
foreach ($shifts as &$shift) { foreach ($shifts as &$shift) {
// TODO: Move queries to model // TODO: Move queries to model
$shift['needed_angeltypes'] = DB::select(' $shift['needed_angeltypes'] = DB::select('
@ -224,30 +225,30 @@ function user_controller()
} }
} }
if ($user_source['api_key'] == '') { if (empty($user_source->api_key)) {
User_reset_api_key($user_source, false); User_reset_api_key($user_source, false);
} }
if ($user_source['force_active']) { if ($user_source->state->force_active) {
$tshirt_score = __('Enough'); $tshirt_score = __('Enough');
} else { } else {
$tshirt_score = sprintf('%.2f', User_tshirt_score($user_source['UID'])) . '&nbsp;h'; $tshirt_score = sprintf('%.2f', User_tshirt_score($user_source->id)) . '&nbsp;h';
} }
return [ return [
$user_source['Nick'], $user_source->name,
User_view( User_view(
$user_source, $user_source,
in_array('admin_user', $privileges), in_array('admin_user', $privileges),
User_is_freeloader($user_source), User_is_freeloader($user_source),
User_angeltypes($user_source['UID']), User_angeltypes($user_source->id),
User_groups($user_source['UID']), User_groups($user_source->id),
$shifts, $shifts,
$user['UID'] == $user_source['UID'], $user->id == $user_source->id,
$tshirt_score, $tshirt_score,
in_array('admin_active', $privileges), in_array('admin_active', $privileges),
in_array('admin_user_worklog', $privileges), in_array('admin_user_worklog', $privileges),
UserWorkLogsForUser($user_source['UID']) UserWorkLogsForUser($user_source->id)
) )
]; ];
} }
@ -406,7 +407,7 @@ function user_password_recovery_title()
/** /**
* Loads a user from param user_id. * Loads a user from param user_id.
* *
* return array * @return User
*/ */
function load_user() function load_user()
{ {
@ -415,8 +416,8 @@ function load_user()
redirect(page_link_to()); redirect(page_link_to());
} }
$user = User($request->input('user_id')); $user = User::find($request->input('user_id'));
if (empty($user)) { if (!$user) {
error(__('User doesn\'t exist.')); error(__('User doesn\'t exist.'));
redirect(page_link_to()); redirect(page_link_to());
} }

@ -1,6 +1,7 @@
<?php <?php
use Engelsystem\Database\DB; use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
use Engelsystem\ShiftsFilter; use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftSignupState; use Engelsystem\ShiftSignupState;
@ -301,7 +302,7 @@ function Shift_free_entries($needed_angeltype, $shift_entries)
/** /**
* Check if shift signup is allowed from the end users point of view (no admin like privileges) * Check if shift signup is allowed from the end users point of view (no admin like privileges)
* *
* @param array $user * @param User $user
* @param array $shift The shift * @param array $shift The shift
* @param array $angeltype The angeltype to which the user wants to sign up * @param array $angeltype The angeltype to which the user wants to sign up
* @param array|null $user_angeltype * @param array|null $user_angeltype
@ -321,12 +322,12 @@ function Shift_signup_allowed_angel(
) { ) {
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries); $free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
if (config('signup_requires_arrival') && !$user['Gekommen']) { if (config('signup_requires_arrival') && !$user->state->arrived) {
return new ShiftSignupState(ShiftSignupState::NOT_ARRIVED, $free_entries); return new ShiftSignupState(ShiftSignupState::NOT_ARRIVED, $free_entries);
} }
if (empty($user_shifts)) { if (empty($user_shifts)) {
$user_shifts = Shifts_by_user($user['UID']); $user_shifts = Shifts_by_user($user->id);
} }
$signed_up = false; $signed_up = false;
@ -352,7 +353,7 @@ function Shift_signup_allowed_angel(
} }
if (empty($user_angeltype)) { if (empty($user_angeltype)) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype);
} }
if ( if (
@ -417,12 +418,13 @@ function Shift_signup_allowed_admin($needed_angeltype, $shift_entries)
* *
* @param array $shift The shift * @param array $shift The shift
* @param array $angeltype The angeltype * @param array $angeltype The angeltype
* @param array $signout_user The user that was signed up for the shift * @param int $signout_user_id The user that was signed up for the shift
* @return bool * @return bool
*/ */
function Shift_signout_allowed($shift, $angeltype, $signout_user) function Shift_signout_allowed($shift, $angeltype, $signout_user_id)
{ {
global $user, $privileges; global $privileges;
$user = auth()->user();
// user shifts admin can sign out any user at any time // user shifts admin can sign out any user at any time
if (in_array('user_shifts_admin', $privileges)) { if (in_array('user_shifts_admin', $privileges)) {
@ -437,7 +439,7 @@ function Shift_signout_allowed($shift, $angeltype, $signout_user)
return true; return true;
} }
if ($signout_user['UID'] == $user['UID'] && $shift['start'] > time() + config('last_unsubscribe') * 3600) { if ($signout_user_id == $user->id && $shift['start'] > time() + config('last_unsubscribe') * 3600) {
return true; return true;
} }
@ -447,7 +449,7 @@ function Shift_signout_allowed($shift, $angeltype, $signout_user)
/** /**
* Check if an angel can sign up for given shift. * Check if an angel can sign up for given shift.
* *
* @param array $signup_user * @param User $signup_user
* @param array $shift The shift * @param array $shift The shift
* @param array $angeltype The angeltype to which the user wants to sign up * @param array $angeltype The angeltype to which the user wants to sign up
* @param array|null $user_angeltype * @param array|null $user_angeltype
@ -465,7 +467,7 @@ function Shift_signup_allowed(
$needed_angeltype, $needed_angeltype,
$shift_entries $shift_entries
) { ) {
global $user, $privileges; global $privileges;
if (in_array('user_shifts_admin', $privileges)) { if (in_array('user_shifts_admin', $privileges)) {
return Shift_signup_allowed_admin($needed_angeltype, $shift_entries); return Shift_signup_allowed_admin($needed_angeltype, $shift_entries);
@ -473,7 +475,7 @@ function Shift_signup_allowed(
if ( if (
in_array('shiftentry_edit_angeltype_supporter', $privileges) in_array('shiftentry_edit_angeltype_supporter', $privileges)
&& User_is_AngelType_supporter($user, $angeltype) && User_is_AngelType_supporter(auth()->user(), $angeltype)
) { ) {
return Shift_signup_allowed_angeltype_supporter($needed_angeltype, $shift_entries); return Shift_signup_allowed_angeltype_supporter($needed_angeltype, $shift_entries);
} }

@ -1,6 +1,7 @@
<?php <?php
use Engelsystem\Database\DB; use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/** /**
* User angeltypes model * User angeltypes model
@ -67,15 +68,13 @@ function User_unconfirmed_AngelTypes($userId)
/** /**
* Returns true if user is angeltype supporter or has privilege admin_user_angeltypes. * Returns true if user is angeltype supporter or has privilege admin_user_angeltypes.
* *
* @param array $user * @param User $user
* @param array $angeltype * @param array $angeltype
* @return bool * @return bool
*/ */
function User_is_AngelType_supporter(&$user, $angeltype) function User_is_AngelType_supporter($user, $angeltype)
{ {
if (!isset($user['privileges'])) { $privileges = privileges_for_user($user->id);
$user['privileges'] = privileges_for_user($user['UID']);
}
return (count(DB::select(' return (count(DB::select('
SELECT `id` SELECT `id`
@ -86,11 +85,11 @@ function User_is_AngelType_supporter(&$user, $angeltype)
LIMIT 1 LIMIT 1
', ',
[ [
$user['UID'], $user->id,
$angeltype['id'] $angeltype['id']
] ]
)) > 0) )) > 0)
|| in_array('admin_user_angeltypes', $user['privileges']); || in_array('admin_user_angeltypes', $privileges);
} }
/** /**

@ -2,6 +2,7 @@
use Carbon\Carbon; use Carbon\Carbon;
use Engelsystem\Database\Db; use Engelsystem\Database\Db;
use Engelsystem\Models\User\User;
/** /**
* Load a single work log entry. * Load a single work log entry.
@ -39,7 +40,7 @@ function UserWorkLogsForUser($userId)
*/ */
function UserWorkLog_delete($userWorkLog) function UserWorkLog_delete($userWorkLog)
{ {
$user_source = User($userWorkLog['user_id']); $user_source = User::find($userWorkLog['user_id']);
$result = Db::delete("DELETE FROM `UserWorkLog` WHERE `id`=?", [ $result = Db::delete("DELETE FROM `UserWorkLog` WHERE `id`=?", [
$userWorkLog['id'] $userWorkLog['id']
]); ]);
@ -62,7 +63,7 @@ function UserWorkLog_delete($userWorkLog)
*/ */
function UserWorkLog_update($userWorkLog) function UserWorkLog_update($userWorkLog)
{ {
$user_source = User($userWorkLog['user_id']); $user_source = User::find($userWorkLog['user_id']);
$result = Db::update("UPDATE `UserWorkLog` SET $result = Db::update("UPDATE `UserWorkLog` SET
`work_timestamp`=?, `work_timestamp`=?,
@ -95,7 +96,7 @@ function UserWorkLog_create($userWorkLog)
{ {
$user = Auth()->user(); $user = Auth()->user();
$user_source = User($userWorkLog['user_id']); $user_source = User::find($userWorkLog['user_id']);
$result = Db::insert("INSERT INTO `UserWorkLog` ( $result = Db::insert("INSERT INTO `UserWorkLog` (
`user_id`, `user_id`,

@ -2,6 +2,7 @@
use Carbon\Carbon; use Carbon\Carbon;
use Engelsystem\Database\DB; use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
use Engelsystem\ValidationResult; use Engelsystem\ValidationResult;
/** /**
@ -238,14 +239,12 @@ function Users($order_by = 'Nick')
/** /**
* Returns true if user is freeloader * Returns true if user is freeloader
* *
* @param array $user * @param User $user
* @return bool * @return bool
*/ */
function User_is_freeloader($user) function User_is_freeloader($user)
{ {
global $user; return count(ShiftEntries_freeloaded_by_user($user->id)) >= config('max_freeloadable_shifts');
return count(ShiftEntries_freeloaded_by_user($user['UID'])) >= config('max_freeloadable_shifts');
} }
/** /**
@ -418,19 +417,6 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de
return new ValidationResult(true, $planned_departure_date); return new ValidationResult(true, $planned_departure_date);
} }
/**
* Returns user by id.
*
* @param int $user_id UID
* @return array|null
*/
function User($user_id)
{
$user = DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]);
return empty($user) ? null : $user;
}
/** /**
* Returns User by api_key. * Returns User by api_key.
* *
@ -473,23 +459,13 @@ function User_by_password_recovery_token($token)
/** /**
* Generates a new api key for given user. * Generates a new api key for given user.
* *
* @param array $user * @param User $user
* @param bool $log * @param bool $log
*/ */
function User_reset_api_key(&$user, $log = true) function User_reset_api_key($user, $log = true)
{ {
$user['api_key'] = md5($user['Nick'] . time() . rand()); $user->api_key = md5($user->name . time() . rand());
DB::update(' $user->save();
UPDATE `User`
SET `api_key`=?
WHERE `UID`=?
LIMIT 1
',
[
$user['api_key'],
$user['UID']
]
);
if ($log) { if ($log) {
engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user))); engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user)));
@ -523,15 +499,15 @@ function User_generate_password_recovery_token(&$user)
} }
/** /**
* @param array $user * @param User $user
* @return float * @return float
*/ */
function User_get_eligable_voucher_count($user) function User_get_eligable_voucher_count($user)
{ {
$voucher_settings = config('voucher_settings'); $voucher_settings = config('voucher_settings');
$shifts_done = count(ShiftEntries_finished_by_user($user['UID'])); $shifts_done = count(ShiftEntries_finished_by_user($user->id));
$earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers']; $earned_vouchers = $user->state->got_voucher - $voucher_settings['initial_vouchers'];
$eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; $eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
if ($eligable_vouchers < 0) { if ($eligable_vouchers < 0) {
return 0; return 0;

@ -68,7 +68,7 @@ function admin_questions()
$questions = DB::select('SELECT * FROM `Questions` WHERE NOT `AID` IS NULL'); $questions = DB::select('SELECT * FROM `Questions` WHERE NOT `AID` IS NULL');
foreach ($questions as $question) { foreach ($questions as $question) {
$user_source = User::find($question['UID']); $user_source = User::find($question['UID']);
$answer_user_source = User($question['AID']); $answer_user_source = User::find($question['AID']);
$answered_questions_table[] = [ $answered_questions_table[] = [
'from' => User_Nick_render($user_source), 'from' => User_Nick_render($user_source),
'question' => str_replace("\n", '<br />', $question['Question']), 'question' => str_replace("\n", '<br />', $question['Question']),

@ -18,7 +18,8 @@ function myshifts_title()
*/ */
function user_myshifts() function user_myshifts()
{ {
global $user, $privileges; global $privileges;
$user = auth()->user();
$request = request(); $request = request();
if ( if (
@ -29,7 +30,7 @@ function user_myshifts()
) { ) {
$shift_entry_id = $request->input('id'); $shift_entry_id = $request->input('id');
} else { } else {
$shift_entry_id = $user['UID']; $shift_entry_id = $user->id;
} }
$shifts_user = User::find($shift_entry_id); $shifts_user = User::find($shift_entry_id);

@ -22,10 +22,9 @@ function shifts_title()
*/ */
function user_shifts() function user_shifts()
{ {
global $user;
$request = request(); $request = request();
if (User_is_freeloader($user)) { if (User_is_freeloader(auth()->user())) {
redirect(page_link_to('user_myshifts')); redirect(page_link_to('user_myshifts'));
} }
@ -169,7 +168,8 @@ function load_types()
*/ */
function view_user_shifts() function view_user_shifts()
{ {
global $user, $privileges, $ical_shifts; global $privileges, $ical_shifts;
$user = auth()->user();
$session = session(); $session = session();
$ical_shifts = []; $ical_shifts = [];
@ -193,7 +193,7 @@ function view_user_shifts()
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter); $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
if ($user['api_key'] == '') { if (empty($user->api_key)) {
User_reset_api_key($user, false); User_reset_api_key($user, false);
} }
@ -212,12 +212,12 @@ function view_user_shifts()
$end_day = date('Y-m-d', $shiftsFilter->getEndTime()); $end_day = date('Y-m-d', $shiftsFilter->getEndTime());
$end_time = date('H:i', $shiftsFilter->getEndTime()); $end_time = date('H:i', $shiftsFilter->getEndTime());
if (config('signup_requires_arrival') && !$user['Gekommen']) { if (config('signup_requires_arrival') && !$user->state->arrived) {
info(render_user_arrived_hint()); info(render_user_arrived_hint());
} }
$ownTypes = []; $ownTypes = [];
foreach (UserAngelTypes_by_User($user['UID']) as $type) { foreach (UserAngelTypes_by_User($user->id) as $type) {
$ownTypes[] = (int)$type['angeltype_id']; $ownTypes[] = (int)$type['angeltype_id'];
} }

@ -1,5 +1,6 @@
<?php <?php
use Engelsystem\Models\User\User;
use Engelsystem\ShiftCalendarRenderer; use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilterRenderer; use Engelsystem\ShiftsFilterRenderer;
@ -129,7 +130,7 @@ function AngelType_edit_view($angeltype, $supporter_mode)
* @param bool $admin_angeltypes * @param bool $admin_angeltypes
* @param bool $supporter * @param bool $supporter
* @param array|null $user_driver_license * @param array|null $user_driver_license
* @param array|null $user * @param User|null $user
* @return string * @return string
*/ */
function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user) function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user)
@ -322,7 +323,7 @@ function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
* @param bool $admin_angeltypes * @param bool $admin_angeltypes
* @param bool $supporter * @param bool $supporter
* @param array $user_driver_license * @param array $user_driver_license
* @param array $user * @param User $user
* @param ShiftsFilterRenderer $shiftsFilterRenderer * @param ShiftsFilterRenderer $shiftsFilterRenderer
* @param ShiftCalendarRenderer $shiftCalendarRenderer * @param ShiftCalendarRenderer $shiftCalendarRenderer
* @param int $tab The selected tab * @param int $tab The selected tab

@ -176,8 +176,6 @@ class ShiftCalendarRenderer
*/ */
private function renderLane(ShiftCalendarLane $lane) private function renderLane(ShiftCalendarLane $lane)
{ {
global $user;
$shift_renderer = new ShiftCalendarShiftRenderer(); $shift_renderer = new ShiftCalendarShiftRenderer();
$html = ''; $html = '';
$rendered_until = $this->getFirstBlockStartTime(); $rendered_until = $this->getFirstBlockStartTime();
@ -192,7 +190,7 @@ class ShiftCalendarRenderer
$shift, $shift,
$this->needed_angeltypes[$shift['SID']], $this->needed_angeltypes[$shift['SID']],
$this->shift_entries[$shift['SID']], $this->shift_entries[$shift['SID']],
$user auth()->user()
); );
$html .= $shift_html; $html .= $shift_html;
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW; $rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;

@ -2,6 +2,8 @@
namespace Engelsystem; namespace Engelsystem;
use Engelsystem\Models\User\User;
/** /**
* Renders a single shift for the shift calendar * Renders a single shift for the shift calendar
*/ */
@ -13,7 +15,7 @@ class ShiftCalendarShiftRenderer
* @param array $shift The shift to render * @param array $shift The shift to render
* @param array $needed_angeltypes * @param array $needed_angeltypes
* @param array $shift_entries * @param array $shift_entries
* @param array $user The user who is viewing the shift calendar * @param User $user The user who is viewing the shift calendar
* @return array * @return array
*/ */
public function render($shift, $needed_angeltypes, $shift_entries, $user) public function render($shift, $needed_angeltypes, $shift_entries, $user)
@ -90,7 +92,7 @@ class ShiftCalendarShiftRenderer
* @param array $shift * @param array $shift
* @param array[] $needed_angeltypes * @param array[] $needed_angeltypes
* @param array[] $shift_entries * @param array[] $shift_entries
* @param array $user * @param User $user
* @return array * @return array
*/ */
private function renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user) private function renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user)
@ -156,7 +158,7 @@ class ShiftCalendarShiftRenderer
* @param array[] $shift_entries * @param array[] $shift_entries
* @param array[] $angeltype The angeltype, containing information about needed angeltypes * @param array[] $angeltype The angeltype, containing information about needed angeltypes
* and already signed up angels * and already signed up angels
* @param array $user The user who is viewing the shift calendar * @param User $user The user who is viewing the shift calendar
* @return array * @return array
*/ */
private function renderShiftNeededAngeltype($shift, $shift_entries, $angeltype, $user) private function renderShiftNeededAngeltype($shift, $shift_entries, $angeltype, $user)

@ -1,12 +1,14 @@
<?php <?php
use Engelsystem\Models\User\User;
/** /**
* Sign off from an user from a shift with admin permissions, asking for ack. * Sign off from an user from a shift with admin permissions, asking for ack.
* *
* @param array $shiftEntry * @param array $shiftEntry
* @param array $shift * @param array $shift
* @param array $angeltype * @param array $angeltype
* @param array $signoff_user * @param User $signoff_user
* *
* @return string HTML * @return string HTML
*/ */
@ -22,7 +24,7 @@ function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_
$angeltype['name'] $angeltype['name']
), true), ), true),
buttons([ buttons([
button(user_link($signoff_user['UID']), glyph('remove') . __('cancel')), button(user_link($signoff_user->id), glyph('remove') . __('cancel')),
button(shift_entry_delete_link($shiftEntry, [ button(shift_entry_delete_link($shiftEntry, [
'continue' => 1 'continue' => 1
]), glyph('ok') . __('delete'), 'btn-danger') ]), glyph('ok') . __('delete'), 'btn-danger')
@ -36,11 +38,11 @@ function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_
* @param array $shiftEntry * @param array $shiftEntry
* @param array $shift * @param array $shift
* @param array $angeltype * @param array $angeltype
* @param array $signoff_user * @param int $signoff_user_id
* *
* @return string HTML * @return string HTML
*/ */
function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user) function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user_id)
{ {
return page_with_title(ShiftEntry_delete_title(), [ return page_with_title(ShiftEntry_delete_title(), [
info(sprintf( info(sprintf(
@ -51,7 +53,7 @@ function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user)
$angeltype['name'] $angeltype['name']
), true), ), true),
buttons([ buttons([
button(user_link($signoff_user['UID']), glyph('remove') . __('cancel')), button(user_link($signoff_user_id), glyph('remove') . __('cancel')),
button(shift_entry_delete_link($shiftEntry, [ button(shift_entry_delete_link($shiftEntry, [
'continue' => 1 'continue' => 1
]), glyph('ok') . __('delete'), 'btn-danger') ]), glyph('ok') . __('delete'), 'btn-danger')
@ -100,7 +102,7 @@ function ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_sel
* @param array $shift * @param array $shift
* @param array $room * @param array $room
* @param array $angeltype * @param array $angeltype
* @param array $signup_user * @param User $signup_user
* @param array $users_select * @param array $users_select
* @return string * @return string
*/ */
@ -113,7 +115,7 @@ function ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_use
info(sprintf(__('Do you want to sign up the following user for this shift as %s?'), info(sprintf(__('Do you want to sign up the following user for this shift as %s?'),
AngelType_name_render($angeltype)), true), AngelType_name_render($angeltype)), true),
form([ form([
form_select('user_id', __('User'), $users_select, $signup_user['UID']), form_select('user_id', __('User'), $users_select, $signup_user->id),
form_submit('submit', glyph('ok') . __('Save')) form_submit('submit', glyph('ok') . __('Save'))
]) ])
]); ]);

@ -1,5 +1,6 @@
<?php <?php
use Engelsystem\Models\User\User;
use Engelsystem\ShiftSignupState; use Engelsystem\ShiftSignupState;
/** /**
@ -54,14 +55,14 @@ function Shift_editor_info_render($shift)
$info[] = sprintf( $info[] = sprintf(
glyph('plus') . __('created at %s by %s'), glyph('plus') . __('created at %s by %s'),
date('Y-m-d H:i', $shift['created_at_timestamp']), date('Y-m-d H:i', $shift['created_at_timestamp']),
User_Nick_render(User($shift['created_by_user_id'])) User_Nick_render(User::find($shift['created_by_user_id']))
); );
} }
if (!empty($shift['edited_by_user_id'])) { if (!empty($shift['edited_by_user_id'])) {
$info[] = sprintf( $info[] = sprintf(
glyph('pencil') . __('edited at %s by %s'), glyph('pencil') . __('edited at %s by %s'),
date('Y-m-d H:i', $shift['edited_at_timestamp']), date('Y-m-d H:i', $shift['edited_at_timestamp']),
User_Nick_render(User($shift['edited_by_user_id'])) User_Nick_render(User::find($shift['edited_by_user_id']))
); );
} }
return join('<br />', $info); return join('<br />', $info);
@ -176,10 +177,8 @@ function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupSt
*/ */
function Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin) function Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin)
{ {
global $user;
$angeltype = $angeltypes[$needed_angeltype['TID']]; $angeltype = $angeltypes[$needed_angeltype['TID']];
$angeltype_supporter = User_is_AngelType_supporter($user, $angeltype); $angeltype_supporter = User_is_AngelType_supporter(auth()->user(), $angeltype);
$needed_angels = ''; $needed_angels = '';
@ -226,7 +225,7 @@ function Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shi
*/ */
function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter) function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter)
{ {
$entry = User_Nick_render(User($shift_entry['UID'])); $entry = User_Nick_render(User::find($shift_entry['UID']));
if ($shift_entry['freeloaded']) { if ($shift_entry['freeloaded']) {
$entry = '<del>' . $entry . '</del>'; $entry = '<del>' . $entry . '</del>';
} }

@ -1,9 +1,11 @@
<?php <?php
use Engelsystem\Models\User\User;
/** /**
* Edit a user's driving license information. * Edit a user's driving license information.
* *
* @param array $user_source The user * @param User $user_source The user
* @param bool $wants_to_drive true, if the user wants to drive * @param bool $wants_to_drive true, if the user wants to drive
* @param array $user_driver_license The user driver license * @param array $user_driver_license The user driver license
* @return string * @return string
@ -12,7 +14,7 @@ function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver
{ {
return page_with_title(sprintf(__('Edit %s driving license information'), User_Nick_render($user_source)), [ return page_with_title(sprintf(__('Edit %s driving license information'), User_Nick_render($user_source)), [
buttons([ buttons([
button(user_link($user_source['UID']), __('Back to profile'), 'back') button(user_link($user_source->id), __('Back to profile'), 'back')
]), ]),
msg(), msg(),
form([ form([

@ -36,7 +36,7 @@ function UserWorkLog_delete_title()
/** /**
* Render edit table. * Render edit table.
* *
* @param array $user_source * @param User $user_source
* @param array $userWorkLog * @param array $userWorkLog
* @return string * @return string
*/ */
@ -54,7 +54,7 @@ function UserWorkLog_edit_form($user_source, $userWorkLog)
/** /**
* Form for edit a user work log entry. * Form for edit a user work log entry.
* *
* @param array $user_source * @param User $user_source
* @param array $userWorkLog * @param array $userWorkLog
* @return string * @return string
*/ */
@ -62,7 +62,7 @@ function UserWorkLog_edit_view($user_source, $userWorkLog)
{ {
return page_with_title(UserWorkLog_edit_title(), [ return page_with_title(UserWorkLog_edit_title(), [
buttons([ buttons([
button(user_link($user_source['UID']), __('back')) button(user_link($user_source->id), __('back'))
]), ]),
msg(), msg(),
UserWorkLog_edit_form($user_source, $userWorkLog) UserWorkLog_edit_form($user_source, $userWorkLog)
@ -72,7 +72,7 @@ function UserWorkLog_edit_view($user_source, $userWorkLog)
/** /**
* Form for adding a user work log entry. * Form for adding a user work log entry.
* *
* @param array $user_source * @param User $user_source
* @param array $userWorkLog * @param array $userWorkLog
* @return string * @return string
*/ */
@ -80,7 +80,7 @@ function UserWorkLog_add_view($user_source, $userWorkLog)
{ {
return page_with_title(UserWorkLog_add_title(), [ return page_with_title(UserWorkLog_add_title(), [
buttons([ buttons([
button(user_link($user_source['UID']), __('back')) button(user_link($user_source->id), __('back'))
]), ]),
msg(), msg(),
UserWorkLog_edit_form($user_source, $userWorkLog) UserWorkLog_edit_form($user_source, $userWorkLog)

@ -169,7 +169,7 @@ function User_delete_view($user)
/** /**
* View for editing the number of given vouchers * View for editing the number of given vouchers
* *
* @param array $user * @param User $user
* @return string * @return string
*/ */
function User_edit_vouchers_view($user) function User_edit_vouchers_view($user)
@ -177,7 +177,7 @@ function User_edit_vouchers_view($user)
return page_with_title(sprintf(__('%s\'s vouchers'), User_Nick_render($user)), [ return page_with_title(sprintf(__('%s\'s vouchers'), User_Nick_render($user)), [
msg(), msg(),
buttons([ buttons([
button(user_link($user['UID']), glyph('chevron-left') . __('back')) button(user_link($user->id), glyph('chevron-left') . __('back'))
]), ]),
info(sprintf( info(sprintf(
__('Angel should receive at least %d vouchers.'), __('Angel should receive at least %d vouchers.'),
@ -185,10 +185,10 @@ function User_edit_vouchers_view($user)
), true), ), true),
form( form(
[ [
form_spinner('vouchers', __('Number of vouchers given out'), $user['got_voucher']), form_spinner('vouchers', __('Number of vouchers given out'), $user->state->got_voucher),
form_submit('submit', __('Save')) form_submit('submit', __('Save'))
], ],
page_link_to('users', ['action' => 'edit_vouchers', 'user_id' => $user['UID']]) page_link_to('users', ['action' => 'edit_vouchers', 'user_id' => $user->id])
) )
]); ]);
} }
@ -275,7 +275,7 @@ function Users_table_header_link($column, $label, $order_by)
} }
/** /**
* @param array $user * @param User|array $user
* @return string|false * @return string|false
*/ */
function User_shift_state_render($user) function User_shift_state_render($user)
@ -349,7 +349,7 @@ function User_view_shiftentries($needed_angel_type)
* Helper that renders a shift line for user view * Helper that renders a shift line for user view
* *
* @param array $shift * @param array $shift
* @param array $user_source * @param User $user_source
* @param bool $its_me * @param bool $its_me
* @return array * @return array
*/ */
@ -398,12 +398,12 @@ function User_view_myshift($shift, $user_source, $its_me)
]; ];
if ($its_me || in_array('user_shifts_admin', $privileges)) { if ($its_me || in_array('user_shifts_admin', $privileges)) {
$myshift['actions'][] = button( $myshift['actions'][] = button(
page_link_to('user_myshifts', ['edit' => $shift['id'], 'id' => $user_source['UID']]), page_link_to('user_myshifts', ['edit' => $shift['id'], 'id' => $user_source->id]),
glyph('edit') . __('edit'), glyph('edit') . __('edit'),
'btn-xs' 'btn-xs'
); );
} }
if (Shift_signout_allowed($shift, ['id' => $shift['TID']], $user_source)) { if (Shift_signout_allowed($shift, ['id' => $shift['TID']], $user_source->id)) {
$myshift['actions'][] = button( $myshift['actions'][] = button(
shift_entry_delete_link($shift), shift_entry_delete_link($shift),
glyph('trash') . __('sign off'), glyph('trash') . __('sign off'),
@ -419,7 +419,7 @@ function User_view_myshift($shift, $user_source, $its_me)
* Helper that prepares the shift table for user view * Helper that prepares the shift table for user view
* *
* @param array[] $shifts * @param array[] $shifts
* @param array $user_source * @param User $user_source
* @param bool $its_me * @param bool $its_me
* @param int $tshirt_score * @param int $tshirt_score
* @param bool $tshirt_admin * @param bool $tshirt_admin
@ -510,7 +510,7 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege)
'comment' => $worklog['comment'] . '<br>' 'comment' => $worklog['comment'] . '<br>'
. sprintf( . sprintf(
__('Added by %s at %s'), __('Added by %s at %s'),
User_Nick_render(User($worklog['created_user_id'])), User_Nick_render(User::find($worklog['created_user_id'])),
date('Y-m-d H:i', $worklog['created_timestamp']) date('Y-m-d H:i', $worklog['created_timestamp'])
), ),
'actions' => $actions 'actions' => $actions
@ -520,7 +520,7 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege)
/** /**
* Renders view for a single user * Renders view for a single user
* *
* @param array $user_source * @param User $user_source
* @param bool $admin_user_privilege * @param bool $admin_user_privilege
* @param bool $freeloader * @param bool $freeloader
* @param array[] $user_angeltypes * @param array[] $user_angeltypes
@ -547,7 +547,9 @@ function User_view(
$user_worklogs $user_worklogs
) { ) {
$nightShiftsConfig = config('night_shifts'); $nightShiftsConfig = config('night_shifts');
$user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']); $user_name = htmlspecialchars(
$user_source->personalData->first_name) . ' ' . htmlspecialchars($user_source->personalData->last_name
);
$myshifts_table = ''; $myshifts_table = '';
if ($its_me || $admin_user_privilege) { if ($its_me || $admin_user_privilege) {
$my_shifts = User_view_myshifts( $my_shifts = User_view_myshifts(
@ -568,14 +570,14 @@ function User_view(
'comment' => __('Comment'), 'comment' => __('Comment'),
'actions' => __('Action') 'actions' => __('Action')
], $my_shifts); ], $my_shifts);
} elseif ($user_source['force_active']) { } elseif ($user_source->state->force_active) {
$myshifts_table = success(__('You have done enough to get a t-shirt.'), true); $myshifts_table = success(__('You have done enough to get a t-shirt.'), true);
} }
} }
return page_with_title( return page_with_title(
'<span class="icon-icon_angel"></span> ' '<span class="icon-icon_angel"></span> '
. htmlspecialchars($user_source['Nick']) . htmlspecialchars($user_source->name)
. ' <small>' . $user_name . '</small>', . ' <small>' . $user_name . '</small>',
[ [
msg(), msg(),
@ -583,21 +585,21 @@ function User_view(
div('col-md-12', [ div('col-md-12', [
buttons([ buttons([
$admin_user_privilege ? button( $admin_user_privilege ? button(
page_link_to('admin_user', ['id' => $user_source['UID']]), page_link_to('admin_user', ['id' => $user_source->id]),
glyph('edit') . __('edit') glyph('edit') . __('edit')
) : '', ) : '',
$admin_user_privilege ? button( $admin_user_privilege ? button(
user_driver_license_edit_link($user_source), user_driver_license_edit_link($user_source),
glyph('road') . __('driving license') glyph('road') . __('driving license')
) : '', ) : '',
($admin_user_privilege && !$user_source['Gekommen']) ? button( ($admin_user_privilege && !$user_source->state->arrived) ? button(
page_link_to('admin_arrive', ['arrived' => $user_source['UID']]), page_link_to('admin_arrive', ['arrived' => $user_source->id]),
__('arrived') __('arrived')
) : '', ) : '',
$admin_user_privilege ? button( $admin_user_privilege ? button(
page_link_to( page_link_to(
'users', 'users',
['action' => 'edit_vouchers', 'user_id' => $user_source['UID']] ['action' => 'edit_vouchers', 'user_id' => $user_source->id]
), ),
glyph('cutlery') . __('Edit vouchers') glyph('cutlery') . __('Edit vouchers')
) : '', ) : '',
@ -610,11 +612,11 @@ function User_view(
glyph('list-alt') . __('Settings') glyph('list-alt') . __('Settings')
) : '', ) : '',
$its_me ? button( $its_me ? button(
page_link_to('ical', ['key' => $user_source['api_key']]), page_link_to('ical', ['key' => $user_source->api_key]),
glyph('calendar') . __('iCal Export') glyph('calendar') . __('iCal Export')
) : '', ) : '',
$its_me ? button( $its_me ? button(
page_link_to('shifts_json_export', ['key' => $user_source['api_key']]), page_link_to('shifts_json_export', ['key' => $user_source->api_key]),
glyph('export') . __('JSON Export') glyph('export') . __('JSON Export')
) : '', ) : '',
$its_me ? button( $its_me ? button(
@ -626,7 +628,7 @@ function User_view(
]), ]),
div('row', [ div('row', [
div('col-md-3', [ div('col-md-3', [
heading(glyph('phone') . $user_source['DECT'], 1) heading(glyph('phone') . $user_source->contact->dect, 1)
]), ]),
User_view_state($admin_user_privilege, $freeloader, $user_source), User_view_state($admin_user_privilege, $freeloader, $user_source),
User_angeltypes_render($user_angeltypes), User_angeltypes_render($user_angeltypes),
@ -658,7 +660,7 @@ function User_view(
* *
* @param bool $admin_user_privilege * @param bool $admin_user_privilege
* @param bool $freeloader * @param bool $freeloader
* @param array $user_source * @param User $user_source
* @return string * @return string
*/ */
function User_view_state($admin_user_privilege, $freeloader, $user_source) function User_view_state($admin_user_privilege, $freeloader, $user_source)
@ -678,7 +680,7 @@ function User_view_state($admin_user_privilege, $freeloader, $user_source)
/** /**
* Render the state section of user view for users. * Render the state section of user view for users.
* *
* @param array $user_source * @param User $user_source
* @return array * @return array
*/ */
function User_view_state_user($user_source) function User_view_state_user($user_source)
@ -687,7 +689,7 @@ function User_view_state_user($user_source)
User_shift_state_render($user_source) User_shift_state_render($user_source)
]; ];
if ($user_source['Gekommen']) { if ($user_source->state->arrived) {
$state[] = '<span class="text-success">' . glyph('home') . __('Arrived') . '</span>'; $state[] = '<span class="text-success">' . glyph('home') . __('Arrived') . '</span>';
} else { } else {
$state[] = '<span class="text-danger">' . __('Not arrived') . '</span>'; $state[] = '<span class="text-danger">' . __('Not arrived') . '</span>';
@ -701,7 +703,7 @@ function User_view_state_user($user_source)
* Render the state section of user view for admins. * Render the state section of user view for admins.
* *
* @param bool $freeloader * @param bool $freeloader
* @param array $user_source * @param User $user_source
* @return array * @return array
*/ */
function User_view_state_admin($freeloader, $user_source) function User_view_state_admin($freeloader, $user_source)
@ -714,29 +716,37 @@ function User_view_state_admin($freeloader, $user_source)
$state[] = User_shift_state_render($user_source); $state[] = User_shift_state_render($user_source);
if ($user_source['Gekommen']) { if ($user_source->state->arrived) {
$state[] = '<span class="text-success">' . glyph('home') $state[] = '<span class="text-success">' . glyph('home')
. sprintf(__('Arrived at %s'), date('Y-m-d', $user_source['arrival_date'])) . sprintf(
__('Arrived at %s'),
$user_source->personalData->arrival_date ? $user_source->personalData->arrival_date->format('Y-m-d') : ''
)
. '</span>'; . '</span>';
if ($user_source['force_active']) { if ($user_source->state->force_active) {
$state[] = '<span class="text-success">' . __('Active (forced)') . '</span>'; $state[] = '<span class="text-success">' . __('Active (forced)') . '</span>';
} elseif ($user_source['Aktiv']) { } elseif ($user_source->state->active) {
$state[] = '<span class="text-success">' . __('Active') . '</span>'; $state[] = '<span class="text-success">' . __('Active') . '</span>';
} }
if ($user_source['Tshirt']) { if ($user_source->personalData->shirt_size) {
$state[] = '<span class="text-success">' . __('T-Shirt') . '</span>'; $state[] = '<span class="text-success">' . __('T-Shirt') . '</span>';
} }
} else { } else {
$arrivalDate = $user_source->personalData->planned_arrival_date;
$state[] = '<span class="text-danger">' $state[] = '<span class="text-danger">'
. sprintf(__('Not arrived (Planned: %s)'), date('Y-m-d', $user_source['planned_arrival_date'])) . sprintf(
__('Not arrived (Planned: %s)'),
$arrivalDate ? $arrivalDate->format('Y-m-d') : ''
)
. '</span>'; . '</span>';
} }
if ($user_source['got_voucher'] > 0) { if ($user_source->state->got_voucher > 0) {
$voucherCount = $user_source->state->got_voucher;
$state[] = '<span class="text-success">' $state[] = '<span class="text-success">'
. glyph('cutlery') . glyph('cutlery')
. _e('Got %s voucher', 'Got %s vouchers', $user_source['got_voucher'], [$user_source['got_voucher']]) . _e('Got %s voucher', 'Got %s vouchers', $voucherCount, [$voucherCount])
. '</span>'; . '</span>';
} else { } else {
$state[] = '<span class="text-danger">' . __('Got no vouchers') . '</span>'; $state[] = '<span class="text-danger">' . __('Got no vouchers') . '</span>';
@ -884,9 +894,7 @@ function render_user_departure_date_hint()
*/ */
function render_user_freeloader_hint() function render_user_freeloader_hint()
{ {
global $user; if (User_is_freeloader(auth()->user())) {
if (User_is_freeloader($user)) {
return sprintf( return sprintf(
__('You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again.'), __('You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again.'),
config('max_freeloadable_shifts') config('max_freeloadable_shifts')

Loading…
Cancel
Save