You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.7 KiB
PHTML

<?php
use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
use Illuminate\Database\Query\JoinClause;
/**
* @return string
*/
8 years ago
function admin_free_title()
{
return __('Free angels');
}
/**
* @return string
*/
8 years ago
function admin_free()
{
$request = request();
8 years ago
$search = '';
if ($request->has('search')) {
8 years ago
$search = strip_request_item('search');
}
8 years ago
$angel_types_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
8 years ago
$angel_types = [
8 years ago
'' => 'alle Typen'
];
8 years ago
foreach ($angel_types_source as $angel_type) {
$angel_types[$angel_type['id']] = $angel_type['name'];
}
8 years ago
$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')
->orderBy('users.name')
->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');
}
});
}
8 years ago
$users = $query->get();
8 years ago
$free_users_table = [];
if ($search == '') {
8 years ago
$tokens = [];
} else {
$tokens = explode(' ', $search);
}
8 years ago
foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
$index = join('', $usr->toArray());
8 years ago
foreach ($tokens as $t) {
if (stristr($index, trim($t))) {
$match = true;
break;
}
}
8 years ago
if (!$match) {
8 years ago
continue;
}
}
8 years ago
8 years ago
$free_users_table[] = [
8 years ago
'name' => User_Nick_render($usr),
'shift_state' => User_shift_state_render($usr),
'dect' => $usr->contact->dect,
'email' => $usr->settings->email_human ? ($usr->contact->email ? $usr->contact->email : $usr->email) : glyph('eye-close'),
8 years ago
'actions' =>
auth()->can('admin_user')
? button(page_link_to('admin_user', ['id' => $usr->id]), __('edit'), 'btn-xs')
8 years ago
: ''
];
8 years ago
}
return page_with_title(admin_free_title(), [
8 years ago
form([
div('row', [
div('col-md-4', [
form_text('search', __('Search'), $search)
8 years ago
]),
div('col-md-4', [
form_select('angeltype', __('Angeltype'), $angel_types, $angelType)
8 years ago
]),
div('col-md-2', [
form_checkbox('confirmed_only', __('Only confirmed'), $request->has('confirmed_only'))
8 years ago
]),
div('col-md-2', [
form_submit('submit', __('Search'))
8 years ago
])
])
]),
table([
'name' => __('Nick'),
8 years ago
'shift_state' => '',
'dect' => __('DECT'),
'email' => __('E-Mail'),
8 years ago
'actions' => ''
], $free_users_table)
]);
}