summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2019-01-13 16:04:01 +0100
committermsquare <msquare@notrademark.de>2019-01-13 16:04:44 +0100
commit60ad343b22ab3cff886e8a8c0f57d40bbff8dcfc (patch)
treef2929345e47b421267c1653a7bff76449556eefd /includes
parent3a01c838af10c20c906d733d7915e3fc523a6d87 (diff)
fixes #178: Show not only next but also last shift in free angels view
Diffstat (limited to 'includes')
-rw-r--r--includes/model/ShiftEntry_model.php2
-rw-r--r--includes/pages/admin_free.php36
-rw-r--r--includes/view/User_view.php17
3 files changed, 34 insertions, 21 deletions
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index 248e7d1e..54837bac 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -206,7 +206,7 @@ function ShiftEntries_finished_by_user($userId)
WHERE `ShiftEntry`.`UID` = ?
AND `Shifts`.`end` < ?
AND `ShiftEntry`.`freeloaded` = 0
- ORDER BY `Shifts`.`end`
+ ORDER BY `Shifts`.`end` desc
',
[
$userId,
diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php
index d2facbc8..1b116805 100644
--- a/includes/pages/admin_free.php
+++ b/includes/pages/admin_free.php
@@ -26,7 +26,7 @@ function admin_free()
$angel_types_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
$angel_types = [
- '' => 'alle Typen'
+ '' => __('Alle')
];
foreach ($angel_types_source as $angel_type) {
$angel_types[$angel_type['id']] = $angel_type['name'];
@@ -49,18 +49,21 @@ function admin_free()
->groupBy('users.id');
if (!empty($angelType)) {
- $query->join('UserAngelTypes', function ($join) use ($angelType, $request, $query) {
+ $query->join('UserAngelTypes', function ($join) use ($angelType) {
/** @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');
- }
});
+ $query->join('AngelTypes', 'UserAngelTypes.angeltype_id', 'AngelTypes.id')
+ ->whereNotNull('UserAngelTypes.confirm_user_id')
+ ->orWhere('AngelTypes.restricted', '=', '0');
}
- $users = $query->get();
+ if($request->has('submit')) {
+ $users = $query->get();
+ } else {
+ $users = [];
+ }
$free_users_table = [];
if ($search == '') {
$tokens = [];
@@ -86,6 +89,7 @@ function admin_free()
$free_users_table[] = [
'name' => User_Nick_render($usr),
'shift_state' => User_shift_state_render($usr),
+ 'last_shift' => User_last_shift_render($usr),
'dect' => $usr->contact->dect,
'email' => $usr->settings->email_human ? ($usr->contact->email ? $usr->contact->email : $usr->email) : glyph('eye-close'),
'actions' =>
@@ -96,24 +100,16 @@ function admin_free()
}
return page_with_title(admin_free_title(), [
form([
- div('row', [
- div('col-md-4', [
- form_text('search', __('Search'), $search)
- ]),
- div('col-md-4', [
- form_select('angeltype', __('Angeltype'), $angel_types, $angelType)
- ]),
- div('col-md-2', [
- form_checkbox('confirmed_only', __('Only confirmed'), $request->has('confirmed_only'))
- ]),
- div('col-md-2', [
+ div('col-md12 form-inline', [
+ form_text('search', __('Search'), $search),
+ form_select('angeltype', __('Angeltype'), $angel_types, $angelType),
form_submit('submit', __('Search'))
- ])
])
]),
table([
'name' => __('Nick'),
- 'shift_state' => '',
+ 'shift_state' => __('Next shift'),
+ 'last_shift' => __('Last shift'),
'dect' => __('DECT'),
'email' => __('E-Mail'),
'actions' => ''
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index c2bf4a06..4768f4ac 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -320,6 +320,23 @@ function User_shift_state_render($user)
. '</span>';
}
+function User_last_shift_render($user)
+{
+ if (!$user->state->arrived) {
+ return '';
+ }
+
+ $last_shifts = ShiftEntries_finished_by_user($user->id);
+ if (empty($last_shifts)) {
+ return '';
+ }
+
+ $lastShift = array_shift($last_shifts);
+ return '<span class="moment-countdown" data-timestamp="' . $lastShift['end'] . '">'
+ . __('Shift ended %c')
+ . '</span>';
+}
+
/**
* @param array $needed_angel_type
* @return string