diff --git a/db/migrations/2018_10_01_000000_create_users_tables.php b/db/migrations/2018_10_01_000000_create_users_tables.php
index b9429a2d..55ee382e 100644
--- a/db/migrations/2018_10_01_000000_create_users_tables.php
+++ b/db/migrations/2018_10_01_000000_create_users_tables.php
@@ -102,7 +102,7 @@ class CreateUsersTables extends Migration
$user->save();
$contact = new Contact([
- 'dect' => ($data->DECT && $data->DECT != '-') ? $data->DECT : null,
+ 'dect' => $data->DECT ? $data->DECT : null,
'mobile' => $data->Handy ?: ($data->Telefon ?: null),
]);
$contact->user()
@@ -170,7 +170,7 @@ class CreateUsersTables extends Migration
public function down()
{
$this->schema->create('User', function (Blueprint $table) {
- $table->increments('UID');
+ $table->integer('UID', true, false);
$table->string('Nick', 23)->unique()->default('');
$table->string('Name', 23)->nullable();
diff --git a/db/migrations/ChangesReferences.php b/db/migrations/ChangesReferences.php
index d50f552e..6bdd187d 100644
--- a/db/migrations/ChangesReferences.php
+++ b/db/migrations/ChangesReferences.php
@@ -3,6 +3,7 @@
namespace Engelsystem\Migrations;
use Illuminate\Database\Schema\Blueprint;
+use stdClass;
trait ChangesReferences
{
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
index bbf2e5b0..c5c1e181 100644
--- a/includes/controller/shift_entries_controller.php
+++ b/includes/controller/shift_entries_controller.php
@@ -11,7 +11,7 @@ use Engelsystem\ShiftSignupState;
function shift_entries_controller()
{
$user = auth()->user();
- if ($user) {
+ if (!$user) {
redirect(page_link_to('login'));
}
@@ -75,10 +75,9 @@ function shift_entry_create_controller()
*/
function shift_entry_create_controller_admin($shift, $angeltype)
{
- $user = auth()->user();
+ $signup_user = auth()->user();
$request = request();
- $signup_user = $user;
if ($request->has('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_select = [];
- foreach ($users as $u) {
- $users_select[$u->id] = $u->name;
+ foreach ($users as $user) {
+ $users_select[$user->id] = $user->name;
}
$angeltypes_select = [];
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index 07e81957..ee6714d4 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -332,13 +332,12 @@ function shifts_controller()
function shift_next_controller()
{
global $privileges;
- $user = auth()->user();
if (!in_array('user_shifts', $privileges)) {
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)) {
redirect(shift_link($upcoming_shifts[0]));
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
index 6080d08b..4269313d 100644
--- a/includes/controller/user_angeltypes_controller.php
+++ b/includes/controller/user_angeltypes_controller.php
@@ -9,9 +9,7 @@ use Engelsystem\Models\User\User;
*/
function user_angeltypes_unconfirmed_hint()
{
- $user = auth()->user();
-
- $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user->id);
+ $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes(auth()->user()->id);
if (count($unconfirmed_user_angeltypes) == 0) {
return null;
}
diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php
index f836c74d..9c44adb5 100644
--- a/includes/controller/user_driver_licenses_controller.php
+++ b/includes/controller/user_driver_licenses_controller.php
@@ -76,9 +76,8 @@ function user_driver_license_edit_link($user = null)
*/
function user_driver_license_load_user()
{
- $user = auth()->user();
$request = request();
- $user_source = $user;
+ $user_source = auth()->user();
if ($request->has('user_id')) {
$user_source = User::find($request->input('user_id'));
diff --git a/includes/controller/user_worklog_controller.php b/includes/controller/user_worklog_controller.php
index 51b70ba2..333fd76e 100644
--- a/includes/controller/user_worklog_controller.php
+++ b/includes/controller/user_worklog_controller.php
@@ -9,12 +9,10 @@ use Engelsystem\Models\User\User;
*/
function user_worklog_delete_controller()
{
- $user = auth()->user();
-
$request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) {
- redirect(user_link($user->id));
+ redirect(user_link(auth()->user()->id));
}
$user_source = User::find($userWorkLog['user_id']);
@@ -38,12 +36,10 @@ function user_worklog_delete_controller()
*/
function user_worklog_edit_controller()
{
- $user = auth()->user();
-
$request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) {
- redirect(user_link($user->id));
+ redirect(user_link(auth()->user()->id));
}
$user_source = User::find($userWorkLog['user_id']);
@@ -110,12 +106,10 @@ function user_worklog_from_request($userWorkLog)
*/
function user_worklog_add_controller()
{
- $user = auth()->user();
-
$request = request();
$user_source = User::find($request->input('user_id'));
if (!$user_source) {
- redirect(user_link($user->id));
+ redirect(user_link(auth()->user()->id));
}
$userWorkLog = UserWorkLog_new($user_source->id);
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index c8d8a4a9..b54bc967 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -167,7 +167,7 @@ function user_edit_vouchers_controller()
if ($valid) {
$user_source->state->got_voucher = $vouchers;
- $user->state->save();
+ $user_source->state->save();
success(__('Saved the number of vouchers.'));
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers',
@@ -268,26 +268,30 @@ function users_list_controller()
redirect(page_link_to(''));
}
- $order_by = 'Nick';
+ $order_by = 'name';
if ($request->has('OrderBy') && in_array($request->input('OrderBy'), [
- 'Nick',
- 'Name',
- 'Vorname',
- 'DECT',
+ 'name',
+ 'last_name',
+ 'first_name',
+ 'dect',
'email',
- 'Size',
- 'Gekommen',
- 'Aktiv',
+ 'shirt_size',
+ 'arrived',
+ 'active',
'force_active',
- 'Tshirt',
- 'lastLogIn'
+ 'got_shirt',
+ 'last_login_at',
])) {
$order_by = $request->input('OrderBy');
}
/** @var User[] $users */
$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('name')
->get();
foreach ($users as $user) {
$user->setAttribute('freeloads', count(ShiftEntries_freeloaded_by_user($user->id)));
diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php
index 4fc10226..566217ef 100644
--- a/includes/helper/email_helper.php
+++ b/includes/helper/email_helper.php
@@ -4,29 +4,15 @@ use Engelsystem\Mail\EngelsystemMailer;
use Engelsystem\Models\User\User;
/**
- * @param array|User $recipientUser
- * @param string $title
- * @param string $message
- * @param bool $notIfItsMe
+ * @param User $recipientUser
+ * @param string $title
+ * @param string $message
+ * @param bool $notIfItsMe
* @return bool
*/
function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false)
{
- $user = Auth()->user();
-
- 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) {
+ if ($notIfItsMe && Auth()->user()->id == $recipientUser->id) {
return true;
}
@@ -36,12 +22,12 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe
/** @var EngelsystemMailer $mailer */
$mailer = app('mailer');
- $translator->setLocale($lang);
+ $translator->setLocale($recipientUser->settings->language);
$status = $mailer->sendView(
- $email,
+ $recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email,
$title,
'emails/mail',
- ['username' => $username, 'message' => $message]
+ ['username' => $recipientUser->name, 'message' => $message]
);
$translator->setLocale($locale);
diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php
index 5304a897..37b26838 100644
--- a/includes/mailer/shifts_mailer.php
+++ b/includes/mailer/shifts_mailer.php
@@ -64,7 +64,7 @@ function mail_shift_change($old_shift, $new_shift)
$message .= $new_room['Name'] . "\n";
foreach ($users as $user) {
- $user = User::find($user->id);
+ $user = (new User())->forceFill($user);
if ($user->settings->email_shiftinfo) {
engelsystem_email_to_user(
$user,
@@ -92,7 +92,7 @@ function mail_shift_delete($shift)
$message .= $room['Name'] . "\n";
foreach ($users as $user) {
- $user = User::find($user->id);
+ $user = (new User())->forceFill($user);
if ($user->settings->email_shiftinfo) {
engelsystem_email_to_user($user, __('Your Shift was deleted'), $message, true);
}
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index d7799a1e..cc909954 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -233,20 +233,23 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
*/
function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
{
- $sql = '
- SELECT
- users.*
- `ShiftEntry`.`UID`,
- `ShiftEntry`.`TID`,
- `ShiftEntry`.`SID`,
- `ShiftEntry`.`Comment`,
- `ShiftEntry`.`freeloaded`
- FROM `Shifts`
- JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID`
- JOIN `users` ON `ShiftEntry`.`UID`=`users`.`id`
- WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
- AND `start` BETWEEN ? AND ?
- ORDER BY `Shifts`.`start`';
+ $sql = sprintf('
+ SELECT
+ users.*,
+ `ShiftEntry`.`UID`,
+ `ShiftEntry`.`TID`,
+ `ShiftEntry`.`SID`,
+ `ShiftEntry`.`Comment`,
+ `ShiftEntry`.`freeloaded`
+ FROM `Shifts`
+ JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID`
+ JOIN `users` ON `ShiftEntry`.`UID`=`users`.`id`
+ WHERE `Shifts`.`RID` IN (%s)
+ AND `start` BETWEEN ? AND ?
+ ORDER BY `Shifts`.`start`
+ ',
+ implode(',', $shiftsFilter->getRooms())
+ );
return DB::select(
$sql,
[
@@ -298,7 +301,7 @@ function Shift_free_entries($needed_angeltype, $shift_entries)
/**
* Check if shift signup is allowed from the end users point of view (no admin like privileges)
*
- * @param User $user
+ * @param User $user
* @param array $shift The shift
* @param array $angeltype The angeltype to which the user wants to sign up
* @param array|null $user_angeltype
@@ -575,7 +578,6 @@ function Shift_update_by_psid($shift)
*/
function Shift_create($shift)
{
- $user = auth()->user();
DB::insert('
INSERT INTO `Shifts` (
`shifttype_id`,
@@ -599,7 +601,7 @@ function Shift_create($shift)
$shift['title'],
$shift['URL'],
$shift['PSID'],
- $user->id,
+ auth()->user()->id,
time(),
time(),
]
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 6192fa20..da25a9a2 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -73,16 +73,16 @@ function User_is_freeloader($user)
function Users_by_angeltype_inverted($angeltype)
{
return User::query()
- ->leftJoin('UserAngelTypes', 'users.id', '=', 'UserAngelTypes.user_id')
+ ->select('users.*')
->leftJoin('UserAngelTypes', function ($query) use ($angeltype) {
/** @var JoinClause $query */
$query
->on('users.id', '=', 'UserAngelTypes.user_id')
- ->on('UserAngelTypes.angeltype_id', '=', $angeltype['id']);
+ ->where('UserAngelTypes.angeltype_id', '=', $angeltype['id']);
})
->whereNull('UserAngelTypes.id')
->orderBy('users.name')
- ->get('users.*');
+ ->get();
}
/**
@@ -94,17 +94,17 @@ function Users_by_angeltype_inverted($angeltype)
function Users_by_angeltype($angeltype)
{
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')
->leftJoin('UserDriverLicenses', 'users.id', '=', 'UserDriverLicenses.user_id')
->where('UserAngelTypes.angeltype_id', '=', $angeltype['id'])
- ->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`.*',
- ]);
+ ->get();
}
/**
@@ -226,6 +226,7 @@ function User_reset_api_key($user, $log = true)
function User_generate_password_recovery_token($user)
{
$reset = PasswordReset::findOrNew($user->id);
+ $reset->user_id = $user->id;
$reset->token = md5($user->name . time() . rand());
$reset->save();
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php
index 8d9f35bd..5b0beae9 100644
--- a/includes/pages/admin_active.php
+++ b/includes/pages/admin_active.php
@@ -2,6 +2,8 @@
use Engelsystem\Models\User\State;
use Engelsystem\Models\User\User;
+use Illuminate\Database\Query\Builder;
+use Illuminate\Database\Query\JoinClause;
/**
* @return string
@@ -23,8 +25,7 @@ function admin_active()
$msg = '';
$search = '';
$forced_count = State::whereForceActive(true)->count();
- $count = $forced_count;
- $limit = '';
+ $count = null;
$set_active = '';
if ($request->has('search')) {
@@ -34,8 +35,6 @@ function admin_active()
$show_all_shifts = $request->has('show_all_shifts');
if ($request->has('set_active')) {
- $valid = true;
-
if ($request->has('count') && preg_match('/^\d+$/', $request->input('count'))) {
$count = strip_request_item('count');
if ($count < $forced_count) {
@@ -46,41 +45,43 @@ function admin_active()
redirect(page_link_to('admin_active'));
}
} else {
- $valid = false;
- $msg .= error(__('Please enter a number of angels to be marked as active.'), true);
+ $msg .= error(__('Please enter a number of angels to be marked as active.'));
+ redirect(page_link_to('admin_active'));
}
- if ($valid) {
- $limit = ' LIMIT ' . $count;
- }
if ($request->has('ack')) {
State::query()
+ ->where('got_shirt', '=', false)
->where('got_shirt', '=', false)
->update(['active' => false]);
- /** @var User[] $users */
- $users = User::query()->raw(sprintf('
- SELECT
- `users`.*,
- COUNT(`ShiftEntry`.`id`) AS `shift_count`,
- (%s + (
- SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
- AND `work_timestamp` < %s
- )) 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,
- time(),
- $limit
- ));
+ $query = User::query()
+ ->selectRaw(
+ sprintf(
+ '
+ users.*,
+ COUNT(ShiftEntry.id) AS shift_count,
+ (%s + (
+ SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
+ AND `work_timestamp` < ?
+ )) AS `shift_length`
+ ',
+ $shift_sum_formula
+ ),
+ [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 = [];
foreach ($users as $usr) {
$usr->state->active = true;
@@ -88,10 +89,9 @@ function admin_active()
$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));
- $limit = '';
$msg = success(__('Marked angels.'), true);
} else {
$set_active = '« '
@@ -120,7 +120,7 @@ function admin_active()
} elseif ($request->has('not_active') && preg_match('/^\d+$/', $request->input('not_active'))) {
$user_id = $request->input('not_active');
$user_source = User::find($user_id);
- if (!$user_source) {
+ if ($user_source) {
$user_source->state->active = false;
$user_source->state->save();
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'))) {
$user_id = $request->input('tshirt');
$user_source = User::find($user_id);
- if (!$user_source) {
+ if ($user_source) {
$user_source->state->got_shirt = true;
$user_source->state->save();
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'))) {
$user_id = $request->input('not_tshirt');
$user_source = User::find($user_id);
- if (!$user_source) {
+ if ($user_source) {
$user_source->state->got_shirt = false;
$user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.');
@@ -152,28 +152,45 @@ function admin_active()
}
}
- $users = User::query()->raw(sprintf('
- SELECT
- `users`.*,
- COUNT(`ShiftEntry`.`id`) AS `shift_count`,
- (%s + (
- SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
- AND `work_timestamp` < %s
- )) 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,
- time(),
- $limit
- ));
+ $query = User::query()
+ ->selectRaw(
+ sprintf(
+ '
+ users.*,
+ COUNT(ShiftEntry.id) AS shift_count,
+ (%s + (
+ SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
+ AND `work_timestamp` < ?
+ )) AS `shift_length`
+ ',
+ $shift_sum_formula
+ ),
+ [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 = [];
if ($search == '') {
$tokens = [];
@@ -202,6 +219,7 @@ function admin_active()
$userData['active'] = glyph_bool($usr->state->active == 1);
$userData['force_active'] = glyph_bool($usr->state->force_active == 1);
$userData['tshirt'] = glyph_bool($usr->state->got_shirt == 1);
+ $userData['shift_count'] = $usr['shift_count'];
$actions = [];
if (!$usr->state->active) {
@@ -262,6 +280,7 @@ function admin_active()
foreach (array_keys($tshirt_sizes) as $size) {
$gc = State::query()
->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_personal_data.shirt_size', '=', $size)
->count();
@@ -283,7 +302,7 @@ function admin_active()
form_submit('submit', __('Search'))
], page_link_to('admin_active')),
$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'))
]) : $set_active,
$msg . msg(),
diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php
index 40b8bf44..870522e2 100644
--- a/includes/pages/admin_arrive.php
+++ b/includes/pages/admin_arrive.php
@@ -44,7 +44,7 @@ function admin_arrive()
if ($user_source) {
$user_source->state->arrived = true;
$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));
success(__('Angel has been marked as arrived.'));
@@ -170,7 +170,7 @@ function admin_arrive()
form_submit('submit', __('Search'))
]),
table([
- 'nick' => __('Nickname'),
+ 'name' => __('Nickname'),
'rendered_planned_arrival_date' => __('Planned arrival'),
'arrived' => __('Arrived?'),
'rendered_arrival_date' => __('Arrival date'),
diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php
index 9b1f581b..d8787f36 100644
--- a/includes/pages/admin_free.php
+++ b/includes/pages/admin_free.php
@@ -2,6 +2,7 @@
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
+use Illuminate\Database\Query\JoinClause;
/**
* @return string
@@ -24,18 +25,6 @@ function admin_free()
$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 = [
'' => 'alle Typen'
@@ -44,27 +33,34 @@ function admin_free()
$angel_types[$angel_type['id']] = $angel_type['name'];
}
- /** @var User[] $users */
- $users = User::query()->raw(sprintf('
- SELECT `users`.*
- FROM `users`
- %s
- LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID`
- LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id`
- LEFT JOIN `Shifts`
- ON (
- `ShiftEntry`.`SID` = `Shifts`.`SID`
- AND `Shifts`.`start` < %u
- AND `Shifts`.`end` > %u
- )
- WHERE `users_state`.`arrived` = 1
- AND `Shifts`.`SID` IS NULL
- GROUP BY `users`.`id`
- ORDER BY `users`
- ', $angelTypeSearch, time(), time()
- )
- );
+ $angelType = $request->input('angeltype', '');
+ $query = User::query()
+ ->select('users.*')
+ ->leftJoin('ShiftEntry', 'users.id', 'ShiftEntry.UID')
+ ->leftJoin('users_state', 'users.id', 'users_state.user_id')
+ ->leftJoin('Shifts', function ($join) {
+ /** @var JoinClause $join */
+ $join->on('ShiftEntry.SID', '=', 'Shifts.SID')
+ ->where('Shifts.start', '<', time())
+ ->where('Shifts.end', '>', time());
+ })
+ ->where('users_state.arrived', '=', 1)
+ ->whereNull('Shifts.SID')
+ ->groupBy('users.id');
+
+ if (!empty($angelType)) {
+ $query->join('UserAngelTypes', function ($join) use ($angelType, $request, $query) {
+ /** @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 = [];
if ($search == '') {
$tokens = [];
diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php
index 3a9a484c..a87a76cf 100644
--- a/includes/pages/admin_user.php
+++ b/includes/pages/admin_user.php
@@ -60,8 +60,13 @@ function admin_user()
$html .= " ' . "\n";
}
$html .= ' email " . ' ' . "\n";
+ . html_select_key(
+ 'size',
+ 'eSize',
+ $tshirt_sizes, $user_source->personalData->shirt_size,
+ __('Please select...')
+ )
+ . '' . "\n";
$options = [
'1' => __('Yes'),
@@ -84,7 +89,7 @@ function admin_user()
// T-Shirt bekommen?
$html .= ' Size '
- . html_select_key('size', 'eSize', $tshirt_sizes, $user_source->personalData->shirt_size,
- __('Please select...')) . ' ' . "\n";
+ $html .= html_options('eTshirt', $options, $user_source->state->got_shirt) . '' . "\n";
$html .= '' . "\n" . 'T-Shirt ' . "\n";
- $html .= html_options('eTshirt', $options, $user_source->personalData->shirt_size) . '