2011-07-19 19:31:07 +02:00
|
|
|
<?php
|
2015-07-12 14:45:58 +02:00
|
|
|
|
2022-06-07 22:59:49 +02:00
|
|
|
use Engelsystem\Helpers\BarChart;
|
2018-10-09 21:47:31 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
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_arrive_title()
|
|
|
|
{
|
2020-12-18 17:07:43 +01:00
|
|
|
return __('Arrive 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_arrive()
|
|
|
|
{
|
2017-01-03 14:12:17 +01:00
|
|
|
$msg = '';
|
|
|
|
$search = '';
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
|
|
|
|
|
|
|
if ($request->has('search')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$search = strip_request_item('search');
|
2017-12-28 14:17:42 +01:00
|
|
|
$search = trim($search);
|
2016-09-29 10:53:17 +02:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-11-20 16:02:03 +01:00
|
|
|
$action = $request->get('action');
|
|
|
|
if (
|
|
|
|
$action == 'reset'
|
|
|
|
&& preg_match('/^\d+$/', $request->input('user'))
|
|
|
|
&& $request->hasPostData('submit')
|
|
|
|
) {
|
|
|
|
$user_id = $request->input('user');
|
2018-10-09 21:47:31 +02:00
|
|
|
$user_source = User::find($user_id);
|
|
|
|
if ($user_source) {
|
2018-10-11 01:26:34 +02:00
|
|
|
$user_source->state->arrived = false;
|
2018-10-14 00:26:05 +02:00
|
|
|
$user_source->state->arrival_date = null;
|
2018-10-11 01:26:34 +02:00
|
|
|
$user_source->state->save();
|
|
|
|
|
2019-05-31 04:03:19 +02:00
|
|
|
engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source, true));
|
2018-08-29 21:55:32 +02:00
|
|
|
success(__('Reset done. Angel has not arrived.'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(user_link($user_source->id));
|
2017-01-02 03:57:23 +01:00
|
|
|
} else {
|
2018-08-29 21:55:32 +02:00
|
|
|
$msg = error(__('Angel not found.'), true);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2018-11-20 16:02:03 +01:00
|
|
|
} elseif (
|
|
|
|
$action == 'arrived'
|
|
|
|
&& preg_match('/^\d+$/', $request->input('user'))
|
|
|
|
&& $request->hasPostData('submit')
|
|
|
|
) {
|
|
|
|
$user_id = $request->input('user');
|
2018-10-09 21:47:31 +02:00
|
|
|
$user_source = User::find($user_id);
|
|
|
|
if ($user_source) {
|
2018-10-11 01:26:34 +02:00
|
|
|
$user_source->state->arrived = true;
|
2018-10-14 00:26:05 +02:00
|
|
|
$user_source->state->arrival_date = new Carbon\Carbon();
|
2018-10-17 01:30:10 +02:00
|
|
|
$user_source->state->save();
|
2018-10-11 01:26:34 +02:00
|
|
|
|
2019-05-31 04:03:19 +02:00
|
|
|
engelsystem_log('User set has arrived: ' . User_Nick_render($user_source, true));
|
2018-08-29 21:55:32 +02:00
|
|
|
success(__('Angel has been marked as arrived.'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(user_link($user_source->id));
|
2017-01-02 03:57:23 +01:00
|
|
|
} else {
|
2018-08-29 21:55:32 +02:00
|
|
|
$msg = error(__('Angel not found.'), true);
|
2013-11-28 22:49:15 +01:00
|
|
|
}
|
2012-12-26 14:02:27 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-10-11 01:26:34 +02:00
|
|
|
/** @var User[] $users */
|
2019-12-26 19:07:51 +01:00
|
|
|
$users = User::with('personalData')->orderBy('name')->get();
|
2017-01-02 03:57:23 +01:00
|
|
|
$arrival_count_at_day = [];
|
|
|
|
$planned_arrival_count_at_day = [];
|
|
|
|
$planned_departure_count_at_day = [];
|
|
|
|
$users_matched = [];
|
2017-01-03 14:12:17 +01:00
|
|
|
if ($search == '') {
|
2017-01-02 03:57:23 +01:00
|
|
|
$tokens = [];
|
2016-09-29 10:53:17 +02:00
|
|
|
} else {
|
2017-01-03 14:12:17 +01:00
|
|
|
$tokens = explode(' ', $search);
|
2016-09-29 10:53:17 +02:00
|
|
|
}
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($users as $usr) {
|
|
|
|
if (count($tokens) > 0) {
|
|
|
|
$match = false;
|
2023-08-26 00:40:43 +02:00
|
|
|
$data = collect($usr->toArray())->flatten()->filter(function ($value) {
|
|
|
|
// Remove empty values
|
|
|
|
return !empty($value) &&
|
|
|
|
// Skip datetime
|
|
|
|
!preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}Z$/', (string) $value);
|
|
|
|
});
|
|
|
|
$index = join(' ', $data->toArray());
|
2019-12-28 10:27:21 +01:00
|
|
|
foreach ($tokens as $token) {
|
|
|
|
$token = trim($token);
|
|
|
|
if (!empty($token) && stristr($index, $token)) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-26 19:39:40 +01:00
|
|
|
|
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
|
|
|
|
2019-12-26 19:07:51 +01:00
|
|
|
$usr->name = User_Nick_render($usr) . User_Pronoun_render($usr);
|
2018-11-02 15:36:44 +01:00
|
|
|
$plannedDepartureDate = $usr->personalData->planned_departure_date;
|
|
|
|
$arrivalDate = $usr->state->arrival_date;
|
|
|
|
$plannedArrivalDate = $usr->personalData->planned_arrival_date;
|
2021-07-23 01:52:19 +02:00
|
|
|
$usr['rendered_planned_departure_date'] = $plannedDepartureDate
|
|
|
|
? $plannedDepartureDate->format(__('Y-m-d'))
|
|
|
|
: '-';
|
2019-07-25 19:02:08 +02:00
|
|
|
$usr['rendered_planned_arrival_date'] = $plannedArrivalDate ? $plannedArrivalDate->format(__('Y-m-d')) : '-';
|
|
|
|
$usr['rendered_arrival_date'] = $arrivalDate ? $arrivalDate->format(__('Y-m-d')) : '-';
|
2021-07-22 21:22:21 +02:00
|
|
|
$usr['arrived'] = icon_bool($usr->state->arrived);
|
2018-11-20 16:02:03 +01:00
|
|
|
$usr['actions'] = form([
|
|
|
|
form_hidden('action', $usr->state->arrived ? 'reset' : 'arrived'),
|
|
|
|
form_hidden('user', $usr->id),
|
2018-12-06 23:05:40 +01:00
|
|
|
form_submit(
|
2021-07-23 01:52:19 +02:00
|
|
|
'submit',
|
2023-10-02 16:15:25 +02:00
|
|
|
$usr->state->arrived ? __('reset') : __('user.arrived'),
|
2021-07-23 01:52:19 +02:00
|
|
|
'btn-sm',
|
|
|
|
true,
|
|
|
|
$usr->state->arrived ? 'secondary' : 'primary'
|
2018-12-06 23:05:40 +01:00
|
|
|
),
|
2018-11-20 16:02:03 +01:00
|
|
|
]);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-10-14 00:26:05 +02:00
|
|
|
if ($usr->state->arrival_date) {
|
2023-07-24 18:49:32 +02:00
|
|
|
$day = $usr->state->arrival_date->format('Y-m-d');
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!isset($arrival_count_at_day[$day])) {
|
2023-07-24 18:49:32 +02:00
|
|
|
$arrival_count_at_day[$day] = [
|
|
|
|
'day' => $usr->state->arrival_date,
|
|
|
|
'count' => 0,
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2023-07-24 18:49:32 +02:00
|
|
|
$arrival_count_at_day[$day]['count']++;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-10-11 01:26:34 +02:00
|
|
|
if ($usr->personalData->planned_arrival_date) {
|
2023-07-24 18:49:32 +02:00
|
|
|
$day = $usr->personalData->planned_arrival_date->format('Y-m-d');
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!isset($planned_arrival_count_at_day[$day])) {
|
2023-07-24 18:49:32 +02:00
|
|
|
$planned_arrival_count_at_day[$day] = [
|
|
|
|
'day' => $usr->personalData->planned_arrival_date,
|
|
|
|
'count' => 0,
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2023-07-24 18:49:32 +02:00
|
|
|
$planned_arrival_count_at_day[$day]['count']++;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-10-11 01:26:34 +02:00
|
|
|
if ($usr->personalData->planned_departure_date && $usr->state->arrived) {
|
2023-07-24 18:49:32 +02:00
|
|
|
$day = $usr->personalData->planned_departure_date->format('Y-m-d');
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!isset($planned_departure_count_at_day[$day])) {
|
2023-07-24 18:49:32 +02:00
|
|
|
$planned_departure_count_at_day[$day] = [
|
|
|
|
'day' => $usr->personalData->planned_departure_date,
|
|
|
|
'count' => 0,
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2023-07-24 18:49:32 +02:00
|
|
|
$planned_departure_count_at_day[$day]['count']++;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$users_matched[] = $usr;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
ksort($arrival_count_at_day);
|
|
|
|
ksort($planned_arrival_count_at_day);
|
|
|
|
ksort($planned_departure_count_at_day);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$arrival_at_day = [];
|
|
|
|
$arrival_sum = 0;
|
2023-07-24 18:49:32 +02:00
|
|
|
foreach ($arrival_count_at_day as $day => $entry) {
|
|
|
|
$arrival_sum += $entry['count'];
|
2017-01-02 03:57:23 +01:00
|
|
|
$arrival_at_day[$day] = [
|
2023-07-24 18:49:32 +02:00
|
|
|
'day' => $entry['day']->format(__('Y-m-d')),
|
|
|
|
'count' => $entry['count'],
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => $arrival_sum,
|
2017-01-02 15:43:36 +01:00
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_arrival_at_day = [];
|
|
|
|
$planned_arrival_sum = 0;
|
2023-07-24 18:49:32 +02:00
|
|
|
foreach ($planned_arrival_count_at_day as $day => $entry) {
|
|
|
|
$planned_arrival_sum += $entry['count'];
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_arrival_at_day[$day] = [
|
2023-07-24 18:49:32 +02:00
|
|
|
'day' => $entry['day']->format(__('Y-m-d')),
|
|
|
|
'count' => $entry['count'],
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => $planned_arrival_sum,
|
2017-01-02 15:43:36 +01:00
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_departure_at_day = [];
|
|
|
|
$planned_departure_sum = 0;
|
2023-07-24 18:49:32 +02:00
|
|
|
foreach ($planned_departure_count_at_day as $day => $entry) {
|
|
|
|
$planned_departure_sum += $entry['count'];
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_departure_at_day[$day] = [
|
2023-07-24 18:49:32 +02:00
|
|
|
'day' => $entry['day']->format(__('Y-m-d')),
|
|
|
|
'count' => $entry['count'],
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => $planned_departure_sum,
|
2017-01-02 15:43:36 +01:00
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return page_with_title(admin_arrive_title(), [
|
2017-01-03 03:22:48 +01:00
|
|
|
$msg . msg(),
|
2017-01-02 15:43:36 +01:00
|
|
|
form([
|
2023-10-02 16:15:25 +02:00
|
|
|
form_text('search', __('form.search'), $search),
|
|
|
|
form_submit('submit', __('form.search')),
|
2023-11-13 16:56:52 +01:00
|
|
|
], url('/admin-arrive')),
|
2017-01-02 15:43:36 +01:00
|
|
|
table([
|
2023-10-02 16:15:25 +02:00
|
|
|
'name' => __('general.name'),
|
2018-08-29 21:55:32 +02:00
|
|
|
'rendered_planned_arrival_date' => __('Planned arrival'),
|
|
|
|
'arrived' => __('Arrived?'),
|
|
|
|
'rendered_arrival_date' => __('Arrival date'),
|
|
|
|
'rendered_planned_departure_date' => __('Planned departure'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'actions' => '',
|
2017-01-02 15:43:36 +01:00
|
|
|
], $users_matched),
|
|
|
|
div('row', [
|
|
|
|
div('col-md-4', [
|
2022-06-07 22:59:49 +02:00
|
|
|
heading(__('Planned arrival statistics'), 3),
|
|
|
|
BarChart::render([
|
2023-10-02 16:15:25 +02:00
|
|
|
'count' => __('user.arrived'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => __('arrived sum'),
|
2017-01-02 15:43:36 +01:00
|
|
|
], [
|
|
|
|
'count' => '#090',
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => '#888',
|
2017-01-02 15:43:36 +01:00
|
|
|
], $planned_arrival_at_day),
|
|
|
|
table([
|
2018-08-29 21:55:32 +02:00
|
|
|
'day' => __('Date'),
|
2023-10-22 18:37:29 +02:00
|
|
|
'count' => __('general.count'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => __('Sum'),
|
|
|
|
], $planned_arrival_at_day),
|
2017-01-02 15:43:36 +01:00
|
|
|
]),
|
|
|
|
div('col-md-4', [
|
2022-06-07 22:59:49 +02:00
|
|
|
heading(__('Arrival statistics'), 3),
|
|
|
|
BarChart::render([
|
2023-10-02 16:15:25 +02:00
|
|
|
'count' => __('user.arrived'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => __('arrived sum'),
|
2017-01-02 15:43:36 +01:00
|
|
|
], [
|
|
|
|
'count' => '#090',
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => '#888',
|
2017-01-02 15:43:36 +01:00
|
|
|
], $arrival_at_day),
|
|
|
|
table([
|
2018-08-29 21:55:32 +02:00
|
|
|
'day' => __('Date'),
|
2023-10-22 18:37:29 +02:00
|
|
|
'count' => __('general.count'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => __('Sum'),
|
|
|
|
], $arrival_at_day),
|
2017-01-02 15:43:36 +01:00
|
|
|
]),
|
|
|
|
div('col-md-4', [
|
2022-06-07 22:59:49 +02:00
|
|
|
heading(__('Planned departure statistics'), 3),
|
|
|
|
BarChart::render([
|
2023-10-02 16:15:25 +02:00
|
|
|
'count' => __('user.arrived'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => __('arrived sum'),
|
2017-01-02 15:43:36 +01:00
|
|
|
], [
|
|
|
|
'count' => '#090',
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => '#888',
|
2017-01-02 15:43:36 +01:00
|
|
|
], $planned_departure_at_day),
|
|
|
|
table([
|
2018-08-29 21:55:32 +02:00
|
|
|
'day' => __('Date'),
|
2023-10-22 18:37:29 +02:00
|
|
|
'count' => __('general.count'),
|
2023-02-05 18:03:00 +01:00
|
|
|
'sum' => __('Sum'),
|
|
|
|
], $planned_departure_at_day),
|
|
|
|
]),
|
|
|
|
]),
|
2017-01-02 15:43:36 +01:00
|
|
|
]);
|
2011-07-19 19:31:07 +02:00
|
|
|
}
|