2011-12-17 16:25:54 +01:00
|
|
|
<?php
|
2016-09-29 10:53:17 +02:00
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
use Engelsystem\Helpers\Carbon;
|
2022-11-09 00:02:30 +01:00
|
|
|
use Engelsystem\Models\AngelType;
|
2018-10-11 01:26:34 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
2022-07-10 21:12:10 +02:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2018-10-17 01:30:10 +02:00
|
|
|
use Illuminate\Database\Query\JoinClause;
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function admin_free_title()
|
|
|
|
{
|
2018-08-29 21:55:32 +02:00
|
|
|
return __('Free angels');
|
2013-11-25 21:04:58 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function admin_free()
|
|
|
|
{
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-03 14:12:17 +01:00
|
|
|
$search = '';
|
2017-07-18 21:38:53 +02:00
|
|
|
if ($request->has('search')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$search = strip_request_item('search');
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2022-07-10 21:12:10 +02:00
|
|
|
/** @var AngelType[]|Collection $angel_types_source */
|
2022-11-09 00:02:30 +01:00
|
|
|
$angel_types_source = AngelType::all(['id', 'name']);
|
2017-01-02 03:57:23 +01:00
|
|
|
$angel_types = [
|
2023-02-05 18:03:00 +01:00
|
|
|
'' => __('All'),
|
2017-01-02 15:43:36 +01:00
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($angel_types_source as $angel_type) {
|
2022-11-09 00:02:30 +01:00
|
|
|
$angel_types[$angel_type->id] = $angel_type->name;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-10-17 01:30:10 +02:00
|
|
|
$angelType = $request->input('angeltype', '');
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2022-12-03 00:57:04 +01:00
|
|
|
/** @var User[] $users */
|
2021-10-04 01:44:02 +02:00
|
|
|
$users = [];
|
2019-04-21 17:52:08 +02:00
|
|
|
if ($request->has('submit')) {
|
2023-12-13 14:42:25 +01:00
|
|
|
$query = User::with(['personalData', 'contact', 'state'])
|
2021-10-04 01:44:02 +02:00
|
|
|
->select('users.*')
|
2023-01-18 13:02:11 +01:00
|
|
|
->leftJoin('shift_entries', 'users.id', 'shift_entries.user_id')
|
2021-10-04 01:44:02 +02:00
|
|
|
->leftJoin('users_state', 'users.id', 'users_state.user_id')
|
2023-01-03 22:19:03 +01:00
|
|
|
->leftJoin('shifts', function ($join) {
|
2021-10-04 01:44:02 +02:00
|
|
|
/** @var JoinClause $join */
|
2023-01-18 13:02:11 +01:00
|
|
|
$join->on('shift_entries.shift_id', '=', 'shifts.id')
|
2023-01-03 22:19:03 +01:00
|
|
|
->where('shifts.start', '<', Carbon::now())
|
|
|
|
->where('shifts.end', '>', Carbon::now());
|
2021-10-04 01:44:02 +02:00
|
|
|
})
|
|
|
|
->where('users_state.arrived', '=', 1)
|
2023-01-03 22:19:03 +01:00
|
|
|
->whereNull('shifts.id')
|
2021-10-04 01:44:02 +02:00
|
|
|
->orderBy('users.name')
|
|
|
|
->groupBy('users.id');
|
|
|
|
|
|
|
|
if (!empty($angelType)) {
|
2022-12-03 00:57:04 +01:00
|
|
|
$query->join('user_angel_type', function ($join) use ($angelType) {
|
2021-10-04 01:44:02 +02:00
|
|
|
/** @var JoinClause $join */
|
2022-12-03 00:57:04 +01:00
|
|
|
$join->on('user_angel_type.user_id', '=', 'users.id')
|
|
|
|
->where('user_angel_type.angel_type_id', '=', $angelType);
|
2021-10-04 01:44:02 +02:00
|
|
|
});
|
2021-10-04 01:57:43 +02:00
|
|
|
|
2022-11-09 00:02:30 +01:00
|
|
|
$query->join('angel_types', function ($join) {
|
2021-10-04 01:57:43 +02:00
|
|
|
/** @var JoinClause $join */
|
2022-12-03 00:57:04 +01:00
|
|
|
$join->on('user_angel_type.angel_type_id', '=', 'angel_types.id')
|
|
|
|
->whereNotNull('user_angel_type.confirm_user_id')
|
2022-11-09 00:02:30 +01:00
|
|
|
->orWhere('angel_types.restricted', '=', '0');
|
2021-10-04 01:57:43 +02:00
|
|
|
});
|
2021-10-04 01:44:02 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 16:04:01 +01:00
|
|
|
$users = $query->get();
|
|
|
|
}
|
2021-10-04 01:44:02 +02:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$free_users_table = [];
|
2017-01-03 14:12:17 +01:00
|
|
|
if ($search == '') {
|
2017-01-02 03:57:23 +01:00
|
|
|
$tokens = [];
|
|
|
|
} else {
|
2017-01-03 14:12:17 +01:00
|
|
|
$tokens = explode(' ', $search);
|
2012-12-30 17:58:23 +01:00
|
|
|
}
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($users as $usr) {
|
|
|
|
if (count($tokens) > 0) {
|
|
|
|
$match = false;
|
2019-12-26 19:07:51 +01:00
|
|
|
$index = join('', $usr->attributesToArray());
|
|
|
|
foreach ($tokens as $token) {
|
|
|
|
$token = trim($token);
|
|
|
|
if (!empty($token) && stristr($index, $token)) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!$match) {
|
2017-01-02 03:57:23 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2022-06-16 23:00:56 +02:00
|
|
|
$email = $usr->contact->email ?: $usr->email;
|
2017-01-02 03:57:23 +01:00
|
|
|
$free_users_table[] = [
|
2023-12-14 22:15:17 +01:00
|
|
|
'name' => User_Nick_render($usr)
|
|
|
|
. User_Pronoun_render($usr)
|
2024-01-02 13:06:07 +01:00
|
|
|
. user_info_icon($usr),
|
2017-01-02 15:43:36 +01:00
|
|
|
'shift_state' => User_shift_state_render($usr),
|
2019-01-13 16:04:01 +01:00
|
|
|
'last_shift' => User_last_shift_render($usr),
|
2023-12-04 23:33:07 +01:00
|
|
|
'dect' => sprintf('<a href="tel:%s">%1$s</a>', htmlspecialchars((string) $usr->contact->dect)),
|
2021-01-12 14:19:24 +01:00
|
|
|
'email' => $usr->settings->email_human
|
2023-12-04 23:33:07 +01:00
|
|
|
? sprintf('<a href="mailto:%s">%1$s</a>', htmlspecialchars((string) $email))
|
2021-07-22 21:22:21 +02:00
|
|
|
: icon('eye-slash'),
|
2017-01-02 15:43:36 +01:00
|
|
|
'actions' =>
|
2018-11-12 14:41:23 +01:00
|
|
|
auth()->can('admin_user')
|
2023-12-21 13:08:29 +01:00
|
|
|
? button(url('/admin-user', ['id' => $usr->id]), icon('pencil'), 'btn-sm', '', __('form.edit'))
|
2023-02-05 18:03:00 +01:00
|
|
|
: '',
|
2017-01-02 15:43:36 +01:00
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return page_with_title(admin_free_title(), [
|
2017-01-02 15:43:36 +01:00
|
|
|
form([
|
2019-04-21 17:52:08 +02:00
|
|
|
div('row', [
|
|
|
|
div('col-md-12 form-inline', [
|
2021-07-25 23:47:16 +02:00
|
|
|
div('row', [
|
2023-10-02 16:15:25 +02:00
|
|
|
form_text('search', __('form.search'), $search, null, null, null, 'col'),
|
2021-07-25 23:47:16 +02:00
|
|
|
form_select('angeltype', __('Angeltype'), $angel_types, $angelType, '', 'col'),
|
2023-12-21 13:08:29 +01:00
|
|
|
form_submit('submit', icon('search') . __('form.search')),
|
2020-05-01 16:29:28 +02:00
|
|
|
]),
|
2019-04-21 17:52:08 +02:00
|
|
|
]),
|
|
|
|
]),
|
2017-01-02 15:43:36 +01:00
|
|
|
]),
|
|
|
|
table([
|
2023-10-02 16:15:25 +02:00
|
|
|
'name' => __('general.name'),
|
2023-11-23 17:37:06 +01:00
|
|
|
'shift_state' => __('shift.next'),
|
2019-01-13 16:04:01 +01:00
|
|
|
'last_shift' => __('Last shift'),
|
2023-10-02 16:15:25 +02:00
|
|
|
'dect' => __('general.dect'),
|
2023-10-03 21:34:03 +02:00
|
|
|
'email' => __('general.email'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'actions' => '',
|
2019-04-21 17:52:08 +02:00
|
|
|
], $free_users_table),
|
2017-01-02 15:43:36 +01:00
|
|
|
]);
|
2011-12-17 16:25:54 +01:00
|
|
|
}
|