Changed more functions 🎉

This commit is contained in:
Igor Scheller 2018-10-09 21:47:31 +02:00 committed by msquare
parent b069a938c6
commit 89e62c95a7
35 changed files with 301 additions and 263 deletions

View File

@ -57,17 +57,17 @@ function angeltype_link($angeltype_id, $params = [])
*/
function angeltypes_about_controller()
{
global $user;
$user = auth()->user();
if (isset($user)) {
$angeltypes = AngelTypes_with_user($user);
if ($user) {
$angeltypes = AngelTypes_with_user($user->id);
} else {
$angeltypes = AngelTypes();
}
return [
__('Teams/Job description'),
AngelTypes_about_view($angeltypes, isset($user))
AngelTypes_about_view($angeltypes, (bool)$user)
];
}
@ -185,7 +185,7 @@ function angeltype_controller()
}
$angeltype = load_angeltype();
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype);
$user_driver_license = UserDriverLicense($user['UID']);
$members = Users_by_angeltype($angeltype);
@ -277,13 +277,14 @@ function angeltype_controller_shiftsFilter($angeltype, $days)
*/
function angeltypes_list_controller()
{
global $privileges, $user;
global $privileges;
$user = auth()->user();
if (!in_array('angeltypes', $privileges)) {
redirect(page_link_to('/'));
}
$angeltypes = AngelTypes_with_user($user);
$angeltypes = AngelTypes_with_user($user->id);
foreach ($angeltypes as &$angeltype) {
$actions = [

View File

@ -1,5 +1,6 @@
<?php
use Engelsystem\Models\User\User;
use Engelsystem\ShiftSignupState;
/**
@ -9,15 +10,14 @@ use Engelsystem\ShiftSignupState;
*/
function shift_entries_controller()
{
global $user;
if (!isset($user)) {
$user = auth()->user();
if ($user) {
redirect(page_link_to('login'));
}
$action = strip_request_item('action');
if (empty($action)) {
redirect(user_link($user['UID']));
redirect(user_link($user->id));
}
switch ($action) {
@ -74,14 +74,14 @@ function shift_entry_create_controller()
*/
function shift_entry_create_controller_admin($shift, $angeltype)
{
global $user;
$user = auth()->user();
$request = request();
$signup_user = $user;
if ($request->has('user_id')) {
$signup_user = User($request->input('user_id'));
$signup_user = User::find($request->input('user_id'));
}
if (empty($signup_user)) {
if (!$signup_user) {
redirect(shift_link($shift));
}
@ -100,7 +100,7 @@ function shift_entry_create_controller_admin($shift, $angeltype)
ShiftEntry_create([
'SID' => $shift['SID'],
'TID' => $angeltype['id'],
'UID' => $signup_user['UID'],
'UID' => $signup_user->id,
'Comment' => '',
'freeloaded' => false,
'freeload_comment' => ''
@ -145,7 +145,7 @@ function shift_entry_create_controller_supporter($shift, $angeltype)
if ($request->has('user_id')) {
$signup_user = User($request->input('user_id'));
}
if (!UserAngelType_exists($signup_user, $angeltype)) {
if (!UserAngelType_exists($signup_user['UID'], $angeltype)) {
error(__('User is not in angeltype.'));
redirect(shift_link($shift));
}
@ -259,8 +259,8 @@ function shift_entry_create_controller_user($shift, $angeltype)
'freeload_comment' => ''
]);
if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user, $angeltype)) {
UserAngelType_create($signup_user, $angeltype);
if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user['UID'], $angeltype)) {
UserAngelType_create($signup_user['UID'], $angeltype);
}
success(__('You are subscribed. Thank you!'));

View File

@ -272,12 +272,12 @@ function shift_controller()
$shifttype = ShiftType($shift['shifttype_id']);
$room = Room($shift['RID']);
$angeltypes = AngelTypes();
$user_shifts = Shifts_by_user($user);
$user_shifts = Shifts_by_user($user['UID']);
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
foreach ($angeltypes as &$angeltype) {
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
if(empty($needed_angeltype)) {
if (empty($needed_angeltype)) {
continue;
}
@ -330,13 +330,14 @@ function shifts_controller()
*/
function shift_next_controller()
{
global $user, $privileges;
global $privileges;
$user = auth()->user();
if (!in_array('user_shifts', $privileges)) {
redirect(page_link_to('/'));
}
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
$upcoming_shifts = ShiftEntries_upcoming_for_user($user->id);
if (!empty($upcoming_shifts)) {
redirect(shift_link($upcoming_shifts[0]));
@ -381,7 +382,5 @@ function shifts_json_export_controller()
*/
function load_ical_shifts()
{
global $user;
return Shifts_by_user($user);
return Shifts_by_user(auth()->user()->id);
}

View File

@ -1,5 +1,7 @@
<?php
use Engelsystem\Models\User\User;
/**
* Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype.
*
@ -7,9 +9,9 @@
*/
function user_angeltypes_unconfirmed_hint()
{
global $user;
$user = auth()->user();
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user->id);
if (count($unconfirmed_user_angeltypes) == 0) {
return null;
}
@ -101,7 +103,7 @@ function user_angeltypes_confirm_all_controller()
}
if ($request->has('confirmed')) {
UserAngelTypes_confirm_all($angeltype['id'], $user);
UserAngelTypes_confirm_all($angeltype['id'], $user['UID']);
engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype)));
success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype)));
@ -146,14 +148,14 @@ function user_angeltype_confirm_controller()
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
if (empty($user_source)) {
$user_source = User::find($user_angeltype['user_id']);
if (!$user_source) {
error(__('User doesn\'t exist.'));
redirect(page_link_to('angeltypes'));
}
if ($request->has('confirmed')) {
UserAngelType_confirm($user_angeltype['id'], $user);
UserAngelType_confirm($user_angeltype['id'], $user['UID']);
engelsystem_log(sprintf(
'%s confirmed for angeltype %s',
@ -201,8 +203,8 @@ function user_angeltype_delete_controller()
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
if (empty($user_source)) {
$user_source = User::find($user_angeltype['user_id']);
if (!$user_source) {
error(__('User doesn\'t exist.'));
redirect(page_link_to('angeltypes'));
}
@ -268,8 +270,8 @@ function user_angeltype_update_controller()
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
if (empty($user_source)) {
$user_source = User::find($user_angeltype['user_id']);
if (!$user_source) {
error(__('User doesn\'t exist.'));
redirect(page_link_to('angeltypes'));
}
@ -322,8 +324,8 @@ function user_angeltype_add_controller()
if (request()->has('submit')) {
$user_source = load_user();
if (!UserAngelType_exists($user_source, $angeltype)) {
$user_angeltype_id = UserAngelType_create($user_source, $angeltype);
if (!UserAngelType_exists($user_source['UID'], $angeltype)) {
$user_angeltype_id = UserAngelType_create($user_source['UID'], $angeltype);
engelsystem_log(sprintf(
'User %s added to %s.',
@ -336,7 +338,7 @@ function user_angeltype_add_controller()
AngelType_name_render($angeltype)
));
UserAngelType_confirm($user_angeltype_id, $user_source);
UserAngelType_confirm($user_angeltype_id, $user_source['UID']);
engelsystem_log(sprintf(
'User %s confirmed as %s.',
User_Nick_render($user_source),
@ -363,14 +365,14 @@ function user_angeltype_join_controller($angeltype)
{
global $user, $privileges;
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype);
if (!empty($user_angeltype)) {
error(sprintf(__('You are already a %s.'), $angeltype['name']));
redirect(page_link_to('angeltypes'));
}
if (request()->has('confirmed')) {
$user_angeltype_id = UserAngelType_create($user, $angeltype);
$user_angeltype_id = UserAngelType_create($user['UID'], $angeltype);
$success_message = sprintf(__('You joined %s.'), $angeltype['name']);
engelsystem_log(sprintf(
@ -381,7 +383,7 @@ function user_angeltype_join_controller($angeltype)
success($success_message);
if (in_array('admin_user_angeltypes', $privileges)) {
UserAngelType_confirm($user_angeltype_id, $user);
UserAngelType_confirm($user_angeltype_id, $user['UID']);
engelsystem_log(sprintf(
'User %s confirmed as %s.',
User_Nick_render($user),

View File

@ -8,10 +8,10 @@
*/
function user_driver_license_required_hint()
{
global $user;
$user = auth()->user();
$angeltypes = User_angeltypes($user);
$user_driver_license = UserDriverLicense($user['UID']);
$angeltypes = User_angeltypes($user->id);
$user_driver_license = UserDriverLicense($user->id);
// User has already entered data, no hint needed.
if (!empty($user_driver_license)) {
@ -124,7 +124,7 @@ function user_driver_license_edit_controller()
if (UserDriverLicense_valid($user_driver_license)) {
if (empty($user_driver_license['user_id'])) {
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source);
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source['UID']);
} else {
UserDriverLicenses_update($user_driver_license);
}

View File

@ -1,5 +1,7 @@
<?php
use Engelsystem\Models\User\User;
/**
* Delete a work log entry.
*
@ -7,20 +9,20 @@
*/
function user_worklog_delete_controller()
{
global $user;
$user = auth()->user();
$request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) {
redirect(user_link($user['UID']));
redirect(user_link($user->id));
}
$user_source = User($userWorkLog['user_id']);
$user_source = User::find($userWorkLog['user_id']);
if ($request->has('confirmed')) {
UserWorkLog_delete($userWorkLog);
success(__('Work log entry deleted.'));
redirect(user_link($user_source['UID']));
redirect(user_link($user_source->id));
}
return [
@ -36,12 +38,12 @@ function user_worklog_delete_controller()
*/
function user_worklog_edit_controller()
{
global $user;
$user = auth()->user();
$request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) {
redirect(user_link($user['UID']));
redirect(user_link($user->id));
}
$user_source = User($userWorkLog['user_id']);
@ -108,15 +110,15 @@ function user_worklog_from_request($userWorkLog)
*/
function user_worklog_add_controller()
{
global $user;
$user = auth()->user();
$request = request();
$user_source = User($request->input('user_id'));
if (empty($user_source)) {
redirect(user_link($user['UID']));
redirect(user_link($user->id));
}
$userWorkLog = UserWorkLog_new($user_source);
$userWorkLog = UserWorkLog_new($user_source['UID']);
if ($request->has('submit')) {
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
@ -186,16 +188,17 @@ function user_worklog_delete_link($userWorkLog, $parameters = [])
*/
function user_worklog_controller()
{
global $user, $privileges;
global $privileges;
$user = auth()->user();
if (!in_array('admin_user_worklog', $privileges)) {
redirect(user_link($user['UID']));
redirect(user_link($user->id));
}
$request = request();
$action = $request->input('action');
if (!$request->has('action')) {
redirect(user_link($user['UID']));
redirect(user_link($user->id));
}
switch ($action) {

View File

@ -1,6 +1,8 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\PasswordReset;
use Engelsystem\Models\User\User;
use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilter;
@ -43,11 +45,12 @@ function users_controller()
*/
function user_delete_controller()
{
global $privileges, $user;
global $privileges;
$user = auth()->user();
$request = request();
if ($request->has('user_id')) {
$user_source = User($request->query->get('user_id'));
$user_source = User::find($request->query->get('user_id'));
} else {
$user_source = $user;
}
@ -57,9 +60,9 @@ function user_delete_controller()
}
// You cannot delete yourself
if ($user['UID'] == $user_source['UID']) {
if ($user->id == $user_source->id) {
error(__('You cannot delete yourself.'));
redirect(user_link($user['UID']));
redirect(user_link($user->id));
}
if ($request->has('submit')) {
@ -68,7 +71,7 @@ function user_delete_controller()
if (
!(
$request->has('password')
&& verify_password($request->postData('password'), $user['Passwort'], $user['UID'])
&& verify_password($request->postData('password'), $user->password, $user->id)
)
) {
$valid = false;
@ -76,7 +79,7 @@ function user_delete_controller()
}
if ($valid) {
User_delete($user_source['UID']);
User_delete($user_source->id);
mail_user_delete($user_source);
success(__('User deleted.'));
@ -87,7 +90,7 @@ function user_delete_controller()
}
return [
sprintf(__('Delete %s'), $user_source['Nick']),
sprintf(__('Delete %s'), $user_source->name),
User_delete_view($user_source)
];
}
@ -196,7 +199,7 @@ function user_controller()
}
}
$shifts = Shifts_by_user($user_source, in_array('user_shifts_admin', $privileges));
$shifts = Shifts_by_user($user_source['UID'], in_array('user_shifts_admin', $privileges));
foreach ($shifts as &$shift) {
// TODO: Move queries to model
$shift['needed_angeltypes'] = DB::select('
@ -228,7 +231,7 @@ function user_controller()
if ($user_source['force_active']) {
$tshirt_score = __('Enough');
} else {
$tshirt_score = sprintf('%.2f', User_tshirt_score($user_source)) . '&nbsp;h';
$tshirt_score = sprintf('%.2f', User_tshirt_score($user_source['UID'])) . '&nbsp;h';
}
return [
@ -237,14 +240,14 @@ function user_controller()
$user_source,
in_array('admin_user', $privileges),
User_is_freeloader($user_source),
User_angeltypes($user_source),
User_groups($user_source),
User_angeltypes($user_source['UID']),
User_groups($user_source['UID']),
$shifts,
$user['UID'] == $user_source['UID'],
$tshirt_score,
in_array('admin_active', $privileges),
in_array('admin_user_worklog', $privileges),
UserWorkLogsForUser($user_source)
UserWorkLogsForUser($user_source['UID'])
)
];
}
@ -270,7 +273,7 @@ function users_list_controller()
$users = Users($order_by);
foreach ($users as &$user) {
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user['UID']));
}
return [
@ -296,8 +299,8 @@ function users_list_controller()
function user_password_recovery_set_new_controller()
{
$request = request();
$user_source = User_by_password_recovery_token($request->input('token'));
if (empty($user_source)) {
$passwordReset = PasswordReset::whereToken($request->input('token'));
if (!$passwordReset) {
error(__('Token is not correct.'));
redirect(page_link_to('login'));
}
@ -319,8 +322,9 @@ function user_password_recovery_set_new_controller()
}
if ($valid) {
set_password($user_source['UID'], $request->postData('password'));
set_password($passwordReset->user->id, $request->postData('password'));
success(__('Password saved.'));
$passwordReset->delete();
redirect(page_link_to('login'));
}
}

View File

@ -1,19 +1,32 @@
<?php
use Engelsystem\Mail\EngelsystemMailer;
use Engelsystem\Models\User\User;
/**
* @param array $recipient_user
* @param string $title
* @param string $message
* @param bool $not_if_its_me
* @param array|User $recipientUser
* @param string $title
* @param string $message
* @param bool $notIfItsMe
* @return bool
*/
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false)
function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false)
{
$user = Auth()->user();
if ($not_if_its_me && $user->id == $recipient_user['UID']) {
if ($recipientUser instanceof User) {
$id = $user->id;
$lang = $user->settings->language;
$email = $user->contact->email ? $user->contact->email : $user->email;
$username = $user->name;
} else {
$id = $recipientUser['UID'];
$lang = $recipientUser['Sprache'];
$email = $recipientUser['email'];
$username = $recipientUser['Nick'];
}
if ($notIfItsMe && $user->id == $id) {
return true;
}
@ -23,12 +36,12 @@ function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_it
/** @var EngelsystemMailer $mailer */
$mailer = app('mailer');
$translator->setLocale($recipient_user['Sprache']);
$translator->setLocale($lang);
$status = $mailer->sendView(
$recipient_user['email'],
$email,
$title,
'emails/mail',
['username' => $recipient_user['Nick'], 'message' => $message]
['username' => $username, 'message' => $message]
);
$translator->setLocale($locale);

View File

@ -1,5 +1,7 @@
<?php
use Engelsystem\Models\User\User;
/**
* @param array $old_shift
* @param array $new_shift
@ -96,12 +98,12 @@ function mail_shift_delete($shift)
}
/**
* @param array $user
* @param User $user
* @param array $shift
*/
function mail_shift_assign($user, $shift)
{
if (!$user['email_shiftinfo']) {
if (!$user->settings->email_shiftinfo) {
return;
}
@ -117,12 +119,12 @@ function mail_shift_assign($user, $shift)
}
/**
* @param array $user
* @param User $user
* @param array $shift
*/
function mail_shift_removed($user, $shift)
{
if (!$user['email_shiftinfo']) {
if (!$user->settings->email_shiftinfo) {
return;
}

View File

@ -1,7 +1,9 @@
<?php
use Engelsystem\Models\User\User;
/**
* @param array $user
* @param User $user
* @return bool
*/
function mail_user_delete($user)

View File

@ -181,10 +181,10 @@ function AngelType_validate_name($name, $angeltype)
/**
* Returns all angeltypes and subscription state to each of them for given user.
*
* @param array $user
* @param int $userId
* @return array
*/
function AngelTypes_with_user($user)
function AngelTypes_with_user($userId)
{
return DB::select('
SELECT `AngelTypes`.*,
@ -194,7 +194,7 @@ function AngelTypes_with_user($user)
FROM `AngelTypes`
LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id`
AND `UserAngelTypes`.`user_id` = ?
ORDER BY `name`', [$user['UID']]);
ORDER BY `name`', [$userId]);
}
/**

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* Returns an array with the attributes of shift entries.
@ -74,7 +75,7 @@ function ShiftEntries_by_shift($shift_id)
*/
function ShiftEntry_create($shift_entry)
{
$user = User($shift_entry['UID']);
$user = User::find($shift_entry['UID']);
$shift = Shift($shift_entry['SID']);
mail_shift_assign($user, $shift);
$result = DB::insert('
@ -150,10 +151,10 @@ function ShiftEntry($shift_entry_id)
*/
function ShiftEntry_delete($shiftEntry)
{
mail_shift_removed(User($shiftEntry['UID']), Shift($shiftEntry['SID']));
mail_shift_removed(User::find($shiftEntry['UID']), Shift($shiftEntry['SID']));
DB::delete('DELETE FROM `ShiftEntry` WHERE `id` = ?', [$shiftEntry['id']]);
$signout_user = User($shiftEntry['UID']);
$signout_user = User::find($shiftEntry['UID']);
$shift = Shift($shiftEntry['SID']);
$shifttype = ShiftType($shift['shifttype_id']);
$room = Room($shift['RID']);
@ -171,10 +172,10 @@ function ShiftEntry_delete($shiftEntry)
/**
* Returns next (or current) shifts of given user.
*
* @param array $user
* @param int $userId
* @return array
*/
function ShiftEntries_upcoming_for_user($user)
function ShiftEntries_upcoming_for_user($userId)
{
return DB::select('
SELECT *
@ -186,7 +187,7 @@ function ShiftEntries_upcoming_for_user($user)
ORDER BY `Shifts`.`end`
',
[
$user['UID'],
$userId,
time(),
]
);
@ -195,10 +196,10 @@ function ShiftEntries_upcoming_for_user($user)
/**
* Returns shifts completed by the given user.
*
* @param array $user
* @param int $userId
* @return array
*/
function ShiftEntries_finished_by_user($user)
function ShiftEntries_finished_by_user($userId)
{
return DB::select('
SELECT *
@ -211,7 +212,7 @@ function ShiftEntries_finished_by_user($user)
ORDER BY `Shifts`.`end`
',
[
$user['UID'],
$userId,
time(),
]
);
@ -242,10 +243,10 @@ function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id)
/**
* Returns all freeloaded shifts for given user.
*
* @param array $user
* @param int $userId
* @return array
*/
function ShiftEntries_freeloaded_by_user($user)
function ShiftEntries_freeloaded_by_user($userId)
{
return DB::select('
SELECT *
@ -254,7 +255,7 @@ function ShiftEntries_freeloaded_by_user($user)
AND `UID` = ?
',
[
$user['UID']
$userId
]
);
}

View File

@ -326,7 +326,7 @@ function Shift_signup_allowed_angel(
}
if (empty($user_shifts)) {
$user_shifts = Shifts_by_user($user);
$user_shifts = Shifts_by_user($user['UID']);
}
$signed_up = false;
@ -352,7 +352,7 @@ function Shift_signup_allowed_angel(
}
if (empty($user_angeltype)) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_angeltype = UserAngelType_by_User_and_AngelType($user['UID'], $angeltype);
}
if (
@ -577,7 +577,7 @@ function Shift_update_by_psid($shift)
*/
function Shift_create($shift)
{
global $user;
$user = auth()->user();
DB::insert('
INSERT INTO `Shifts` (
`shifttype_id`,
@ -601,7 +601,7 @@ function Shift_create($shift)
$shift['title'],
$shift['URL'],
$shift['PSID'],
$user['UID'],
$user->id,
time(),
time(),
]
@ -613,11 +613,11 @@ function Shift_create($shift)
/**
* Return users shifts.
*
* @param array $user
* @param int $userId
* @param bool $include_freeload_comments
* @return array[]
*/
function Shifts_by_user($user, $include_freeload_comments = false)
function Shifts_by_user($userId, $include_freeload_comments = false)
{
return DB::select('
SELECT
@ -640,7 +640,7 @@ function Shifts_by_user($user, $include_freeload_comments = false)
ORDER BY `start`
',
[
$user['UID']
$userId
]
);
}

View File

@ -9,43 +9,43 @@ use Engelsystem\Database\DB;
/**
* Checks if a user joined an angeltype.
*
* @param array $user The user to be checked
* @param int $userId The user to be checked
* @param array $angeltype The angeltype to be checked
* @return boolean
*/
function UserAngelType_exists($user, $angeltype)
function UserAngelType_exists($userId, $angeltype)
{
return count(DB::select('
SELECT `id`
FROM `UserAngelTypes`
WHERE `UserAngelTypes`.`user_id`=?
AND `angeltype_id`=?
', [$user['UID'], $angeltype['id']])) > 0;
', [$userId, $angeltype['id']])) > 0;
}
/**
* List users angeltypes.
*
* @param array $user
* @param int $userId
* @return array[]
*/
function User_angeltypes($user)
function User_angeltypes($userId)
{
return DB::select('
SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter`
FROM `UserAngelTypes`
JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`
WHERE `UserAngelTypes`.`user_id`=?
', [$user['UID']]);
', [$userId]);
}
/**
* Gets unconfirmed user angeltypes for angeltypes of which the given user is a supporter.
*
* @param array $user
* @param int $userId
* @return array[]
*/
function User_unconfirmed_AngelTypes($user)
function User_unconfirmed_AngelTypes($userId)
{
return DB::select('
SELECT
@ -61,7 +61,7 @@ function User_unconfirmed_AngelTypes($user)
AND `UnconfirmedMembers`.`confirm_user_id` IS NULL
GROUP BY `UserAngelTypes`.`angeltype_id`, `UserAngelTypes`.`id`
ORDER BY `AngelTypes`.`name`
', [$user['UID']]);
', [$userId]);
}
/**
@ -126,32 +126,32 @@ function UserAngelTypes_delete_all($angeltype_id)
/**
* Confirm all unconfirmed UserAngelTypes for given Angeltype.
*
* @param int $angeltype_id
* @param array $confirm_user
* @param int $angeltype_id
* @param int $confirm_user_id
*/
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user_id)
{
DB::update('
UPDATE `UserAngelTypes`
SET `confirm_user_id`=?
WHERE `angeltype_id`=?
AND `confirm_user_id` IS NULL
', [$confirm_user['UID'], $angeltype_id]);
', [$confirm_user_id, $angeltype_id]);
}
/**
* Confirm an UserAngelType with confirming user.
*
* @param int $user_angeltype_id
* @param array $confirm_user
* @param int $user_angeltype_id
* @param int $confirm_user_id
*/
function UserAngelType_confirm($user_angeltype_id, $confirm_user)
function UserAngelType_confirm($user_angeltype_id, $confirm_user_id)
{
DB::update('
UPDATE `UserAngelTypes`
SET `confirm_user_id`=?
WHERE `id`=?
LIMIT 1', [$confirm_user['UID'], $user_angeltype_id]);
LIMIT 1', [$confirm_user_id, $user_angeltype_id]);
}
/**
@ -170,18 +170,18 @@ function UserAngelType_delete($user_angeltype)
/**
* Create an UserAngelType.
*
* @param array $user
* @param int $userId
* @param array $angeltype
* @return int
*/
function UserAngelType_create($user, $angeltype)
function UserAngelType_create($userId, $angeltype)
{
DB::insert('
INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`, `supporter`)
VALUES (?, ?, FALSE)
',
[
$user['UID'],
$userId,
$angeltype['id']
]
);
@ -209,11 +209,11 @@ function UserAngelType($user_angeltype_id)
/**
* Get an UserAngelType by user and angeltype.
*
* @param array $user
* @param int $userId
* @param array $angeltype
* @return array|null
*/
function UserAngelType_by_User_and_AngelType($user, $angeltype)
function UserAngelType_by_User_and_AngelType($userId, $angeltype)
{
$angelType = DB::selectOne('
SELECT *
@ -223,7 +223,7 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype)
LIMIT 1
',
[
$user['UID'],
$userId,
$angeltype['id']
]
);
@ -234,16 +234,16 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype)
/**
* Get an UserAngelTypes by user
*
* @param array $user
* @param int $userId
* @return array[]|null
*/
function UserAngelTypes_by_User($user)
function UserAngelTypes_by_User($userId)
{
return DB::select('
SELECT *
FROM `UserAngelTypes`
WHERE `user_id`=?
',
[$user['UID']]
[$userId]
);
}

View File

@ -57,12 +57,12 @@ function UserDriverLicense($user_id)
* Create a user's driver license entry
*
* @param array $user_driver_license The UserDriverLicense to create
* @param array $user
* @param int $userId
* @return array
*/
function UserDriverLicenses_create($user_driver_license, $user)
function UserDriverLicenses_create($user_driver_license, $userId)
{
$user_driver_license['user_id'] = $user['UID'];
$user_driver_license['user_id'] = $userId;
DB::insert('
INSERT INTO `UserDriverLicenses` (
`user_id`,

View File

@ -5,10 +5,10 @@ use Engelsystem\Database\DB;
/**
* Returns users groups
*
* @param array $user
* @param int $userId
* @return array[]
*/
function User_groups($user)
function User_groups($userId)
{
return DB::select('
SELECT `Groups`.*
@ -17,6 +17,6 @@ function User_groups($user)
WHERE `UserGroups`.`uid`=?
ORDER BY `UserGroups`.`group_id`
',
[$user['UID']]
[$userId]
);
}

View File

@ -21,13 +21,13 @@ function UserWorkLog($user_worklog_id)
/**
* Returns all work log entries for a user.
*
* @param array $user
* @param int $userId
* @return array[]
*/
function UserWorkLogsForUser($user)
function UserWorkLogsForUser($userId)
{
return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [
$user['UID']
$userId
]);
}
@ -123,10 +123,10 @@ function UserWorkLog_create($userWorkLog)
/**
* New user work log entry
*
* @param array[] $user
* @param int $userId
* @return array
*/
function UserWorkLog_new($user)
function UserWorkLog_new($userId)
{
$work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', time()));
@ -137,7 +137,7 @@ function UserWorkLog_new($user)
}
return [
'user_id' => $user['UID'],
'user_id' => $userId,
'work_timestamp' => $work_date,
'work_hours' => 0,
'comment' => ''

View File

@ -22,10 +22,10 @@ function User_delete($user_id)
* Returns the tshirt score (number of hours counted for tshirt).
* Accounts only ended shifts.
*
* @param array[] $user
* @param int $userId
* @return int
*/
function User_tshirt_score($user)
function User_tshirt_score($userId)
{
$shift_sum_formula = User_get_shifts_sum_query();
$result_shifts = DB::selectOne('
@ -36,7 +36,7 @@ function User_tshirt_score($user)
AND `Shifts`.`end` < ?
GROUP BY `User`.`UID`
', [
$user['UID'],
$userId,
time()
]);
if (!isset($result_shifts['tshirt_score'])) {
@ -50,7 +50,7 @@ function User_tshirt_score($user)
WHERE `User`.`UID` = ?
AND `UserWorkLog`.`work_timestamp` < ?
', [
$user['UID'],
$userId,
time()
]);
if (!isset($result_worklog['tshirt_score'])) {
@ -245,7 +245,7 @@ function User_is_freeloader($user)
{
global $user;
return count(ShiftEntries_freeloaded_by_user($user)) >= config('max_freeloadable_shifts');
return count(ShiftEntries_freeloaded_by_user($user['UID'])) >= config('max_freeloadable_shifts');
}
/**
@ -526,10 +526,10 @@ function User_generate_password_recovery_token(&$user)
* @param array $user
* @return float
*/
function User_get_eligable_voucher_count(&$user)
function User_get_eligable_voucher_count($user)
{
$voucher_settings = config('voucher_settings');
$shifts_done = count(ShiftEntries_finished_by_user($user));
$shifts_done = count(ShiftEntries_finished_by_user($user['UID']));
$earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
$eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -100,8 +101,8 @@ function admin_active()
if ($request->has('active') && preg_match('/^\d+$/', $request->input('active'))) {
$user_id = $request->input('active');
$user_source = User($user_id);
if (!empty($user_source)) {
$user_source = User::find($user_id);
if ($user_source) {
DB::update('UPDATE `User` SET `Aktiv`=1 WHERE `UID`=? LIMIT 1', [$user_id]);
engelsystem_log('User ' . User_Nick_render($user_source) . ' is active now.');
$msg = success(__('Angel has been marked as active.'), true);
@ -110,8 +111,8 @@ function admin_active()
}
} elseif ($request->has('not_active') && preg_match('/^\d+$/', $request->input('not_active'))) {
$user_id = $request->input('not_active');
$user_source = User($user_id);
if (!empty($user_source)) {
$user_source = User::find($user_id);
if (!$user_source) {
DB::update('UPDATE `User` SET `Aktiv`=0 WHERE `UID`=? LIMIT 1', [$user_id]);
engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.');
$msg = success(__('Angel has been marked as not active.'), true);
@ -120,8 +121,8 @@ function admin_active()
}
} elseif ($request->has('tshirt') && preg_match('/^\d+$/', $request->input('tshirt'))) {
$user_id = $request->input('tshirt');
$user_source = User($user_id);
if (!empty($user_source)) {
$user_source = User::find($user_id);
if (!$user_source) {
DB::update('UPDATE `User` SET `Tshirt`=1 WHERE `UID`=? LIMIT 1', [$user_id]);
engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.');
$msg = success(__('Angel has got a t-shirt.'), true);
@ -130,8 +131,8 @@ function admin_active()
}
} elseif ($request->has('not_tshirt') && preg_match('/^\d+$/', $request->input('not_tshirt'))) {
$user_id = $request->input('not_tshirt');
$user_source = User($user_id);
if (!empty($user_source)) {
$user_source = User::find($user_id);
if (!$user_source) {
DB::update('UPDATE `User` SET `Tshirt`=0 WHERE `UID`=? LIMIT 1', [$user_id]);
engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.');
$msg = success(__('Angel has got no t-shirt.'), true);

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -26,8 +27,8 @@ function admin_arrive()
if ($request->has('reset') && preg_match('/^\d+$/', $request->input('reset'))) {
$user_id = $request->input('reset');
$user_source = User($user_id);
if (!empty($user_source)) {
$user_source = User::find($user_id);
if ($user_source) {
DB::update('
UPDATE `User`
SET `Gekommen`=0, `arrival_date` = NULL
@ -36,14 +37,14 @@ function admin_arrive()
', [$user_id]);
engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source));
success(__('Reset done. Angel has not arrived.'));
redirect(user_link($user_source['UID']));
redirect(user_link($user_source->id));
} else {
$msg = error(__('Angel not found.'), true);
}
} elseif ($request->has('arrived') && preg_match('/^\d+$/', $request->input('arrived'))) {
$user_id = $request->input('arrived');
$user_source = User($user_id);
if (!empty($user_source)) {
$user_source = User::find($user_id);
if ($user_source) {
DB::update('
UPDATE `User`
SET `Gekommen`=1, `arrival_date`=?
@ -52,7 +53,7 @@ function admin_arrive()
', [time(), $user_id]);
engelsystem_log('User set has arrived: ' . User_Nick_render($user_source));
success(__('Angel has been marked as arrived.'));
redirect(user_link($user_source['UID']));
redirect(user_link($user_source->id));
} else {
$msg = error(__('Angel not found.'), true);
}

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -29,7 +30,7 @@ function admin_news()
switch ($request->input('action')) {
case 'edit':
$user_source = User($news['UID']);
$user_source = User::find($news['UID']);
if (
!in_array('admin_news_html', $privileges)
&& strip_tags($news['Text']) != $news['Text']

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -46,7 +47,7 @@ function admin_questions()
$unanswered_questions_table = [];
$questions = DB::select('SELECT * FROM `Questions` WHERE `AID` IS NULL');
foreach ($questions as $question) {
$user_source = User($question['UID']);
$user_source = User::find($question['UID']);
$unanswered_questions_table[] = [
'from' => User_Nick_render($user_source),
@ -66,7 +67,7 @@ function admin_questions()
$answered_questions_table = [];
$questions = DB::select('SELECT * FROM `Questions` WHERE NOT `AID` IS NULL');
foreach ($questions as $question) {
$user_source = User($question['UID']);
$user_source = User::find($question['UID']);
$answer_user_source = User($question['AID']);
$answered_questions_table[] = [
'from' => User_Nick_render($user_source),

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -27,8 +28,8 @@ function admin_user()
$user_id = $request->input('id');
if (!$request->has('action')) {
$user_source = User($user_id);
if (empty($user_source)) {
$user_source = User::find($user_id);
if (!$user_source) {
error(__('This user does not exist.'));
redirect(users_link());
}
@ -47,22 +48,20 @@ function admin_user()
$html .= '<input type="hidden" name="Type" value="Normal">' . "\n";
$html .= '<tr><td>' . "\n";
$html .= '<table>' . "\n";
$html .= ' <tr><td>Nick</td><td>' . '<input size="40" name="eNick" value="' . $user_source['Nick'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Nick</td><td>' . '<input size="40" name="eNick" value="' . $user_source->name . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Last login</td><td><p class="help-block">'
. date('Y-m-d H:i', $user_source['lastLogIn'])
. $user_source->last_login_at->format('Y-m-d H:i')
. '</p></td></tr>' . "\n";
$html .= ' <tr><td>Name</td><td>' . '<input size="40" name="eName" value="' . $user_source['Name'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Vorname</td><td>' . '<input size="40" name="eVorname" value="' . $user_source['Vorname'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Alter</td><td>' . '<input size="5" name="eAlter" value="' . $user_source['Alter'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Telefon</td><td>' . '<input type="tel" size="40" name="eTelefon" value="' . $user_source['Telefon'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Handy</td><td>' . '<input type= "tel" size="40" name="eHandy" value="' . $user_source['Handy'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>DECT</td><td>' . '<input size="4" name="eDECT" value="' . $user_source['DECT'] . '" class="form-control"></td></tr>' . "\n";
if ($user_source['email_by_human_allowed']) {
$html .= " <tr><td>email</td><td>" . '<input type="email" size="40" name="eemail" value="' . $user_source['email'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Name</td><td>' . '<input size="40" name="eName" value="' . $user_source->personalData->last_name . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Vorname</td><td>' . '<input size="40" name="eVorname" value="' . $user_source->personalData->first_name . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Handy</td><td>' . '<input type= "tel" size="40" name="eHandy" value="' . $user_source->contact->mobile . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>DECT</td><td>' . '<input size="4" name="eDECT" value="' . $user_source->contact->dect . '" class="form-control"></td></tr>' . "\n";
if ($user_source->settings->email_human) {
$html .= " <tr><td>email</td><td>" . '<input type="email" size="40" name="eemail" value="' . $user_source->email . '" class="form-control"></td></tr>' . "\n";
}
$html .= " <tr><td>jabber</td><td>" . '<input type="email" size="40" name="ejabber" value="' . $user_source['jabber'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Size</td><td>'
. html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size'], __('Please select...')) . '</td></tr>' . "\n";
. html_select_key('size', 'eSize', $tshirt_sizes, $user_source->personalData->shirt_size,
__('Please select...')) . '</td></tr>' . "\n";
$options = [
'1' => __('Yes'),
@ -71,23 +70,21 @@ function admin_user()
// Gekommen?
$html .= ' <tr><td>Gekommen</td><td>' . "\n";
$html .= html_options('eGekommen', $options, $user_source['Gekommen']) . '</td></tr>' . "\n";
$html .= html_options('eGekommen', $options, $user_source->state->arrived) . '</td></tr>' . "\n";
// Aktiv?
$html .= ' <tr><td>Aktiv</td><td>' . "\n";
$html .= html_options('eAktiv', $options, $user_source['Aktiv']) . '</td></tr>' . "\n";
$html .= html_options('eAktiv', $options, $user_source->state->active) . '</td></tr>' . "\n";
// Aktiv erzwingen
if (in_array('admin_active', $privileges)) {
$html .= ' <tr><td>' . __('Force active') . '</td><td>' . "\n";
$html .= html_options('force_active', $options, $user_source['force_active']) . '</td></tr>' . "\n";
$html .= html_options('force_active', $options, $user_source->state->force_active) . '</td></tr>' . "\n";
}
// T-Shirt bekommen?
$html .= ' <tr><td>T-Shirt</td><td>' . "\n";
$html .= html_options('eTshirt', $options, $user_source['Tshirt']) . '</td></tr>' . "\n";
$html .= ' <tr><td>Hometown</td><td>' . '<input size="40" name="Hometown" value="' . $user_source['Hometown'] . '" class="form-control"></td></tr>' . "\n";
$html .= html_options('eTshirt', $options, $user_source->personalData->shirt_size) . '</td></tr>' . "\n";
$html .= '</table>' . "\n" . '</td><td valign="top"></td></tr>';
@ -165,7 +162,7 @@ function admin_user()
}
$html .= buttons([
button(user_delete_link($user_source['UID']), glyph('lock') . __('delete'), 'btn-danger')
button(user_delete_link($user_source->id), glyph('lock') . __('delete'), 'btn-danger')
]);
$html .= "<hr />";
@ -227,7 +224,7 @@ function admin_user()
$user_groups_info[] = $groups[$group]['Name'];
}
}
$user_source = User($user_id);
$user_source = User::find($user_id);
engelsystem_log(
'Set groups of ' . User_Nick_render($user_source) . ' to: '
. join(', ', $user_groups_info)
@ -243,7 +240,7 @@ function admin_user()
case 'save':
$force_active = $user->state->force_active;
$user_source = User($user_id);
$user_source = User::find($user_id);
if (in_array('admin_active', $privileges)) {
$force_active = $request->input('force_active');
}
@ -252,37 +249,29 @@ function admin_user()
`Nick` = ?,
`Name` = ?,
`Vorname` = ?,
`Telefon` = ?,
`Handy` = ?,
`Alter` =?,
`DECT` = ?,
' . ($user_source['email_by_human_allowed']
' . ($user_source->settings->email_human
? '`email` = ' . DB::getPdo()->quote($request->postData('eemail')) . ','
: '') . '
`jabber` = ?,
`Size` = ?,
`Gekommen`= ?,
`Aktiv`= ?,
`force_active`= ?,
`Tshirt` = ?,
`Hometown` = ?
`Tshirt` = ?
WHERE `UID` = ?
LIMIT 1';
DB::update($sql, [
User_validate_Nick($request->postData('eNick')),
$request->postData('eName'),
$request->postData('eVorname'),
$request->postData('eTelefon'),
$request->postData('eHandy'),
$request->postData('eAlter'),
$request->postData('eDECT'),
$request->postData('ejabber'),
$request->postData('eSize'),
$request->postData('eGekommen'),
$request->postData('eAktiv'),
$force_active,
$request->postData('eTshirt'),
$request->postData('Hometown'),
$user_id,
]);
engelsystem_log(
@ -300,7 +289,7 @@ function admin_user()
&& $request->postData('new_pw') == $request->postData('new_pw2')
) {
set_password($user_id, $request->postData('new_pw'));
$user_source = User($user_id);
$user_source = User::find($user_id);
engelsystem_log('Set new password for ' . User_Nick_render($user_source));
$html .= success('Passwort neu gesetzt.', true);
} else {

View File

@ -2,6 +2,7 @@
use Carbon\Carbon;
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -264,7 +265,7 @@ function guest_register()
}
engelsystem_log(
'User ' . User_Nick_render(User($user_id))
'User ' . User_Nick_render(User::find($user_id))
. ' signed up as: ' . join(', ', $user_angel_types_info)
);
success(__('Angel registration successful!'));
@ -430,10 +431,10 @@ function guest_login()
if ($request->has('submit')) {
if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 0) {
$nick = User_validate_Nick($request->input('nick'));
$login_user = DB::selectOne('SELECT * FROM `User` WHERE `Nick`=?', [$nick]);
if (!empty($login_user)) {
$login_user = User::whereName($nick);
if ($login_user) {
if ($request->has('password')) {
if (!verify_password($request->postData('password'), $login_user['Passwort'], $login_user['UID'])) {
if (!verify_password($request->postData('password'), $login_user->password, $login_user->id)) {
$valid = false;
error(__('Your password is incorrect. Please try it again.'));
}
@ -450,9 +451,9 @@ function guest_login()
error(__('Please enter a nickname.'));
}
if ($valid && !empty($login_user)) {
$session->set('uid', $login_user['UID']);
$session->set('locale', $login_user['Sprache']);
if ($valid && $login_user) {
$session->set('uid', $login_user->id);
$session->set('locale', $login_user->settings->language);
redirect(page_link_to('news'));
}

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -34,13 +35,13 @@ function user_unread_messages()
*/
function user_messages()
{
global $user;
$user = auth()->user();
$request = request();
if (!$request->has('action')) {
$users = DB::select(
'SELECT `UID`, `Nick` FROM `User` WHERE NOT `UID`=? ORDER BY `Nick`',
[$user['UID']]
[$user->id]
);
$to_select_data = [
@ -61,8 +62,8 @@ function user_messages()
ORDER BY `isRead`,`Datum` DESC
',
[
$user['UID'],
$user['UID'],
$user->id,
$user->id,
]
);
@ -78,8 +79,8 @@ function user_messages()
];
foreach ($messages as $message) {
$sender_user_source = User($message['SUID']);
$receiver_user_source = User($message['RUID']);
$sender_user_source = User::find($message['SUID']);
$receiver_user_source = User::find($message['RUID']);
$messages_table_entry = [
'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '',
@ -89,7 +90,7 @@ function user_messages()
'text' => str_replace("\n", '<br />', $message['Text'])
];
if ($message['RUID'] == $user['UID']) {
if ($message['RUID'] == $user->id) {
if ($message['isRead'] == 'N') {
$messages_table_entry['actions'] = button(
page_link_to('user_messages', ['action' => 'read', 'id' => $message['id']]),
@ -134,7 +135,7 @@ function user_messages()
'SELECT `RUID` FROM `Messages` WHERE `id`=? LIMIT 1',
[$message_id]
);
if (!empty($message) && $message['RUID'] == $user['UID']) {
if (!empty($message) && $message['RUID'] == $user->id) {
DB::update(
'UPDATE `Messages` SET `isRead`=\'Y\' WHERE `id`=? LIMIT 1',
[$message_id]
@ -156,7 +157,7 @@ function user_messages()
'SELECT `SUID` FROM `Messages` WHERE `id`=? LIMIT 1',
[$message_id]
);
if (!empty($message) && $message['SUID'] == $user['UID']) {
if (!empty($message) && $message['SUID'] == $user->id) {
DB::delete('DELETE FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]);
redirect(page_link_to('user_messages'));
} else {

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -31,12 +32,12 @@ function user_myshifts()
$shift_entry_id = $user['UID'];
}
$shifts_user = DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$shift_entry_id]);
$shifts_user = User::find($shift_entry_id);
if ($request->has('reset')) {
if ($request->input('reset') == 'ack') {
User_reset_api_key($user);
success(__('Key changed.'));
redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']]));
redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id]));
}
return page_with_title(__('Reset API key'), [
error(
@ -68,7 +69,7 @@ function user_myshifts()
',
[
$shift_entry_id,
$shifts_user['UID'],
$shifts_user->id,
]
);
if (!empty($shift)) {
@ -87,7 +88,7 @@ function user_myshifts()
}
$comment = strip_request_item_nl('comment');
$user_source = User($shift['UID']);
$user_source = User::find($shift['UID']);
if ($valid) {
ShiftEntry_update([
@ -105,7 +106,7 @@ function user_myshifts()
. '. Freeloaded: ' . ($freeloaded ? 'YES Comment: ' . $freeload_comment : 'NO')
);
success(__('Shift saved.'));
redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']]));
redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id]));
}
}
@ -125,6 +126,6 @@ function user_myshifts()
}
}
redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']]));
redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id]));
return '';
}

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -111,9 +112,7 @@ function display_news($news)
}
$html .= '<span class="glyphicon glyphicon-time"></span> ' . date('Y-m-d H:i', $news['Datum']) . '&emsp;';
$user_source = User($news['UID']);
$html .= User_Nick_render($user_source);
$html .= User_Nick_render(User::find($news['UID']));
if ($page != 'news_comments') {
$html .= '&emsp;<a href="' . page_link_to('news_comments', ['nid' => $news['ID']]) . '">'
. '<span class="glyphicon glyphicon-comment"></span> '
@ -171,7 +170,7 @@ function user_news_comments()
[$nid]
);
foreach ($comments as $comment) {
$user_source = User($comment['UID']);
$user_source = User::find($comment['UID']);
$html .= '<div class="panel panel-default">';
$html .= '<div class="panel-body">' . nl2br(htmlspecialchars($comment['Text'])) . '</div>';

View File

@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
* @return string
@ -29,7 +30,7 @@ function user_questions()
[$user->id]
);
foreach ($answered_questions as &$question) {
$answer_user_source = User($question['AID']);
$answer_user_source = User::find($question['AID']);
$question['answer_user'] = User_Nick_render($answer_user_source);
}

View File

@ -217,7 +217,7 @@ function view_user_shifts()
}
$ownTypes = [];
foreach (UserAngelTypes_by_User($user) as $type) {
foreach (UserAngelTypes_by_User($user['UID']) as $type) {
$ownTypes[] = (int)$type['angeltype_id'];
}

View File

@ -8,11 +8,11 @@
*/
function engelsystem_log($message)
{
global $user;
$nick = "Guest";
$logger = app('logger');
$user = auth()->user();
if (isset($user)) {
if ($user) {
$nick = User_Nick_render($user);
}

View File

@ -75,10 +75,10 @@ function Shift_editor_info_render($shift)
*/
function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null)
{
global $user;
$user = auth()->user();
if (empty($user_angeltype)) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype);
}
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
@ -103,7 +103,8 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null)
*/
function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupState $shift_signup_state)
{
global $user, $privileges;
global $privileges;
$user = auth()->user();
$shift_admin = in_array('admin_shifts', $privileges);
$user_shift_admin = in_array('user_shifts_admin', $privileges);
@ -141,7 +142,7 @@ function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupSt
$admin_rooms ? button(room_link($room), glyph('map-marker') . $room['Name']) : '',
];
}
$buttons[] = button(user_link($user['UID']), '<span class="icon-icon_angel"></span> ' . __('My shifts'));
$buttons[] = button(user_link($user->id), '<span class="icon-icon_angel"></span> ' . __('My shifts'));
$content[] = buttons($buttons);
$content[] = Shift_view_header($shift, $room);

View File

@ -1,8 +1,10 @@
<?php
use Engelsystem\Models\User\User;
/**
* @param array $user_angeltype
* @param array $user
* @param User $user
* @param array $angeltype
* @param bool $supporter
* @return string
@ -89,7 +91,7 @@ function UserAngelTypes_confirm_all_view($angeltype)
/**
* @param array $user_angeltype
* @param array $user
* @param User $user
* @param array $angeltype
* @return string
*/
@ -118,7 +120,7 @@ function UserAngelType_confirm_view($user_angeltype, $user, $angeltype)
/**
* @param array $user_angeltype
* @param array $user
* @param User $user
* @param array $angeltype
* @return string
*/

View File

@ -1,9 +1,11 @@
<?php
use Engelsystem\Models\User\User;
/**
* Delete work log entry.
*
* @param array $user_source
* @param User $user_source
* @param array $userWorkLog
* @return string
*/
@ -15,7 +17,7 @@ function UserWorkLog_delete_view($user_source, $userWorkLog)
User_Nick_render($user_source)
), true),
buttons([
button(user_link($user_source['UID']), glyph('remove') . __('cancel')),
button(user_link($user_source->id), glyph('remove') . __('cancel')),
button(user_worklog_delete_link($userWorkLog, [
'confirmed' => 1
]), glyph('ok') . __('delete'), 'btn-danger')

View File

@ -145,7 +145,7 @@ function User_registration_success_view($event_welcome_message)
/**
* Gui for deleting user with password field.
*
* @param array $user
* @param User $user
* @return string
*/
function User_delete_view($user)
@ -153,7 +153,7 @@ function User_delete_view($user)
return page_with_title(sprintf(__('Delete %s'), User_Nick_render($user)), [
msg(),
buttons([
button(user_edit_link($user['UID']), glyph('chevron-left') . __('back'))
button(user_edit_link($user->id), glyph('chevron-left') . __('back'))
]),
error(
__('Do you really want to delete the user including all his shifts and every other piece of his data?'),
@ -292,7 +292,7 @@ function User_shift_state_render($user)
return '';
}
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
$upcoming_shifts = ShiftEntries_upcoming_for_user($user['UID']);
if (empty($upcoming_shifts)) {
return '<span class="text-success">' . __('Free') . '</span>';
@ -823,15 +823,25 @@ function User_groups_render($user_groups)
/**
* Render a user nickname.
*
* @param array $user_source
* @param array|User $user
* @return string
*/
function User_Nick_render($user_source)
function User_Nick_render($user)
{
if ($user instanceof User) {
$id = $user->id;
$name = $user->name;
$arrived = $user->state->arrived;
} else {
$id = $user['UID'];
$name = $user['Nick'];
$arrived = $user['Gekommen'];
}
return render_profile_link(
'<span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . '</a>',
$user_source['UID'],
($user_source['Gekommen'] ? '' : 'text-muted')
'<span class="icon-icon_angel"></span> ' . htmlspecialchars($name) . '</a>',
$id,
($arrived ? '' : 'text-muted')
);
}
@ -861,9 +871,7 @@ function render_profile_link($text, $user_id = null, $class = '')
*/
function render_user_departure_date_hint()
{
global $user;
if (!isset($user['planned_departure_date']) || empty($user['planned_departure_date'])) {
if (!auth()->user()->personalData->planned_departure_date) {
$text = __('Please enter your planned date of departure on your settings page to give us a feeling for teardown capacities.');
return render_profile_link($text, null, 'alert-link');
}
@ -895,9 +903,9 @@ function render_user_freeloader_hint()
*/
function render_user_arrived_hint()
{
global $user;
$user = auth()->user();
if ($user['Gekommen'] == 0) {
if (!$user->state->arrived) {
/** @var Carbon $buildup */
$buildup = config('buildup_start');
if (!empty($buildup) && $buildup->lessThan(new Carbon())) {
@ -913,9 +921,9 @@ function render_user_arrived_hint()
*/
function render_user_tshirt_hint()
{
global $user;
$user = auth()->user();
if (config('enable_tshirt_size') && $user['Size'] == '') {
if (config('enable_tshirt_size') && !$user->personalData->shirt_size) {
$text = __('You need to specify a tshirt size in your settings!');
return render_profile_link($text, null, 'alert-link');
}
@ -928,9 +936,9 @@ function render_user_tshirt_hint()
*/
function render_user_dect_hint()
{
global $user;
$user = auth()->user();
if ($user['Gekommen'] == 1 && $user['DECT'] == '') {
if ($user->state->arrived && !$user->contact->dect) {
$text = __('You need to specify a DECT phone number in your settings! If you don\'t have a DECT phone, just enter \'-\'.');
return render_profile_link($text, null, 'alert-link');
}

View File

@ -6,7 +6,9 @@ use Engelsystem\Models\BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property integer $user_id
* @property integer $user_id
*
* @property-read \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User $user
*
* @method static \Illuminate\Database\Query\Builder|static whereUserId($value)
*/