summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/controller/angeltypes_controller.php11
-rw-r--r--includes/controller/shift_entries_controller.php35
-rw-r--r--includes/controller/shifts_controller.php5
-rw-r--r--includes/controller/user_angeltypes_controller.php29
-rw-r--r--includes/controller/user_driver_licenses_controller.php29
-rw-r--r--includes/controller/user_worklog_controller.php16
-rw-r--r--includes/controller/users_controller.php47
-rw-r--r--includes/model/Shifts_model.php32
-rw-r--r--includes/model/UserAngelTypes_model.php13
-rw-r--r--includes/model/UserWorkLog_model.php7
-rw-r--r--includes/model/User_model.php46
-rw-r--r--includes/pages/admin_questions.php2
-rw-r--r--includes/pages/user_myshifts.php5
-rw-r--r--includes/pages/user_shifts.php12
-rw-r--r--includes/view/AngelTypes_view.php5
-rw-r--r--includes/view/ShiftCalendarRenderer.php4
-rw-r--r--includes/view/ShiftCalendarShiftRenderer.php8
-rw-r--r--includes/view/ShiftEntry_view.php16
-rw-r--r--includes/view/Shifts_view.php11
-rw-r--r--includes/view/UserDriverLicenses_view.php6
-rw-r--r--includes/view/UserWorkLog_view.php10
-rw-r--r--includes/view/User_view.php86
22 files changed, 215 insertions, 220 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index b161266d..82cbf935 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -105,7 +105,7 @@ function angeltype_delete_controller()
*/
function angeltype_edit_controller()
{
- global $privileges, $user;
+ global $privileges;
// In supporter mode only allow to modify description
$supporter_mode = !in_array('admin_angel_types', $privileges);
@@ -115,7 +115,7 @@ function angeltype_edit_controller()
// Edit existing angeltype
$angeltype = load_angeltype();
- if (!User_is_AngelType_supporter($user, $angeltype)) {
+ if (!User_is_AngelType_supporter(auth()->user(), $angeltype)) {
redirect(page_link_to('angeltypes'));
}
} else {
@@ -178,15 +178,16 @@ function angeltype_edit_controller()
*/
function angeltype_controller()
{
- global $privileges, $user;
+ global $privileges;
+ $user = auth()->user();
if (!in_array('angeltypes', $privileges)) {
redirect(page_link_to('/'));
}
$angeltype = load_angeltype();
- $user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype);
- $user_driver_license = UserDriverLicense($user['UID']);
+ $user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype);
+ $user_driver_license = UserDriverLicense($user->id);
$members = Users_by_angeltype($angeltype);
$days = angeltype_controller_shiftsFilterDays($angeltype);
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
index 8fbee96e..2876991a 100644
--- a/includes/controller/shift_entries_controller.php
+++ b/includes/controller/shift_entries_controller.php
@@ -35,7 +35,8 @@ function shift_entries_controller()
*/
function shift_entry_create_controller()
{
- global $privileges, $user;
+ global $privileges;
+ $user = auth()->user();
$request = request();
if (User_is_freeloader($user)) {
@@ -44,7 +45,7 @@ function shift_entry_create_controller()
$shift = Shift($request->input('shift_id'));
if (empty($shift)) {
- redirect(user_link($user['UID']));
+ redirect(user_link($user->id));
}
$angeltype = AngelType($request->input('angeltype_id'));
@@ -54,7 +55,7 @@ function shift_entry_create_controller()
}
if (empty($angeltype)) {
- redirect(user_link($user['UID']));
+ redirect(user_link($user->id));
}
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)
{
- global $user;
$request = request();
+ $signup_user = auth()->user();
- $signup_user = $user;
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.'));
redirect(shift_link($shift));
}
@@ -172,7 +172,7 @@ function shift_entry_create_controller_supporter($shift, $angeltype)
ShiftEntry_create([
'SID' => $shift['SID'],
'TID' => $angeltype['id'],
- 'UID' => $signup_user['UID'],
+ 'UID' => $signup_user->id,
'Comment' => '',
'freeloaded' => false,
'freeload_comment' => ''
@@ -227,10 +227,9 @@ function shift_entry_error_message(ShiftSignupState $shift_signup_state)
*/
function shift_entry_create_controller_user($shift, $angeltype)
{
- global $user;
$request = request();
- $signup_user = $user;
+ $signup_user = auth()->user();
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
$shift_signup_state = Shift_signup_allowed(
@@ -253,14 +252,14 @@ function shift_entry_create_controller_user($shift, $angeltype)
ShiftEntry_create([
'SID' => $shift['SID'],
'TID' => $angeltype['id'],
- 'UID' => $signup_user['UID'],
+ 'UID' => $signup_user->id,
'Comment' => $comment,
'freeloaded' => false,
'freeload_comment' => ''
]);
- if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user['UID'], $angeltype)) {
- UserAngelType_create($signup_user['UID'], $angeltype);
+ if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user->id, $angeltype)) {
+ UserAngelType_create($signup_user->id, $angeltype);
}
success(__('You are subscribed. Thank you!'));
@@ -342,10 +341,10 @@ function shift_entry_delete_controller()
$shift = Shift($shiftEntry['SID']);
$angeltype = AngelType($shiftEntry['TID']);
- $signout_user = User($shiftEntry['UID']);
- if (!Shift_signout_allowed($shift, $angeltype, $signout_user)) {
+ $signout_user = User::find($shiftEntry['UID']);
+ 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.'));
- redirect(user_link($signout_user['UID']));
+ redirect(user_link($signout_user->id));
}
if ($request->has('continue')) {
@@ -354,10 +353,10 @@ function shift_entry_delete_controller()
redirect(shift_link($shift));
}
- if ($user->id == $signout_user['UID']) {
+ if ($user->id == $signout_user->id) {
return [
ShiftEntry_delete_title(),
- ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user)
+ ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user->id)
];
}
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index 5454c648..b56440e5 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -252,7 +252,8 @@ function shift_delete_controller()
*/
function shift_controller()
{
- global $user, $privileges;
+ global $privileges;
+ $user = auth()->user();
$request = request();
if (!in_array('user_shifts', $privileges)) {
@@ -272,7 +273,7 @@ function shift_controller()
$shifttype = ShiftType($shift['shifttype_id']);
$room = Room($shift['RID']);
$angeltypes = AngelTypes();
- $user_shifts = Shifts_by_user($user['UID']);
+ $user_shifts = Shifts_by_user($user->id);
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
foreach ($angeltypes as &$angeltype) {
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
index ee1f93ee..a38adfec 100644
--- a/includes/controller/user_angeltypes_controller.php
+++ b/includes/controller/user_angeltypes_controller.php
@@ -43,7 +43,6 @@ function user_angeltypes_unconfirmed_hint()
*/
function user_angeltypes_delete_all_controller()
{
- global $user;
$request = request();
if (!$request->has('angeltype_id')) {
@@ -57,7 +56,7 @@ function user_angeltypes_delete_all_controller()
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.'));
redirect(page_link_to('angeltypes'));
}
@@ -83,7 +82,8 @@ function user_angeltypes_delete_all_controller()
*/
function user_angeltypes_confirm_all_controller()
{
- global $user, $privileges;
+ global $privileges;
+ $user = auth()->user();
$request = request();
if (!$request->has('angeltype_id')) {
@@ -103,7 +103,7 @@ function user_angeltypes_confirm_all_controller()
}
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)));
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()
{
- global $user;
+ $user = auth()->user();
$request = request();
if (!$request->has('user_angeltype_id')) {
@@ -155,7 +155,7 @@ function user_angeltype_confirm_controller()
}
if ($request->has('confirmed')) {
- UserAngelType_confirm($user_angeltype['id'], $user['UID']);
+ UserAngelType_confirm($user_angeltype['id'], $user->id);
engelsystem_log(sprintf(
'%s confirmed for angeltype %s',
@@ -183,8 +183,8 @@ function user_angeltype_confirm_controller()
*/
function user_angeltype_delete_controller()
{
- global $user;
$request = request();
+ $user = auth()->user();
if (!$request->has('user_angeltype_id')) {
error(__('User angeltype doesn\'t exist.'));
@@ -209,7 +209,7 @@ function user_angeltype_delete_controller()
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.'));
redirect(page_link_to('angeltypes'));
}
@@ -305,18 +305,17 @@ function user_angeltype_update_controller()
*/
function user_angeltype_add_controller()
{
- global $user;
$angeltype = load_angeltype();
// 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);
}
// Allow to add any user
// Default selection
- $user_source = $user;
+ $user_source = auth()->user();
// Load possible users, that are not in the angeltype already
$users_source = Users_by_angeltype_inverted($angeltype);
@@ -324,8 +323,8 @@ function user_angeltype_add_controller()
if (request()->has('submit')) {
$user_source = load_user();
- if (!UserAngelType_exists($user_source['UID'], $angeltype)) {
- $user_angeltype_id = UserAngelType_create($user_source['UID'], $angeltype);
+ if (!UserAngelType_exists($user_source->id, $angeltype)) {
+ $user_angeltype_id = UserAngelType_create($user_source->id, $angeltype);
engelsystem_log(sprintf(
'User %s added to %s.',
@@ -338,7 +337,7 @@ function user_angeltype_add_controller()
AngelType_name_render($angeltype)
));
- UserAngelType_confirm($user_angeltype_id, $user_source['UID']);
+ UserAngelType_confirm($user_angeltype_id, $user_source->id);
engelsystem_log(sprintf(
'User %s confirmed as %s.',
User_Nick_render($user_source),
@@ -351,7 +350,7 @@ function user_angeltype_add_controller()
return [
__('Add user to angeltype'),
- UserAngelType_add_view($angeltype, $users_source, $user_source['UID'])
+ UserAngelType_add_view($angeltype, $users_source, $user_source->id)
];
}
diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php
index 4c7c7fff..f836c74d 100644
--- a/includes/controller/user_driver_licenses_controller.php
+++ b/includes/controller/user_driver_licenses_controller.php
@@ -1,5 +1,7 @@
<?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
* information provided.
@@ -55,30 +57,31 @@ function user_driver_licenses_controller()
/**
* Link to user driver license edit page for given user.
*
- * @param array $user
+ * @param User $user
* @return string
*/
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', ['user_id' => $user['UID']]);
+
+ return page_link_to('user_driver_licenses', ['user_id' => $user->id]);
}
/**
* Loads the user for the driver license.
*
- * @return array
+ * @return User
*/
function user_driver_license_load_user()
{
- global $user;
+ $user = auth()->user();
$request = request();
$user_source = $user;
if ($request->has('user_id')) {
- $user_source = User($request->input('user_id'));
+ $user_source = User::find($request->input('user_id'));
if (empty($user_source)) {
redirect(user_driver_license_edit_link());
}
@@ -100,11 +103,11 @@ function user_driver_license_edit_controller()
$user_source = user_driver_license_load_user();
// 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());
}
- $user_driver_license = UserDriverLicense($user_source['UID']);
+ $user_driver_license = UserDriverLicense($user_source->id);
if (empty($user_driver_license)) {
$wants_to_drive = false;
$user_driver_license = UserDriverLicense_new();
@@ -124,26 +127,26 @@ 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['UID']);
+ $user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source->id);
} else {
UserDriverLicenses_update($user_driver_license);
}
engelsystem_log('Driver license information updated.');
success(__('Your driver license information has been saved.'));
- redirect(user_link($user_source['UID']));
+ redirect(user_link($user_source->id));
} else {
error(__('Please select at least one driving license.'));
}
} elseif (!empty($user_driver_license['user_id'])) {
- UserDriverLicenses_delete($user_source['UID']);
+ UserDriverLicenses_delete($user_source->id);
engelsystem_log('Driver license information removed.');
success(__('Your driver license information has been removed.'));
- redirect(user_link($user_source['UID']));
+ redirect(user_link($user_source->id));
}
}
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)
];
}
diff --git a/includes/controller/user_worklog_controller.php b/includes/controller/user_worklog_controller.php
index e1b3ee86..51b70ba2 100644
--- a/includes/controller/user_worklog_controller.php
+++ b/includes/controller/user_worklog_controller.php
@@ -45,7 +45,7 @@ function user_worklog_edit_controller()
if (empty($userWorkLog)) {
redirect(user_link($user->id));
}
- $user_source = User($userWorkLog['user_id']);
+ $user_source = User::find($userWorkLog['user_id']);
if ($request->has('submit')) {
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
@@ -54,7 +54,7 @@ function user_worklog_edit_controller()
UserWorkLog_update($userWorkLog);
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();
$request = request();
- $user_source = User($request->input('user_id'));
- if (empty($user_source)) {
+ $user_source = User::find($request->input('user_id'));
+ if (!$user_source) {
redirect(user_link($user->id));
}
- $userWorkLog = UserWorkLog_new($user_source['UID']);
+ $userWorkLog = UserWorkLog_new($user_source->id);
if ($request->has('submit')) {
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
@@ -127,7 +127,7 @@ function user_worklog_add_controller()
UserWorkLog_create($userWorkLog);
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.
*
- * @param array $user
+ * @param User $user
*
* @return string
*/
@@ -148,7 +148,7 @@ function user_worklog_add_link($user)
{
return page_link_to('user_worklog', [
'action' => 'add',
- 'user_id' => $user['UID']
+ 'user_id' => $user->id,
]);
}
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index be78c1d7..3c05f596 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -135,11 +135,12 @@ function user_link($userId)
*/
function user_edit_vouchers_controller()
{
- global $privileges, $user;
+ global $privileges;
+ $user = auth()->user();
$request = request();
if ($request->has('user_id')) {
- $user_source = User($request->input('user_id'));
+ $user_source = User::find($request->input('user_id'));
} else {
$user_source = $user;
}
@@ -164,20 +165,19 @@ function user_edit_vouchers_controller()
}
if ($valid) {
- $user_source['got_voucher'] = $vouchers;
-
- User_update($user_source);
+ $user_source->state->got_voucher = $vouchers;
+ $user->state->save();
success(__('Saved the number of 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 [
- sprintf(__('%s\'s vouchers'), $user_source['Nick']),
+ sprintf(__('%s\'s vouchers'), $user_source->name),
User_edit_vouchers_view($user_source)
];
}
@@ -187,19 +187,20 @@ function user_edit_vouchers_controller()
*/
function user_controller()
{
- global $privileges, $user;
+ global $privileges;
+ $user = auth()->user();
$request = request();
$user_source = $user;
if ($request->has('user_id')) {
- $user_source = User($request->input('user_id'));
- if (empty($user_source)) {
+ $user_source = User::find($request->input('user_id'));
+ if (!$user_source) {
error(__('User not found.'));
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) {
// TODO: Move queries to model
$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);
}
- if ($user_source['force_active']) {
+ if ($user_source->state->force_active) {
$tshirt_score = __('Enough');
} 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 [
- $user_source['Nick'],
+ $user_source->name,
User_view(
$user_source,
in_array('admin_user', $privileges),
User_is_freeloader($user_source),
- User_angeltypes($user_source['UID']),
- User_groups($user_source['UID']),
+ User_angeltypes($user_source->id),
+ User_groups($user_source->id),
$shifts,
- $user['UID'] == $user_source['UID'],
+ $user->id == $user_source->id,
$tshirt_score,
in_array('admin_active', $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.
*
- * return array
+ * @return User
*/
function load_user()
{
@@ -415,8 +416,8 @@ function load_user()
redirect(page_link_to());
}
- $user = User($request->input('user_id'));
- if (empty($user)) {
+ $user = User::find($request->input('user_id'));
+ if (!$user) {
error(__('User doesn\'t exist.'));
redirect(page_link_to());
}
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index e03ca0bf..9e803efd 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
+use Engelsystem\Models\User\User;
use Engelsystem\ShiftsFilter;
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)
*
- * @param array $user
+ * @param User $user
* @param array $shift The shift
* @param array $angeltype The angeltype to which the user wants to sign up
* @param array|null $user_angeltype
@@ -321,12 +322,12 @@ function Shift_signup_allowed_angel(
) {
$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);
}
if (empty($user_shifts)) {
- $user_shifts = Shifts_by_user($user['UID']);
+ $user_shifts = Shifts_by_user($user->id);
}
$signed_up = false;
@@ -352,7 +353,7 @@ function Shift_signup_allowed_angel(
}
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 (
@@ -415,14 +416,15 @@ function Shift_signup_allowed_admin($needed_angeltype, $shift_entries)
/**
* Check if an angel can signout from a shift.
*
- * @param array $shift The shift
- * @param array $angeltype The angeltype
- * @param array $signout_user The user that was signed up for the shift
+ * @param array $shift The shift
+ * @param array $angeltype The angeltype
+ * @param int $signout_user_id The user that was signed up for the shift
* @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
if (in_array('user_shifts_admin', $privileges)) {
@@ -437,7 +439,7 @@ function Shift_signout_allowed($shift, $angeltype, $signout_user)
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;
}
@@ -447,7 +449,7 @@ function Shift_signout_allowed($shift, $angeltype, $signout_user)
/**
* 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 $angeltype The angeltype to which the user wants to sign up
* @param array|null $user_angeltype
@@ -465,7 +467,7 @@ function Shift_signup_allowed(
$needed_angeltype,
$shift_entries
) {
- global $user, $privileges;
+ global $privileges;
if (in_array('user_shifts_admin', $privileges)) {
return Shift_signup_allowed_admin($needed_angeltype, $shift_entries);
@@ -473,7 +475,7 @@ function Shift_signup_allowed(
if (
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);
}
@@ -613,8 +615,8 @@ function Shift_create($shift)
/**
* Return users shifts.
*
- * @param int $userId
- * @param bool $include_freeload_comments
+ * @param int $userId
+ * @param bool $include_freeload_comments
* @return array[]
*/
function Shifts_by_user($userId, $include_freeload_comments = false)
diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php
index 943dbb5b..e18eaf1b 100644
--- a/includes/model/UserAngelTypes_model.php
+++ b/includes/model/UserAngelTypes_model.php
@@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
+use Engelsystem\Models\User\User;
/**
* 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.
*
- * @param array $user
+ * @param User $user
* @param array $angeltype
* @return bool
*/
-function User_is_AngelType_supporter(&$user, $angeltype)
+function User_is_AngelType_supporter($user, $angeltype)
{
- if (!isset($user['privileges'])) {
- $user['privileges'] = privileges_for_user($user['UID']);
- }
+ $privileges = privileges_for_user($user->id);
return (count(DB::select('
SELECT `id`
@@ -86,11 +85,11 @@ function User_is_AngelType_supporter(&$user, $angeltype)
LIMIT 1
',
[
- $user['UID'],
+ $user->id,
$angeltype['id']
]
)) > 0)
- || in_array('admin_user_angeltypes', $user['privileges']);
+ || in_array('admin_user_angeltypes', $privileges);
}
/**
diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php
index c7de3f9e..11f60901 100644
--- a/includes/model/UserWorkLog_model.php
+++ b/includes/model/UserWorkLog_model.php
@@ -2,6 +2,7 @@
use Carbon\Carbon;
use Engelsystem\Database\Db;
+use Engelsystem\Models\User\User;
/**
* Load a single work log entry.
@@ -39,7 +40,7 @@ function UserWorkLogsForUser($userId)
*/
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`=?", [
$userWorkLog['id']
]);
@@ -62,7 +63,7 @@ function UserWorkLog_delete($userWorkLog)
*/
function UserWorkLog_update($userWorkLog)
{
- $user_source = User($userWorkLog['user_id']);
+ $user_source = User::find($userWorkLog['user_id']);
$result = Db::update("UPDATE `UserWorkLog` SET
`work_timestamp`=?,
@@ -95,7 +96,7 @@ function UserWorkLog_create($userWorkLog)
{
$user = Auth()->user();
- $user_source = User($userWorkLog['user_id']);
+ $user_source = User::find($userWorkLog['user_id']);
$result = Db::insert("INSERT INTO `UserWorkLog` (
`user_id`,
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index bed6bf47..298ac18d 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -2,6 +2,7 @@
use Carbon\Carbon;
use Engelsystem\Database\DB;
+use Engelsystem\Models\User\User;
use Engelsystem\ValidationResult;
/**
@@ -238,14 +239,12 @@ function Users($order_by = 'Nick')
/**
* Returns true if user is freeloader
*
- * @param array $user
+ * @param User $user
* @return bool
*/
function User_is_freeloader($user)
{
- global $user;
-
- return count(ShiftEntries_freeloaded_by_user($user['UID'])) >= config('max_freeloadable_shifts');
+ return count(ShiftEntries_freeloaded_by_user($user->id)) >= config('max_freeloadable_shifts');
}
/**
@@ -419,19 +418,6 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de
}
/**
- * 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.
*
* @param string $api_key User api key
@@ -473,23 +459,13 @@ function User_by_password_recovery_token($token)
/**
* Generates a new api key for given user.
*
- * @param array $user
- * @param bool $log
+ * @param User $user
+ * @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());
- DB::update('
- UPDATE `User`
- SET `api_key`=?
- WHERE `UID`=?
- LIMIT 1
- ',
- [
- $user['api_key'],
- $user['UID']
- ]
- );
+ $user->api_key = md5($user->name . time() . rand());
+ $user->save();
if ($log) {
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
*/
function User_get_eligable_voucher_count($user)
{
$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;
if ($eligable_vouchers < 0) {
return 0;
diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php
index 02f53d93..85d62362 100644
--- a/includes/pages/admin_questions.php
+++ b/includes/pages/admin_questions.php
@@ -68,7 +68,7 @@ function admin_questions()
$questions = DB::select('SELECT * FROM `Questions` WHERE NOT `AID` IS NULL');
foreach ($questions as $question) {
$user_source = User::find($question['UID']);
- $answer_user_source = User($question['AID']);
+ $answer_user_source = User::find($question['AID']);
$answered_questions_table[] = [
'from' => User_Nick_render($user_source),
'question' => str_replace("\n", '<br />', $question['Question']),
diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php
index ab4b00b6..7f20139c 100644
--- a/includes/pages/user_myshifts.php
+++ b/includes/pages/user_myshifts.php
@@ -18,7 +18,8 @@ function myshifts_title()
*/
function user_myshifts()
{
- global $user, $privileges;
+ global $privileges;
+ $user = auth()->user();
$request = request();
if (
@@ -29,7 +30,7 @@ function user_myshifts()
) {
$shift_entry_id = $request->input('id');
} else {
- $shift_entry_id = $user['UID'];
+ $shift_entry_id = $user->id;
}
$shifts_user = User::find($shift_entry_id);
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 350394be..3e300e3c 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -22,10 +22,9 @@ function shifts_title()
*/
function user_shifts()
{
- global $user;
$request = request();
- if (User_is_freeloader($user)) {
+ if (User_is_freeloader(auth()->user())) {
redirect(page_link_to('user_myshifts'));
}
@@ -169,7 +168,8 @@ function load_types()
*/
function view_user_shifts()
{
- global $user, $privileges, $ical_shifts;
+ global $privileges, $ical_shifts;
+ $user = auth()->user();
$session = session();
$ical_shifts = [];
@@ -193,7 +193,7 @@ function view_user_shifts()
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
- if ($user['api_key'] == '') {
+ if (empty($user->api_key)) {
User_reset_api_key($user, false);
}
@@ -212,12 +212,12 @@ function view_user_shifts()
$end_day = date('Y-m-d', $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());
}
$ownTypes = [];
- foreach (UserAngelTypes_by_User($user['UID']) as $type) {
+ foreach (UserAngelTypes_by_User($user->id) as $type) {
$ownTypes[] = (int)$type['angeltype_id'];
}
diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php
index c64297c2..be79cbb9 100644
--- a/includes/view/AngelTypes_view.php
+++ b/includes/view/AngelTypes_view.php
@@ -1,5 +1,6 @@
<?php
+use Engelsystem\Models\User\User;
use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilterRenderer;
@@ -129,7 +130,7 @@ function AngelType_edit_view($angeltype, $supporter_mode)
* @param bool $admin_angeltypes
* @param bool $supporter
* @param array|null $user_driver_license
- * @param array|null $user
+ * @param User|null $user
* @return string
*/
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 $supporter
* @param array $user_driver_license
- * @param array $user
+ * @param User $user
* @param ShiftsFilterRenderer $shiftsFilterRenderer
* @param ShiftCalendarRenderer $shiftCalendarRenderer
* @param int $tab The selected tab
diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php
index fc099d7d..dfc55d54 100644
--- a/includes/view/ShiftCalendarRenderer.php
+++ b/includes/view/ShiftCalendarRenderer.php
@@ -176,8 +176,6 @@ class ShiftCalendarRenderer
*/
private function renderLane(ShiftCalendarLane $lane)
{
- global $user;
-
$shift_renderer = new ShiftCalendarShiftRenderer();
$html = '';
$rendered_until = $this->getFirstBlockStartTime();
@@ -192,7 +190,7 @@ class ShiftCalendarRenderer
$shift,
$this->needed_angeltypes[$shift['SID']],
$this->shift_entries[$shift['SID']],
- $user
+ auth()->user()
);
$html .= $shift_html;
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php
index 80cea241..f1847698 100644
--- a/includes/view/ShiftCalendarShiftRenderer.php
+++ b/includes/view/ShiftCalendarShiftRenderer.php
@@ -2,6 +2,8 @@
namespace Engelsystem;
+use Engelsystem\Models\User\User;
+
/**
* Renders a single shift for the shift calendar
*/
@@ -13,7 +15,7 @@ class ShiftCalendarShiftRenderer
* @param array $shift The shift to render
* @param array $needed_angeltypes
* @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
*/
public function render($shift, $needed_angeltypes, $shift_entries, $user)
@@ -90,7 +92,7 @@ class ShiftCalendarShiftRenderer
* @param array $shift
* @param array[] $needed_angeltypes
* @param array[] $shift_entries
- * @param array $user
+ * @param User $user
* @return array
*/
private function renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user)
@@ -156,7 +158,7 @@ class ShiftCalendarShiftRenderer
* @param array[] $shift_entries
* @param array[] $angeltype The angeltype, containing information about needed angeltypes
* 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
*/
private function renderShiftNeededAngeltype($shift, $shift_entries, $angeltype, $user)
diff --git a/includes/view/ShiftEntry_view.php b/includes/view/ShiftEntry_view.php
index 1d6ba3a3..51f02cce 100644
--- a/includes/view/ShiftEntry_view.php
+++ b/includes/view/ShiftEntry_view.php
@@ -1,12 +1,14 @@
<?php
+use Engelsystem\Models\User\User;
+
/**
* Sign off from an user from a shift with admin permissions, asking for ack.
*
* @param array $shiftEntry
* @param array $shift
* @param array $angeltype
- * @param array $signoff_user
+ * @param User $signoff_user
*
* @return string HTML
*/
@@ -22,7 +24,7 @@ function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_
$angeltype['name']
), true),
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, [
'continue' => 1
]), glyph('ok') . __('delete'), 'btn-danger')
@@ -36,11 +38,11 @@ function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_
* @param array $shiftEntry
* @param array $shift
* @param array $angeltype
- * @param array $signoff_user
+ * @param int $signoff_user_id
*
* @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(), [
info(sprintf(
@@ -51,7 +53,7 @@ function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user)
$angeltype['name']
), true),
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, [
'continue' => 1
]), glyph('ok') . __('delete'), 'btn-danger')
@@ -100,7 +102,7 @@ function ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_sel
* @param array $shift
* @param array $room
* @param array $angeltype
- * @param array $signup_user
+ * @param User $signup_user
* @param array $users_select
* @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?'),
AngelType_name_render($angeltype)), true),
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'))
])
]);
diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php
index bd13a390..2485ec67 100644
--- a/includes/view/Shifts_view.php
+++ b/includes/view/Shifts_view.php
@@ -1,5 +1,6 @@
<?php
+use Engelsystem\Models\User\User;
use Engelsystem\ShiftSignupState;
/**
@@ -54,14 +55,14 @@ function Shift_editor_info_render($shift)
$info[] = sprintf(
glyph('plus') . __('created at %s by %s'),
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'])) {
$info[] = sprintf(
glyph('pencil') . __('edited at %s by %s'),
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);
@@ -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)
{
- global $user;
-
$angeltype = $angeltypes[$needed_angeltype['TID']];
- $angeltype_supporter = User_is_AngelType_supporter($user, $angeltype);
+ $angeltype_supporter = User_is_AngelType_supporter(auth()->user(), $angeltype);
$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)
{
- $entry = User_Nick_render(User($shift_entry['UID']));
+ $entry = User_Nick_render(User::find($shift_entry['UID']));
if ($shift_entry['freeloaded']) {
$entry = '<del>' . $entry . '</del>';
}
diff --git a/includes/view/UserDriverLicenses_view.php b/includes/view/UserDriverLicenses_view.php
index 664a5d58..32977d31 100644
--- a/includes/view/UserDriverLicenses_view.php
+++ b/includes/view/UserDriverLicenses_view.php
@@ -1,9 +1,11 @@
<?php
+use Engelsystem\Models\User\User;
+
/**
* 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 array $user_driver_license The user driver license
* @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)), [
buttons([
- button(user_link($user_source['UID']), __('Back to profile'), 'back')
+ button(user_link($user_source->id), __('Back to profile'), 'back')
]),
msg(),
form([
diff --git a/includes/view/UserWorkLog_view.php b/includes/view/UserWorkLog_view.php
index e930e9e5..ee35350b 100644
--- a/includes/view/UserWorkLog_view.php
+++ b/includes/view/UserWorkLog_view.php
@@ -36,7 +36,7 @@ function UserWorkLog_delete_title()
/**
* Render edit table.
*
- * @param array $user_source
+ * @param User $user_source
* @param array $userWorkLog
* @return string
*/
@@ -54,7 +54,7 @@ function UserWorkLog_edit_form($user_source, $userWorkLog)
/**
* Form for edit a user work log entry.
*
- * @param array $user_source
+ * @param User $user_source
* @param array $userWorkLog
* @return string
*/
@@ -62,7 +62,7 @@ function UserWorkLog_edit_view($user_source, $userWorkLog)
{
return page_with_title(UserWorkLog_edit_title(), [
buttons([
- button(user_link($user_source['UID']), __('back'))
+ button(user_link($user_source->id), __('back'))
]),
msg(),
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.
*
- * @param array $user_source
+ * @param User $user_source
* @param array $userWorkLog
* @return string
*/
@@ -80,7 +80,7 @@ function UserWorkLog_add_view($user_source, $userWorkLog)
{
return page_with_title(UserWorkLog_add_title(), [
buttons([
- button(user_link($user_source['UID']), __('back'))
+ button(user_link($user_source->id), __('back'))
]),
msg(),
UserWorkLog_edit_form($user_source, $userWorkLog)
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index 6243d26e..1c1aa30a 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -169,7 +169,7 @@ function User_delete_view($user)
/**
* View for editing the number of given vouchers
*
- * @param array $user
+ * @param User $user
* @return string
*/
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)), [
msg(),
buttons([
- button(user_link($user['UID']), glyph('chevron-left') . __('back'))
+ button(user_link($user->id), glyph('chevron-left') . __('back'))
]),
info(sprintf(
__('Angel should receive at least %d vouchers.'),
@@ -185,10 +185,10 @@ function User_edit_vouchers_view($user)
), true),
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'))
],
- 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
*/
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
*
* @param array $shift
- * @param array $user_source
+ * @param User $user_source
* @param bool $its_me
* @return array
*/
@@ -398,12 +398,12 @@ function User_view_myshift($shift, $user_source, $its_me)
];
if ($its_me || in_array('user_shifts_admin', $privileges)) {
$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'),
'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(
shift_entry_delete_link($shift),
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
*
* @param array[] $shifts
- * @param array $user_source
+ * @param User $user_source
* @param bool $its_me
* @param int $tshirt_score
* @param bool $tshirt_admin
@@ -510,7 +510,7 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege)
'comment' => $worklog['comment'] . '<br>'
. sprintf(
__('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'])
),
'actions' => $actions
@@ -520,7 +520,7 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege)
/**
* Renders view for a single user
*
- * @param array $user_source
+ * @param User $user_source
* @param bool $admin_user_privilege
* @param bool $freeloader
* @param array[] $user_angeltypes
@@ -547,7 +547,9 @@ function User_view(
$user_worklogs
) {
$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 = '';
if ($its_me || $admin_user_privilege) {
$my_shifts = User_view_myshifts(
@@ -568,14 +570,14 @@ function User_view(
'comment' => __('Comment'),
'actions' => __('Action')
], $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);
}
}
return page_with_title(
'<span class="icon-icon_angel"></span> '
- . htmlspecialchars($user_source['Nick'])
+ . htmlspecialchars($user_source->name)
. ' <small>' . $user_name . '</small>',
[
msg(),
@@ -583,21 +585,21 @@ function User_view(
div('col-md-12', [
buttons([
$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')
) : '',
$admin_user_privilege ? button(
user_driver_license_edit_link($user_source),
glyph('road') . __('driving license')
) : '',
- ($admin_user_privilege && !$user_source['Gekommen']) ? button(
- page_link_to('admin_arrive', ['arrived' => $user_source['UID']]),
+ ($admin_user_privilege && !$user_source->state->arrived) ? button(
+ page_link_to('admin_arrive', ['arrived' => $user_source->id]),
__('arrived')
) : '',
$admin_user_privilege ? button(
page_link_to(
'users',
- ['action' => 'edit_vouchers', 'user_id' => $user_source['UID']]
+ ['action' => 'edit_vouchers', 'user_id' => $user_source->id]
),
glyph('cutlery') . __('Edit vouchers')
) : '',
@@ -610,11 +612,11 @@ function User_view(
glyph('list-alt') . __('Settings')
) : '',
$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')
) : '',
$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')
) : '',
$its_me ? button(
@@ -626,7 +628,7 @@ function User_view(
]),
div('row', [
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_angeltypes_render($user_angeltypes),
@@ -656,9 +658,9 @@ function User_view(
/**
* Render the state section of user view
*
- * @param bool $admin_user_privilege
- * @param bool $freeloader
- * @param array $user_source
+ * @param bool $admin_user_privilege
+ * @param bool $freeloader
+ * @param User $user_source
* @return string
*/
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.
*
- * @param array $user_source
+ * @param User $user_source
* @return array
*/
function User_view_state_user($user_source)
@@ -687,7 +689,7 @@ function User_view_state_user($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>';
} else {
$state[] = '<span class="text-danger">' . __('Not arrived') . '</span>';
@@ -700,8 +702,8 @@ function User_view_state_user($user_source)
/**
* Render the state section of user view for admins.
*
- * @param bool $freeloader
- * @param array $user_source
+ * @param bool $freeloader
+ * @param User $user_source
* @return array
*/
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);
- if ($user_source['Gekommen']) {
+ if ($user_source->state->arrived) {
$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>';
- if ($user_source['force_active']) {
+ if ($user_source->state->force_active) {
$state[] = '<span class="text-success">' . __('Active (forced)') . '</span>';
- } elseif ($user_source['Aktiv']) {
+ } elseif ($user_source->state->active) {
$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>';
}
} else {
+ $arrivalDate = $user_source->personalData->planned_arrival_date;
$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>';
}
- if ($user_source['got_voucher'] > 0) {
+ if ($user_source->state->got_voucher > 0) {
+ $voucherCount = $user_source->state->got_voucher;
$state[] = '<span class="text-success">'
. 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>';
} else {
$state[] = '<span class="text-danger">' . __('Got no vouchers') . '</span>';
@@ -884,9 +894,7 @@ function render_user_departure_date_hint()
*/
function render_user_freeloader_hint()
{
- global $user;
-
- if (User_is_freeloader($user)) {
+ if (User_is_freeloader(auth()->user())) {
return sprintf(
__('You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again.'),
config('max_freeloadable_shifts')