summaryrefslogtreecommitdiff
path: root/includes/controller
diff options
context:
space:
mode:
Diffstat (limited to 'includes/controller')
-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
7 files changed, 88 insertions, 84 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());
}