From 2dcb7cc2de448c664bbc9a7112f9cb13dc15c516 Mon Sep 17 00:00:00 2001
From: Igor Scheller
Date: Mon, 8 Oct 2018 21:15:56 +0200
Subject: [PATCH] Replaced some global `$user` variables
---
.../controller/shift_entries_controller.php | 4 ++--
.../user_driver_licenses_controller.php | 9 +++----
includes/controller/users_controller.php | 4 ++--
includes/helper/email_helper.php | 4 ++--
includes/model/Message_model.php | 8 +++----
includes/model/Shifts_model.php | 4 ++--
includes/model/UserWorkLog_model.php | 4 ++--
includes/pages/admin_import.php | 5 ++--
includes/pages/admin_news.php | 5 ++--
includes/pages/admin_questions.php | 4 ++--
includes/pages/admin_user.php | 15 ++++++------
includes/pages/guest_login.php | 7 +++---
includes/pages/user_messages.php | 6 ++---
includes/pages/user_news.php | 10 ++++----
includes/pages/user_questions.php | 10 ++++----
includes/pages/user_shifts.php | 10 ++++----
includes/sys_menu.php | 4 ++--
includes/view/Rooms_view.php | 4 ++--
src/helpers.php | 17 +++++++++----
tests/Unit/HelpersTest.php | 24 ++++++++++++++++++-
20 files changed, 97 insertions(+), 61 deletions(-)
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
index 05a3a5e5..2c57f550 100644
--- a/includes/controller/shift_entries_controller.php
+++ b/includes/controller/shift_entries_controller.php
@@ -336,7 +336,7 @@ function shift_entry_load()
*/
function shift_entry_delete_controller()
{
- global $user;
+ $user = Auth()->user();
$request = request();
$shiftEntry = shift_entry_load();
@@ -354,7 +354,7 @@ function shift_entry_delete_controller()
redirect(shift_link($shift));
}
- if ($user['UID'] == $signout_user['UID']) {
+ if ($user->id == $signout_user['UID']) {
return [
ShiftEntry_delete_title(),
ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user)
diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php
index 6621866d..422ad382 100644
--- a/includes/controller/user_driver_licenses_controller.php
+++ b/includes/controller/user_driver_licenses_controller.php
@@ -37,9 +37,9 @@ function user_driver_license_required_hint()
*/
function user_driver_licenses_controller()
{
- global $user;
+ $user = Auth()->user();
- if (!isset($user)) {
+ if (!$user) {
redirect(page_link_to(''));
}
@@ -94,12 +94,13 @@ function user_driver_license_load_user()
*/
function user_driver_license_edit_controller()
{
- global $privileges, $user;
+ global $privileges;
+ $user = Auth()->user();
$request = request();
$user_source = user_driver_license_load_user();
// only privilege admin_user can edit other users driver license information
- if ($user['UID'] != $user_source['UID'] && !in_array('admin_user', $privileges)) {
+ if ($user->id != $user_source['UID'] && !in_array('admin_user', $privileges)) {
redirect(user_driver_license_edit_link());
}
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index d7f97c7e..13264fd1 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -11,10 +11,10 @@ use Engelsystem\ShiftsFilter;
*/
function users_controller()
{
- global $user;
+ $user = Auth()->user();
$request = request();
- if (!isset($user)) {
+ if (!$user) {
redirect(page_link_to(''));
}
diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php
index 7cd60933..8668cab0 100644
--- a/includes/helper/email_helper.php
+++ b/includes/helper/email_helper.php
@@ -11,9 +11,9 @@ use Engelsystem\Mail\EngelsystemMailer;
*/
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false)
{
- global $user;
+ $user = Auth()->user();
- if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
+ if ($not_if_its_me && $user->id == $recipient_user['UID']) {
return true;
}
diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php
index 3f66f74a..4f8a3972 100644
--- a/includes/model/Message_model.php
+++ b/includes/model/Message_model.php
@@ -27,7 +27,7 @@ function Message($message_id)
/**
* TODO: use validation functions, return new message id
- * TODO: global $user con not be used in model!
+ * TODO: global $user can't be used in model!
* send message
*
* @param int $receiver_user_id User ID of Receiver
@@ -36,7 +36,7 @@ function Message($message_id)
*/
function Message_send($receiver_user_id, $text)
{
- global $user;
+ $user = Auth()->user();
$text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text));
$receiver_user_id = preg_replace('/([^\d]{1,})/ui', '', strip_tags($receiver_user_id));
@@ -49,7 +49,7 @@ function Message_send($receiver_user_id, $text)
WHERE `UID` = ?
AND NOT `UID` = ?
LIMIT 1
- ', [$receiver_user_id, $user['UID']])) > 0
+ ', [$receiver_user_id, $user->id])) > 0
) {
return DB::insert('
INSERT INTO `Messages` (`Datum`, `SUID`, `RUID`, `Text`)
@@ -57,7 +57,7 @@ function Message_send($receiver_user_id, $text)
',
[
time(),
- $user['UID'],
+ $user->id,
$receiver_user_id,
$text
]
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 74facc0a..30ce5a97 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -518,7 +518,7 @@ function Shift_delete($shift_id)
*/
function Shift_update($shift)
{
- global $user;
+ $user = Auth()->user();
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
mail_shift_change(Shift($shift['SID']), $shift);
@@ -543,7 +543,7 @@ function Shift_update($shift)
$shift['title'],
$shift['URL'],
$shift['PSID'],
- $user['UID'],
+ $user->id,
time(),
$shift['SID']
]
diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php
index dd4b2574..46ab891e 100644
--- a/includes/model/UserWorkLog_model.php
+++ b/includes/model/UserWorkLog_model.php
@@ -93,7 +93,7 @@ function UserWorkLog_update($userWorkLog)
*/
function UserWorkLog_create($userWorkLog)
{
- global $user;
+ $user = Auth()->user();
$user_source = User($userWorkLog['user_id']);
@@ -110,7 +110,7 @@ function UserWorkLog_create($userWorkLog)
$userWorkLog['work_timestamp'],
$userWorkLog['work_hours'],
$userWorkLog['comment'],
- $user['UID'],
+ $user->id,
time()
]);
diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php
index 29aa719b..f6889320 100644
--- a/includes/pages/admin_import.php
+++ b/includes/pages/admin_import.php
@@ -13,7 +13,8 @@ function admin_import_title()
*/
function admin_import()
{
- global $rooms_import, $user;
+ global $rooms_import;
+ $user = Auth()->user();
$html = '';
$import_dir = __DIR__ . '/../../import';
$request = request();
@@ -38,7 +39,7 @@ function admin_import()
error(__('Webserver has no write-permission on import directory.'));
}
- $import_file = $import_dir . '/import_' . $user['UID'] . '.xml';
+ $import_file = $import_dir . '/import_' . $user->id . '.xml';
$shifttype_id = null;
$add_minutes_start = 15;
$add_minutes_end = 15;
diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php
index 8a3fe9c2..d387e06b 100644
--- a/includes/pages/admin_news.php
+++ b/includes/pages/admin_news.php
@@ -7,7 +7,8 @@ use Engelsystem\Database\DB;
*/
function admin_news()
{
- global $user, $privileges;
+ global $privileges;
+ $user = Auth()->user();
$request = request();
if (!$request->has('action')) {
@@ -77,7 +78,7 @@ function admin_news()
time(),
strip_tags($request->postData('eBetreff')),
$text,
- $user['UID'],
+ $user->id,
$request->has('eTreffen') ? 1 : 0,
$news_id
]
diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php
index b4a956d5..fc84ff9e 100644
--- a/includes/pages/admin_questions.php
+++ b/includes/pages/admin_questions.php
@@ -39,7 +39,7 @@ function admin_new_questions()
*/
function admin_questions()
{
- global $user;
+ $user = Auth()->user();
$request = request();
if (!$request->has('action')) {
@@ -126,7 +126,7 @@ function admin_questions()
LIMIT 1
',
[
- $user['UID'],
+ $user->id,
$answer,
$question_id,
]
diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php
index a0125604..2ef48eb7 100644
--- a/includes/pages/admin_user.php
+++ b/includes/pages/admin_user.php
@@ -15,7 +15,8 @@ function admin_user_title()
*/
function admin_user()
{
- global $user, $privileges;
+ global $privileges;
+ $user = Auth()->user();
$tshirt_sizes = config('tshirt_sizes');
$request = request();
$html = '';
@@ -52,7 +53,7 @@ function admin_user()
. '
' . "\n";
$html .= ' Name | ' . ' |
' . "\n";
$html .= ' Vorname | ' . ' |
' . "\n";
- $html .= ' Alter | ' . ' |
' . "\n";
+ $html .= ' Alter | ' . ' |
' . "\n";
$html .= ' Telefon | ' . ' |
' . "\n";
$html .= ' Handy | ' . ' |
' . "\n";
$html .= ' DECT | ' . ' |
' . "\n";
@@ -114,7 +115,7 @@ function admin_user()
$my_highest_group = DB::selectOne(
'SELECT group_id FROM `UserGroups` WHERE `uid`=? ORDER BY `group_id` LIMIT 1',
- [$user['UID']]
+ [$user->id]
);
if (!empty($my_highest_group)) {
$my_highest_group = $my_highest_group['group_id'];
@@ -128,7 +129,7 @@ function admin_user()
$his_highest_group = $his_highest_group['group_id'];
}
- if ($user_id != $user['UID'] && $my_highest_group <= $his_highest_group) {
+ if ($user_id != $user->id && $my_highest_group <= $his_highest_group) {
$html .= 'Hier kannst Du die Benutzergruppen des Engels festlegen: