User: Bugfixes & code cleanup

main
Igor Scheller 6 years ago committed by msquare
parent d7aea575ff
commit a2aaba9cab

@ -102,7 +102,7 @@ class CreateUsersTables extends Migration
$user->save(); $user->save();
$contact = new Contact([ $contact = new Contact([
'dect' => ($data->DECT && $data->DECT != '-') ? $data->DECT : null, 'dect' => $data->DECT ? $data->DECT : null,
'mobile' => $data->Handy ?: ($data->Telefon ?: null), 'mobile' => $data->Handy ?: ($data->Telefon ?: null),
]); ]);
$contact->user() $contact->user()
@ -170,7 +170,7 @@ class CreateUsersTables extends Migration
public function down() public function down()
{ {
$this->schema->create('User', function (Blueprint $table) { $this->schema->create('User', function (Blueprint $table) {
$table->increments('UID'); $table->integer('UID', true, false);
$table->string('Nick', 23)->unique()->default(''); $table->string('Nick', 23)->unique()->default('');
$table->string('Name', 23)->nullable(); $table->string('Name', 23)->nullable();

@ -3,6 +3,7 @@
namespace Engelsystem\Migrations; namespace Engelsystem\Migrations;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use stdClass;
trait ChangesReferences trait ChangesReferences
{ {

@ -11,7 +11,7 @@ use Engelsystem\ShiftSignupState;
function shift_entries_controller() function shift_entries_controller()
{ {
$user = auth()->user(); $user = auth()->user();
if ($user) { if (!$user) {
redirect(page_link_to('login')); redirect(page_link_to('login'));
} }
@ -75,10 +75,9 @@ function shift_entry_create_controller()
*/ */
function shift_entry_create_controller_admin($shift, $angeltype) function shift_entry_create_controller_admin($shift, $angeltype)
{ {
$user = auth()->user(); $signup_user = auth()->user();
$request = request(); $request = request();
$signup_user = $user;
if ($request->has('user_id')) { if ($request->has('user_id')) {
$signup_user = User::find($request->input('user_id')); $signup_user = User::find($request->input('user_id'));
} }
@ -113,8 +112,8 @@ function shift_entry_create_controller_admin($shift, $angeltype)
$users = User::all(); $users = User::all();
$users_select = []; $users_select = [];
foreach ($users as $u) { foreach ($users as $user) {
$users_select[$u->id] = $u->name; $users_select[$user->id] = $user->name;
} }
$angeltypes_select = []; $angeltypes_select = [];

@ -332,13 +332,12 @@ function shifts_controller()
function shift_next_controller() function shift_next_controller()
{ {
global $privileges; global $privileges;
$user = auth()->user();
if (!in_array('user_shifts', $privileges)) { if (!in_array('user_shifts', $privileges)) {
redirect(page_link_to('/')); redirect(page_link_to('/'));
} }
$upcoming_shifts = ShiftEntries_upcoming_for_user($user->id); $upcoming_shifts = ShiftEntries_upcoming_for_user(auth()->user()->id);
if (!empty($upcoming_shifts)) { if (!empty($upcoming_shifts)) {
redirect(shift_link($upcoming_shifts[0])); redirect(shift_link($upcoming_shifts[0]));

@ -9,9 +9,7 @@ use Engelsystem\Models\User\User;
*/ */
function user_angeltypes_unconfirmed_hint() function user_angeltypes_unconfirmed_hint()
{ {
$user = auth()->user(); $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes(auth()->user()->id);
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user->id);
if (count($unconfirmed_user_angeltypes) == 0) { if (count($unconfirmed_user_angeltypes) == 0) {
return null; return null;
} }

@ -76,9 +76,8 @@ function user_driver_license_edit_link($user = null)
*/ */
function user_driver_license_load_user() function user_driver_license_load_user()
{ {
$user = auth()->user();
$request = request(); $request = request();
$user_source = $user; $user_source = auth()->user();
if ($request->has('user_id')) { if ($request->has('user_id')) {
$user_source = User::find($request->input('user_id')); $user_source = User::find($request->input('user_id'));

@ -9,12 +9,10 @@ use Engelsystem\Models\User\User;
*/ */
function user_worklog_delete_controller() function user_worklog_delete_controller()
{ {
$user = auth()->user();
$request = request(); $request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id')); $userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) { if (empty($userWorkLog)) {
redirect(user_link($user->id)); redirect(user_link(auth()->user()->id));
} }
$user_source = User::find($userWorkLog['user_id']); $user_source = User::find($userWorkLog['user_id']);
@ -38,12 +36,10 @@ function user_worklog_delete_controller()
*/ */
function user_worklog_edit_controller() function user_worklog_edit_controller()
{ {
$user = auth()->user();
$request = request(); $request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id')); $userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) { if (empty($userWorkLog)) {
redirect(user_link($user->id)); redirect(user_link(auth()->user()->id));
} }
$user_source = User::find($userWorkLog['user_id']); $user_source = User::find($userWorkLog['user_id']);
@ -110,12 +106,10 @@ function user_worklog_from_request($userWorkLog)
*/ */
function user_worklog_add_controller() function user_worklog_add_controller()
{ {
$user = auth()->user();
$request = request(); $request = request();
$user_source = User::find($request->input('user_id')); $user_source = User::find($request->input('user_id'));
if (!$user_source) { if (!$user_source) {
redirect(user_link($user->id)); redirect(user_link(auth()->user()->id));
} }
$userWorkLog = UserWorkLog_new($user_source->id); $userWorkLog = UserWorkLog_new($user_source->id);

@ -167,7 +167,7 @@ function user_edit_vouchers_controller()
if ($valid) { if ($valid) {
$user_source->state->got_voucher = $vouchers; $user_source->state->got_voucher = $vouchers;
$user->state->save(); $user_source->state->save();
success(__('Saved the number of vouchers.')); success(__('Saved the number of vouchers.'));
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers', engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers',
@ -268,26 +268,30 @@ function users_list_controller()
redirect(page_link_to('')); redirect(page_link_to(''));
} }
$order_by = 'Nick'; $order_by = 'name';
if ($request->has('OrderBy') && in_array($request->input('OrderBy'), [ if ($request->has('OrderBy') && in_array($request->input('OrderBy'), [
'Nick', 'name',
'Name', 'last_name',
'Vorname', 'first_name',
'DECT', 'dect',
'email', 'email',
'Size', 'shirt_size',
'Gekommen', 'arrived',
'Aktiv', 'active',
'force_active', 'force_active',
'Tshirt', 'got_shirt',
'lastLogIn' 'last_login_at',
])) { ])) {
$order_by = $request->input('OrderBy'); $order_by = $request->input('OrderBy');
} }
/** @var User[] $users */ /** @var User[] $users */
$users = User::query() $users = User::query()
->leftJoin('users_contact', 'users.id', '=', 'users_contact.user_id')
->leftJoin('users_personal_data', 'users.id', '=', 'users_personal_data.user_id')
->leftJoin('users_state', 'users.id', '=', 'users_state.user_id')
->orderBy($order_by) ->orderBy($order_by)
->orderBy('name')
->get(); ->get();
foreach ($users as $user) { foreach ($users as $user) {
$user->setAttribute('freeloads', count(ShiftEntries_freeloaded_by_user($user->id))); $user->setAttribute('freeloads', count(ShiftEntries_freeloaded_by_user($user->id)));

@ -4,7 +4,7 @@ use Engelsystem\Mail\EngelsystemMailer;
use Engelsystem\Models\User\User; use Engelsystem\Models\User\User;
/** /**
* @param array|User $recipientUser * @param User $recipientUser
* @param string $title * @param string $title
* @param string $message * @param string $message
* @param bool $notIfItsMe * @param bool $notIfItsMe
@ -12,21 +12,7 @@ use Engelsystem\Models\User\User;
*/ */
function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false) function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false)
{ {
$user = Auth()->user(); if ($notIfItsMe && Auth()->user()->id == $recipientUser->id) {
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; return true;
} }
@ -36,12 +22,12 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe
/** @var EngelsystemMailer $mailer */ /** @var EngelsystemMailer $mailer */
$mailer = app('mailer'); $mailer = app('mailer');
$translator->setLocale($lang); $translator->setLocale($recipientUser->settings->language);
$status = $mailer->sendView( $status = $mailer->sendView(
$email, $recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email,
$title, $title,
'emails/mail', 'emails/mail',
['username' => $username, 'message' => $message] ['username' => $recipientUser->name, 'message' => $message]
); );
$translator->setLocale($locale); $translator->setLocale($locale);

@ -64,7 +64,7 @@ function mail_shift_change($old_shift, $new_shift)
$message .= $new_room['Name'] . "\n"; $message .= $new_room['Name'] . "\n";
foreach ($users as $user) { foreach ($users as $user) {
$user = User::find($user->id); $user = (new User())->forceFill($user);
if ($user->settings->email_shiftinfo) { if ($user->settings->email_shiftinfo) {
engelsystem_email_to_user( engelsystem_email_to_user(
$user, $user,
@ -92,7 +92,7 @@ function mail_shift_delete($shift)
$message .= $room['Name'] . "\n"; $message .= $room['Name'] . "\n";
foreach ($users as $user) { foreach ($users as $user) {
$user = User::find($user->id); $user = (new User())->forceFill($user);
if ($user->settings->email_shiftinfo) { if ($user->settings->email_shiftinfo) {
engelsystem_email_to_user($user, __('Your Shift was deleted'), $message, true); engelsystem_email_to_user($user, __('Your Shift was deleted'), $message, true);
} }

@ -233,9 +233,9 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
*/ */
function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
{ {
$sql = ' $sql = sprintf('
SELECT SELECT
users.* users.*,
`ShiftEntry`.`UID`, `ShiftEntry`.`UID`,
`ShiftEntry`.`TID`, `ShiftEntry`.`TID`,
`ShiftEntry`.`SID`, `ShiftEntry`.`SID`,
@ -244,9 +244,12 @@ function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
FROM `Shifts` FROM `Shifts`
JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID` JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID`
JOIN `users` ON `ShiftEntry`.`UID`=`users`.`id` JOIN `users` ON `ShiftEntry`.`UID`=`users`.`id`
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ') WHERE `Shifts`.`RID` IN (%s)
AND `start` BETWEEN ? AND ? AND `start` BETWEEN ? AND ?
ORDER BY `Shifts`.`start`'; ORDER BY `Shifts`.`start`
',
implode(',', $shiftsFilter->getRooms())
);
return DB::select( return DB::select(
$sql, $sql,
[ [
@ -575,7 +578,6 @@ function Shift_update_by_psid($shift)
*/ */
function Shift_create($shift) function Shift_create($shift)
{ {
$user = auth()->user();
DB::insert(' DB::insert('
INSERT INTO `Shifts` ( INSERT INTO `Shifts` (
`shifttype_id`, `shifttype_id`,
@ -599,7 +601,7 @@ function Shift_create($shift)
$shift['title'], $shift['title'],
$shift['URL'], $shift['URL'],
$shift['PSID'], $shift['PSID'],
$user->id, auth()->user()->id,
time(), time(),
time(), time(),
] ]

@ -73,16 +73,16 @@ function User_is_freeloader($user)
function Users_by_angeltype_inverted($angeltype) function Users_by_angeltype_inverted($angeltype)
{ {
return User::query() return User::query()
->leftJoin('UserAngelTypes', 'users.id', '=', 'UserAngelTypes.user_id') ->select('users.*')
->leftJoin('UserAngelTypes', function ($query) use ($angeltype) { ->leftJoin('UserAngelTypes', function ($query) use ($angeltype) {
/** @var JoinClause $query */ /** @var JoinClause $query */
$query $query
->on('users.id', '=', 'UserAngelTypes.user_id') ->on('users.id', '=', 'UserAngelTypes.user_id')
->on('UserAngelTypes.angeltype_id', '=', $angeltype['id']); ->where('UserAngelTypes.angeltype_id', '=', $angeltype['id']);
}) })
->whereNull('UserAngelTypes.id') ->whereNull('UserAngelTypes.id')
->orderBy('users.name') ->orderBy('users.name')
->get('users.*'); ->get();
} }
/** /**
@ -94,17 +94,17 @@ function Users_by_angeltype_inverted($angeltype)
function Users_by_angeltype($angeltype) function Users_by_angeltype($angeltype)
{ {
return User::query() return User::query()
->select('users.*',
'UserAngelTypes.id AS user_angeltype_id',
'UserAngelTypes.confirm_user_id',
'UserAngelTypes.supporter',
'UserDriverLicenses.user_id AS wants_to_drive',
'UserDriverLicenses.*'
)
->join('UserAngelTypes', 'users.id', '=', 'UserAngelTypes.user_id') ->join('UserAngelTypes', 'users.id', '=', 'UserAngelTypes.user_id')
->leftJoin('UserDriverLicenses', 'users.id', '=', 'UserDriverLicenses.user_id') ->leftJoin('UserDriverLicenses', 'users.id', '=', 'UserDriverLicenses.user_id')
->where('UserAngelTypes.angeltype_id', '=', $angeltype['id']) ->where('UserAngelTypes.angeltype_id', '=', $angeltype['id'])
->get([ ->get();
'users.*',
'`UserAngelTypes`.`id` AS `user_angeltype_id`',
'`UserAngelTypes`.`confirm_user_id`',
'`UserAngelTypes`.`supporter`',
'(`UserDriverLicenses`.`user_id` IS NOT NULL) AS `wants_to_drive`',
'`UserDriverLicenses`.*',
]);
} }
/** /**
@ -226,6 +226,7 @@ function User_reset_api_key($user, $log = true)
function User_generate_password_recovery_token($user) function User_generate_password_recovery_token($user)
{ {
$reset = PasswordReset::findOrNew($user->id); $reset = PasswordReset::findOrNew($user->id);
$reset->user_id = $user->id;
$reset->token = md5($user->name . time() . rand()); $reset->token = md5($user->name . time() . rand());
$reset->save(); $reset->save();

@ -2,6 +2,8 @@
use Engelsystem\Models\User\State; use Engelsystem\Models\User\State;
use Engelsystem\Models\User\User; use Engelsystem\Models\User\User;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
/** /**
* @return string * @return string
@ -23,8 +25,7 @@ function admin_active()
$msg = ''; $msg = '';
$search = ''; $search = '';
$forced_count = State::whereForceActive(true)->count(); $forced_count = State::whereForceActive(true)->count();
$count = $forced_count; $count = null;
$limit = '';
$set_active = ''; $set_active = '';
if ($request->has('search')) { if ($request->has('search')) {
@ -34,8 +35,6 @@ function admin_active()
$show_all_shifts = $request->has('show_all_shifts'); $show_all_shifts = $request->has('show_all_shifts');
if ($request->has('set_active')) { if ($request->has('set_active')) {
$valid = true;
if ($request->has('count') && preg_match('/^\d+$/', $request->input('count'))) { if ($request->has('count') && preg_match('/^\d+$/', $request->input('count'))) {
$count = strip_request_item('count'); $count = strip_request_item('count');
if ($count < $forced_count) { if ($count < $forced_count) {
@ -46,41 +45,43 @@ function admin_active()
redirect(page_link_to('admin_active')); redirect(page_link_to('admin_active'));
} }
} else { } else {
$valid = false; $msg .= error(__('Please enter a number of angels to be marked as active.'));
$msg .= error(__('Please enter a number of angels to be marked as active.'), true); redirect(page_link_to('admin_active'));
} }
if ($valid) {
$limit = ' LIMIT ' . $count;
}
if ($request->has('ack')) { if ($request->has('ack')) {
State::query() State::query()
->where('got_shirt', '=', false)
->where('got_shirt', '=', false) ->where('got_shirt', '=', false)
->update(['active' => false]); ->update(['active' => false]);
/** @var User[] $users */ $query = User::query()
$users = User::query()->raw(sprintf(' ->selectRaw(
SELECT sprintf(
`users`.*, '
COUNT(`ShiftEntry`.`id`) AS `shift_count`, users.*,
COUNT(ShiftEntry.id) AS shift_count,
(%s + ( (%s + (
SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id` SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
AND `work_timestamp` < %s AND `work_timestamp` < ?
)) AS `shift_length` )) AS `shift_length`
FROM `users`
LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID`
LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID`
LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id`
WHERE `users_state`.`arrived` = 1
AND `users_state`.`force_active` = 0
GROUP BY `users`.`id`
ORDER BY `force_active` DESC, `shift_length` DESC
%s
', ',
$shift_sum_formula, $shift_sum_formula
time(), ),
$limit [time()]
)); )
->leftJoin('ShiftEntry', 'users.id', '=', 'ShiftEntry.UID')
->leftJoin('Shifts', 'ShiftEntry.SID', '=', 'Shifts.SID')
->leftJoin('users_state', 'users.id', '=', 'users_state.user_id')
->where('users_state.arrived', '=', true)
->where('users_state.force_active', '=', false)
->groupBy('users.id')
->orderByDesc('force_active')
->orderByDesc('shift_length')
->orderByDesc('name')
->limit($count);
$users = $query->get();
$user_nicks = []; $user_nicks = [];
foreach ($users as $usr) { foreach ($users as $usr) {
$usr->state->active = true; $usr->state->active = true;
@ -88,10 +89,9 @@ function admin_active()
$user_nicks[] = User_Nick_render($usr); $user_nicks[] = User_Nick_render($usr);
} }
State::whereForceActive(true)->update(['active' => 'true']); State::whereForceActive(true)->update(['active' => true]);
engelsystem_log('These angels are active now: ' . join(', ', $user_nicks)); engelsystem_log('These angels are active now: ' . join(', ', $user_nicks));
$limit = '';
$msg = success(__('Marked angels.'), true); $msg = success(__('Marked angels.'), true);
} else { } else {
$set_active = '<a href="' . page_link_to('admin_active', ['search' => $search]) . '">&laquo; ' $set_active = '<a href="' . page_link_to('admin_active', ['search' => $search]) . '">&laquo; '
@ -120,7 +120,7 @@ function admin_active()
} elseif ($request->has('not_active') && preg_match('/^\d+$/', $request->input('not_active'))) { } elseif ($request->has('not_active') && preg_match('/^\d+$/', $request->input('not_active'))) {
$user_id = $request->input('not_active'); $user_id = $request->input('not_active');
$user_source = User::find($user_id); $user_source = User::find($user_id);
if (!$user_source) { if ($user_source) {
$user_source->state->active = false; $user_source->state->active = false;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.'); engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.');
@ -131,7 +131,7 @@ function admin_active()
} elseif ($request->has('tshirt') && preg_match('/^\d+$/', $request->input('tshirt'))) { } elseif ($request->has('tshirt') && preg_match('/^\d+$/', $request->input('tshirt'))) {
$user_id = $request->input('tshirt'); $user_id = $request->input('tshirt');
$user_source = User::find($user_id); $user_source = User::find($user_id);
if (!$user_source) { if ($user_source) {
$user_source->state->got_shirt = true; $user_source->state->got_shirt = true;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.'); engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.');
@ -142,7 +142,7 @@ function admin_active()
} elseif ($request->has('not_tshirt') && preg_match('/^\d+$/', $request->input('not_tshirt'))) { } elseif ($request->has('not_tshirt') && preg_match('/^\d+$/', $request->input('not_tshirt'))) {
$user_id = $request->input('not_tshirt'); $user_id = $request->input('not_tshirt');
$user_source = User::find($user_id); $user_source = User::find($user_id);
if (!$user_source) { if ($user_source) {
$user_source->state->got_shirt = false; $user_source->state->got_shirt = false;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.'); engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.');
@ -152,28 +152,45 @@ function admin_active()
} }
} }
$users = User::query()->raw(sprintf(' $query = User::query()
SELECT ->selectRaw(
`users`.*, sprintf(
COUNT(`ShiftEntry`.`id`) AS `shift_count`, '
users.*,
COUNT(ShiftEntry.id) AS shift_count,
(%s + ( (%s + (
SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id` SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
AND `work_timestamp` < %s AND `work_timestamp` < ?
)) AS `shift_length` )) AS `shift_length`
FROM `users`
LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id`
LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID`
LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` '
. ($show_all_shifts ? '' : 'AND (`Shifts`.`end` < ' . time() . " OR `Shifts`.`end` IS NULL)") . '
WHERE `users_state`.`arrived` = 1
GROUP BY `users`.`id`
ORDER BY `users_state`.`force_active` DESC, `shift_length` DESC
%s
', ',
$shift_sum_formula, $shift_sum_formula
time(), ),
$limit [time()]
)); )
->leftJoin('ShiftEntry', 'users.id', '=', 'ShiftEntry.UID')
->leftJoin('Shifts', function ($join) use ($show_all_shifts) {
/** @var JoinClause $join */
$join->on('ShiftEntry.SID', '=', 'Shifts.SID');
if ($show_all_shifts) {
$join->where(function ($query) {
/** @var Builder $query */
$query->where('Shifts.end', '<', time())
->orWhereNull('Shifts.end');
});
}
})
->leftJoin('users_state', 'users.id', '=', 'users_state.user_id')
->where('users_state.arrived', '=', true)
->groupBy('users.id')
->orderByDesc('force_active')
->orderByDesc('shift_length')
->orderByDesc('name');
if (!is_null($count)) {
$query->limit($count);
}
$users = $query->get();
$matched_users = []; $matched_users = [];
if ($search == '') { if ($search == '') {
$tokens = []; $tokens = [];
@ -202,6 +219,7 @@ function admin_active()
$userData['active'] = glyph_bool($usr->state->active == 1); $userData['active'] = glyph_bool($usr->state->active == 1);
$userData['force_active'] = glyph_bool($usr->state->force_active == 1); $userData['force_active'] = glyph_bool($usr->state->force_active == 1);
$userData['tshirt'] = glyph_bool($usr->state->got_shirt == 1); $userData['tshirt'] = glyph_bool($usr->state->got_shirt == 1);
$userData['shift_count'] = $usr['shift_count'];
$actions = []; $actions = [];
if (!$usr->state->active) { if (!$usr->state->active) {
@ -262,6 +280,7 @@ function admin_active()
foreach (array_keys($tshirt_sizes) as $size) { foreach (array_keys($tshirt_sizes) as $size) {
$gc = State::query() $gc = State::query()
->leftJoin('users_settings', 'users_state.user_id', '=', 'users_settings.user_id') ->leftJoin('users_settings', 'users_state.user_id', '=', 'users_settings.user_id')
->leftJoin('users_personal_data', 'users_state.user_id', '=', 'users_personal_data.user_id')
->where('users_state.got_shirt', '=', true) ->where('users_state.got_shirt', '=', true)
->where('users_personal_data.shirt_size', '=', $size) ->where('users_personal_data.shirt_size', '=', $size)
->count(); ->count();
@ -283,7 +302,7 @@ function admin_active()
form_submit('submit', __('Search')) form_submit('submit', __('Search'))
], page_link_to('admin_active')), ], page_link_to('admin_active')),
$set_active == '' ? form([ $set_active == '' ? form([
form_text('count', __('How much angels should be active?'), $count), form_text('count', __('How much angels should be active?'), $count ? $count : $forced_count),
form_submit('set_active', __('Preview')) form_submit('set_active', __('Preview'))
]) : $set_active, ]) : $set_active,
$msg . msg(), $msg . msg(),

@ -44,7 +44,7 @@ function admin_arrive()
if ($user_source) { if ($user_source) {
$user_source->state->arrived = true; $user_source->state->arrived = true;
$user_source->state->arrival_date = new Carbon\Carbon(); $user_source->state->arrival_date = new Carbon\Carbon();
$user_source->personalData->save(); $user_source->state->save();
engelsystem_log('User set has arrived: ' . User_Nick_render($user_source)); engelsystem_log('User set has arrived: ' . User_Nick_render($user_source));
success(__('Angel has been marked as arrived.')); success(__('Angel has been marked as arrived.'));
@ -170,7 +170,7 @@ function admin_arrive()
form_submit('submit', __('Search')) form_submit('submit', __('Search'))
]), ]),
table([ table([
'nick' => __('Nickname'), 'name' => __('Nickname'),
'rendered_planned_arrival_date' => __('Planned arrival'), 'rendered_planned_arrival_date' => __('Planned arrival'),
'arrived' => __('Arrived?'), 'arrived' => __('Arrived?'),
'rendered_arrival_date' => __('Arrival date'), 'rendered_arrival_date' => __('Arrival date'),

@ -2,6 +2,7 @@
use Engelsystem\Database\DB; use Engelsystem\Database\DB;
use Engelsystem\Models\User\User; use Engelsystem\Models\User\User;
use Illuminate\Database\Query\JoinClause;
/** /**
* @return string * @return string
@ -24,18 +25,6 @@ function admin_free()
$search = strip_request_item('search'); $search = strip_request_item('search');
} }
$angelTypeSearch = '';
$angelType = $request->input('angeltype', '');
if (!empty($angelType)) {
$angelTypeSearch = ' INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = '
. DB::getPdo()->quote($angelType)
. ' AND `UserAngelTypes`.`user_id` = `users`.`id`';
if ($request->has('confirmed_only')) {
$angelTypeSearch .= ' AND `UserAngelTypes`.`confirm_user_id`';
}
$angelTypeSearch .= ') ';
}
$angel_types_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`'); $angel_types_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
$angel_types = [ $angel_types = [
'' => 'alle Typen' '' => 'alle Typen'
@ -44,27 +33,34 @@ function admin_free()
$angel_types[$angel_type['id']] = $angel_type['name']; $angel_types[$angel_type['id']] = $angel_type['name'];
} }
/** @var User[] $users */ $angelType = $request->input('angeltype', '');
$users = User::query()->raw(sprintf(' $query = User::query()
SELECT `users`.* ->select('users.*')
FROM `users` ->leftJoin('ShiftEntry', 'users.id', 'ShiftEntry.UID')
%s ->leftJoin('users_state', 'users.id', 'users_state.user_id')
LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID` ->leftJoin('Shifts', function ($join) {
LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id` /** @var JoinClause $join */
LEFT JOIN `Shifts` $join->on('ShiftEntry.SID', '=', 'Shifts.SID')
ON ( ->where('Shifts.start', '<', time())
`ShiftEntry`.`SID` = `Shifts`.`SID` ->where('Shifts.end', '>', time());
AND `Shifts`.`start` < %u })
AND `Shifts`.`end` > %u ->where('users_state.arrived', '=', 1)
) ->whereNull('Shifts.SID')
WHERE `users_state`.`arrived` = 1 ->groupBy('users.id');
AND `Shifts`.`SID` IS NULL
GROUP BY `users`.`id` if (!empty($angelType)) {
ORDER BY `users` $query->join('UserAngelTypes', function ($join) use ($angelType, $request, $query) {
', $angelTypeSearch, time(), time() /** @var JoinClause $join */
) $join->on('UserAngelTypes.user_id', '=', 'users.id')
); ->where('UserAngelTypes.angeltype_id', '=', $angelType);
if ($request->has('confirmed_only')) {
$join->whereNotNull('UserAngelTypes.confirm_user_id');
}
});
}
$users = $query->get();
$free_users_table = []; $free_users_table = [];
if ($search == '') { if ($search == '') {
$tokens = []; $tokens = [];

@ -60,8 +60,13 @@ function admin_user()
$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>email</td><td>" . '<input type="email" size="40" name="eemail" value="' . $user_source->email . '" class="form-control"></td></tr>' . "\n";
} }
$html .= ' <tr><td>Size</td><td>' $html .= ' <tr><td>Size</td><td>'
. html_select_key('size', 'eSize', $tshirt_sizes, $user_source->personalData->shirt_size, . html_select_key(
__('Please select...')) . '</td></tr>' . "\n"; 'size',
'eSize',
$tshirt_sizes, $user_source->personalData->shirt_size,
__('Please select...')
)
. '</td></tr>' . "\n";
$options = [ $options = [
'1' => __('Yes'), '1' => __('Yes'),
@ -84,7 +89,7 @@ function admin_user()
// T-Shirt bekommen? // T-Shirt bekommen?
$html .= ' <tr><td>T-Shirt</td><td>' . "\n"; $html .= ' <tr><td>T-Shirt</td><td>' . "\n";
$html .= html_options('eTshirt', $options, $user_source->personalData->shirt_size) . '</td></tr>' . "\n"; $html .= html_options('eTshirt', $options, $user_source->state->got_shirt) . '</td></tr>' . "\n";
$html .= '</table>' . "\n" . '</td><td valign="top"></td></tr>'; $html .= '</table>' . "\n" . '</td><td valign="top"></td></tr>';
@ -244,7 +249,7 @@ function admin_user()
if (in_array('admin_active', $privileges)) { if (in_array('admin_active', $privileges)) {
$force_active = $request->input('force_active'); $force_active = $request->input('force_active');
} }
if($user_source->settings->email_human){ if ($user_source->settings->email_human) {
$user_source->email = $request->postData('eemail'); $user_source->email = $request->postData('eemail');
} }
$user_source->name = User_validate_Nick($request->postData('eNick')); $user_source->name = User_validate_Nick($request->postData('eNick'));

@ -57,7 +57,11 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
if ($request->has('planned_departure_date')) { if ($request->has('planned_departure_date')) {
$tmp = parse_date('Y-m-d H:i', $request->input('planned_departure_date') . ' 00:00'); $tmp = parse_date('Y-m-d H:i', $request->input('planned_departure_date') . ' 00:00');
$result = User_validate_planned_departure_date($user_source->state->arrival_date->getTimestamp(), $tmp); $plannedArrivalDate = $user_source->personalData->planned_arrival_date;
$result = User_validate_planned_departure_date(
$plannedArrivalDate ? $plannedArrivalDate->getTimestamp() : 0,
$tmp
);
$user_source->personalData->planned_departure_date = Carbon::createFromTimestamp($result->getValue()); $user_source->personalData->planned_departure_date = Carbon::createFromTimestamp($result->getValue());
if (!$result->isValid()) { if (!$result->isValid()) {
$valid = false; $valid = false;
@ -66,7 +70,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
} }
// Trivia // Trivia
$user_source->name = strip_request_item('lastname', $user_source['Name']); $user_source->personalData->last_name = strip_request_item('lastname', $user_source['Name']);
$user_source->personalData->first_name = strip_request_item('prename', $user_source['Vorname']); $user_source->personalData->first_name = strip_request_item('prename', $user_source['Vorname']);
if (strlen(strip_request_item('dect')) <= 5) { if (strlen(strip_request_item('dect')) <= 5) {
$user_source->contact->dect = strip_request_item('dect', $user_source['DECT']); $user_source->contact->dect = strip_request_item('dect', $user_source['DECT']);

@ -203,6 +203,7 @@ function AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $a
$members_unconfirmed = []; $members_unconfirmed = [];
foreach ($members as $member) { foreach ($members as $member) {
$member->name = User_Nick_render($member); $member->name = User_Nick_render($member);
$member['dect'] = $member->contact->dect;
if ($angeltype['requires_driver_license']) { if ($angeltype['requires_driver_license']) {
$member['wants_to_drive'] = glyph_bool($member['wants_to_drive']); $member['wants_to_drive'] = glyph_bool($member['wants_to_drive']);
$member['has_car'] = glyph_bool($member['has_car']); $member['has_car'] = glyph_bool($member['has_car']);
@ -294,8 +295,8 @@ function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
{ {
if ($angeltype['requires_driver_license'] && ($supporter || $admin_angeltypes)) { if ($angeltype['requires_driver_license'] && ($supporter || $admin_angeltypes)) {
return [ return [
'Nick' => __('Nick'), 'name' => __('Nick'),
'DECT' => __('DECT'), 'dect' => __('DECT'),
'wants_to_drive' => __('Driver'), 'wants_to_drive' => __('Driver'),
'has_car' => __('Has car'), 'has_car' => __('Has car'),
'has_license_car' => __('Car'), 'has_license_car' => __('Car'),
@ -307,8 +308,8 @@ function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
]; ];
} }
return [ return [
'Nick' => __('Nick'), 'name' => __('Nick'),
'DECT' => __('DECT'), 'dect' => __('DECT'),
'actions' => '' 'actions' => ''
]; ];
} }
@ -420,16 +421,16 @@ function AngelType_view_info(
if (count($members_confirmed) > 0) { if (count($members_confirmed) > 0) {
$members_confirmed[] = [ $members_confirmed[] = [
'Nick' => __('Sum'), 'name' => __('Sum'),
'DECT' => count($members_confirmed), 'dect' => count($members_confirmed),
'actions' => '' 'actions' => ''
]; ];
} }
if (count($members_unconfirmed) > 0) { if (count($members_unconfirmed) > 0) {
$members_unconfirmed[] = [ $members_unconfirmed[] = [
'Nick' => __('Sum'), 'name' => __('Sum'),
'DECT' => count($members_unconfirmed), 'dect' => count($members_unconfirmed),
'actions' => '' 'actions' => ''
]; ];
} }

@ -16,7 +16,7 @@ function public_dashboard_view($stats, $free_shifts)
]; ];
foreach ($free_shifts as $i => $shift) { foreach ($free_shifts as $i => $shift) {
$shift_panels[] = public_dashboard_shift_render($shift); $shift_panels[] = public_dashboard_shift_render($shift);
if($i % 4 == 3) { if ($i % 4 == 3) {
$shift_panels[] = '</div><div class="row">'; $shift_panels[] = '</div><div class="row">';
} }
} }

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

@ -25,7 +25,6 @@ function User_settings_view(
$tshirt_sizes $tshirt_sizes
) { ) {
$personalData = $user_source->personalData; $personalData = $user_source->personalData;
$state = $user_source->state;
return page_with_title(settings_title(), [ return page_with_title(settings_title(), [
msg(), msg(),
div('row', [ div('row', [
@ -34,12 +33,12 @@ function User_settings_view(
form_info('', __('Here you can change your user details.')), form_info('', __('Here you can change your user details.')),
form_info(entry_required() . ' = ' . __('Entry required!')), form_info(entry_required() . ' = ' . __('Entry required!')),
form_text('nick', __('Nick'), $user_source->name, true), form_text('nick', __('Nick'), $user_source->name, true),
form_text('lastname', __('Last name'), $user_source->personalData->last_name), form_text('lastname', __('Last name'), $personalData->last_name),
form_text('prename', __('First name'), $user_source->personalData->first_name), form_text('prename', __('First name'), $personalData->first_name),
form_date( form_date(
'planned_arrival_date', 'planned_arrival_date',
__('Planned date of arrival') . ' ' . entry_required(), __('Planned date of arrival') . ' ' . entry_required(),
$state->arrival_date ? $state->arrival_date->getTimestamp() : '', $personalData->planned_arrival_date ? $personalData->planned_arrival_date->getTimestamp() : '',
$buildup_start_date, $buildup_start_date,
$teardown_end_date $teardown_end_date
), ),
@ -52,7 +51,7 @@ function User_settings_view(
), ),
form_text('dect', __('DECT'), $user_source->contact->dect), form_text('dect', __('DECT'), $user_source->contact->dect),
form_text('mobile', __('Mobile'), $user_source->contact->mobile), form_text('mobile', __('Mobile'), $user_source->contact->mobile),
form_text('mail', __('E-Mail') . ' ' . entry_required(), $user_source->contact->email), form_text('mail', __('E-Mail') . ' ' . entry_required(), $user_source->email),
form_checkbox( form_checkbox(
'email_shiftinfo', 'email_shiftinfo',
__( __(
@ -70,7 +69,7 @@ function User_settings_view(
'tshirt_size', 'tshirt_size',
__('Shirt size'), __('Shirt size'),
$tshirt_sizes, $tshirt_sizes,
$user_source->personalData->shirt_size, $personalData->shirt_size,
__('Please select...') __('Please select...')
) : '', ) : '',
form_info('', __('Please visit the angeltypes page to manage your angeltypes.')), form_info('', __('Please visit the angeltypes page to manage your angeltypes.')),
@ -215,31 +214,31 @@ function Users_view(
$usersList = []; $usersList = [];
foreach ($users as $user) { foreach ($users as $user) {
$u = []; $u = [];
$u['Nick'] = User_Nick_render($user); $u['name'] = User_Nick_render($user);
$u['Vorname'] = $user->personalData->first_name; $u['first_name'] = $user->personalData->first_name;
$u['Name'] = $user->personalData->last_name; $u['last_name'] = $user->personalData->last_name;
$u['DECT'] = $user->contact->dect; $u['dect'] = $user->contact->dect;
$u['Gekommen'] = glyph_bool($user->state->arrived); $u['arrived'] = glyph_bool($user->state->arrived);
$u['got_voucher'] = glyph_bool($user->state->got_voucher); $u['got_voucher'] = $user->state->got_voucher;
$u['freeloads'] = $user->getAttribute('freeloads'); $u['freeloads'] = $user->getAttribute('freeloads');
$u['Aktiv'] = glyph_bool($user->state->active); $u['active'] = glyph_bool($user->state->active);
$u['force_active'] = glyph_bool($user->state->force_active); $u['force_active'] = glyph_bool($user->state->force_active);
$u['Tshirt'] = glyph_bool($user->state->got_shirt); $u['got_shirt'] = glyph_bool($user->state->got_shirt);
$u['Size'] = $user->personalData->shirt_size; $u['shirt_size'] = $user->personalData->shirt_size;
$u['lastLogIn'] = $user->last_login_at ? $user->last_login_at->format(__('m/d/Y h:i a')) : ''; $u['last_login_at'] = $user->last_login_at ? $user->last_login_at->format(__('m/d/Y h:i a')) : '';
$u['actions'] = table_buttons([ $u['actions'] = table_buttons([
button_glyph(page_link_to('admin_user', ['id' => $user->id]), 'edit', 'btn-xs') button_glyph(page_link_to('admin_user', ['id' => $user->id]), 'edit', 'btn-xs')
]); ]);
$usersList[] = $u; $usersList[] = $u;
} }
$usersList[] = [ $usersList[] = [
'Nick' => '<strong>' . __('Sum') . '</strong>', 'name' => '<strong>' . __('Sum') . '</strong>',
'Gekommen' => $arrived_count, 'arrived' => $arrived_count,
'got_voucher' => $voucher_count, 'got_voucher' => $voucher_count,
'Aktiv' => $active_count, 'active' => $active_count,
'force_active' => $force_active_count, 'force_active' => $force_active_count,
'freeloads' => $freeloads_count, 'freeloads' => $freeloads_count,
'Tshirt' => $tshirts_count, 'got_shirt' => $tshirts_count,
'actions' => '<strong>' . count($usersList) . '</strong>' 'actions' => '<strong>' . count($usersList) . '</strong>'
]; ];
@ -249,18 +248,18 @@ function Users_view(
button(page_link_to('register'), glyph('plus') . __('New user')) button(page_link_to('register'), glyph('plus') . __('New user'))
]), ]),
table([ table([
'Nick' => Users_table_header_link('Nick', __('Nick'), $order_by), 'name' => Users_table_header_link('name', __('Nick'), $order_by),
'Vorname' => Users_table_header_link('Vorname', __('Prename'), $order_by), 'first_name' => Users_table_header_link('first_name', __('Prename'), $order_by),
'Name' => Users_table_header_link('Name', __('Name'), $order_by), 'last_name' => Users_table_header_link('last_name', __('Name'), $order_by),
'DECT' => Users_table_header_link('DECT', __('DECT'), $order_by), 'dect' => Users_table_header_link('dect', __('DECT'), $order_by),
'Gekommen' => Users_table_header_link('Gekommen', __('Arrived'), $order_by), 'arrived' => Users_table_header_link('arrived', __('Arrived'), $order_by),
'got_voucher' => Users_table_header_link('got_voucher', __('Voucher'), $order_by), 'got_voucher' => Users_table_header_link('got_voucher', __('Voucher'), $order_by),
'freeloads' => __('Freeloads'), 'freeloads' => __('Freeloads'),
'Aktiv' => Users_table_header_link('Aktiv', __('Active'), $order_by), 'active' => Users_table_header_link('active', __('Active'), $order_by),
'force_active' => Users_table_header_link('force_active', __('Forced'), $order_by), 'force_active' => Users_table_header_link('force_active', __('Forced'), $order_by),
'Tshirt' => Users_table_header_link('Tshirt', __('T-Shirt'), $order_by), 'got_shirt' => Users_table_header_link('got_shirt', __('T-Shirt'), $order_by),
'Size' => Users_table_header_link('Size', __('Size'), $order_by), 'shirt_size' => Users_table_header_link('shirt_size', __('Size'), $order_by),
'lastLogIn' => Users_table_header_link('lastLogIn', __('Last login'), $order_by), 'last_login_at' => Users_table_header_link('last_login_at', __('Last login'), $order_by),
'actions' => '' 'actions' => ''
], $usersList) ], $usersList)
]); ]);
@ -282,24 +281,16 @@ function Users_table_header_link($column, $label, $order_by)
} }
/** /**
* @param User|array $user * @param User $user
* @return string|false * @return string|false
*/ */
function User_shift_state_render($user) function User_shift_state_render($user)
{ {
if ($user instanceof User) { if (!$user->state->arrived) {
$id = $user->id;
$arrived = $user->state->arrived;
} else {
$arrived = $user['Gekommen'];
$id = $user['UID'];
}
if (!$arrived) {
return ''; return '';
} }
$upcoming_shifts = ShiftEntries_upcoming_for_user($id); $upcoming_shifts = ShiftEntries_upcoming_for_user($user->id);
if (empty($upcoming_shifts)) { if (empty($upcoming_shifts)) {
return '<span class="text-success">' . __('Free') . '</span>'; return '<span class="text-success">' . __('Free') . '</span>';
} }
@ -735,7 +726,7 @@ function User_view_state_admin($freeloader, $user_source)
} elseif ($user_source->state->active) { } elseif ($user_source->state->active) {
$state[] = '<span class="text-success">' . __('Active') . '</span>'; $state[] = '<span class="text-success">' . __('Active') . '</span>';
} }
if ($user_source->personalData->shirt_size) { if ($user_source->state->got_shirt) {
$state[] = '<span class="text-success">' . __('T-Shirt') . '</span>'; $state[] = '<span class="text-success">' . __('T-Shirt') . '</span>';
} }
} else { } else {
@ -844,20 +835,14 @@ function User_groups_render($user_groups)
*/ */
function User_Nick_render($user) function User_Nick_render($user)
{ {
if ($user instanceof User) { if (is_array($user)) {
$id = $user->id; $user = (new User())->forceFill($user);
$name = $user->name;
$arrived = $user->state->arrived;
} else {
$id = $user['UID'];
$name = $user['Nick'];
$arrived = $user['Gekommen'];
} }
return render_profile_link( return render_profile_link(
'<span class="icon-icon_angel"></span> ' . htmlspecialchars($name) . '</a>', '<span class="icon-icon_angel"></span> ' . htmlspecialchars($user->name) . '</a>',
$id, $user->id,
($arrived ? '' : 'text-muted') ($user->state->arrived ? '' : 'text-muted')
); );
} }
@ -917,9 +902,7 @@ function render_user_freeloader_hint()
*/ */
function render_user_arrived_hint() function render_user_arrived_hint()
{ {
$user = auth()->user(); if (!auth()->user()->state->arrived) {
if (!$user->state->arrived) {
/** @var Carbon $buildup */ /** @var Carbon $buildup */
$buildup = config('buildup_start'); $buildup = config('buildup_start');
if (!empty($buildup) && $buildup->lessThan(new Carbon())) { if (!empty($buildup) && $buildup->lessThan(new Carbon())) {
@ -935,9 +918,7 @@ function render_user_arrived_hint()
*/ */
function render_user_tshirt_hint() function render_user_tshirt_hint()
{ {
$user = auth()->user(); if (config('enable_tshirt_size') && !auth()->user()->personalData->shirt_size) {
if (config('enable_tshirt_size') && !$user->personalData->shirt_size) {
$text = __('You need to specify a tshirt size in your settings!'); $text = __('You need to specify a tshirt size in your settings!');
return render_profile_link($text, null, 'alert-link'); return render_profile_link($text, null, 'alert-link');
} }
@ -951,7 +932,6 @@ function render_user_tshirt_hint()
function render_user_dect_hint() function render_user_dect_hint()
{ {
$user = auth()->user(); $user = auth()->user();
if ($user->state->arrived && !$user->contact->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 \'-\'.'); $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'); return render_profile_link($text, null, 'alert-link');

@ -22,6 +22,11 @@ class State extends HasUserModel
/** @var string The table associated with the model */ /** @var string The table associated with the model */
protected $table = 'users_state'; protected $table = 'users_state';
/** @var array The attributes that should be mutated to dates */
protected $dates = [
'arrival_date',
];
/** The attributes that are mass assignable */ /** The attributes that are mass assignable */
protected $fillable = [ protected $fillable = [
'user_id', 'user_id',

Loading…
Cancel
Save