clear up mvc for user list
This commit is contained in:
parent
1d9e1c467c
commit
bd2a8b441f
|
@ -54,6 +54,9 @@ function user_controller() {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all users.
|
||||
*/
|
||||
function users_list_controller() {
|
||||
global $privileges;
|
||||
|
||||
|
@ -61,39 +64,19 @@ function users_list_controller() {
|
|||
redirect(page_link_to(''));
|
||||
|
||||
$order_by = 'Nick';
|
||||
if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], array(
|
||||
'Nick',
|
||||
'Name',
|
||||
'Vorname',
|
||||
'Alter',
|
||||
'DECT',
|
||||
'email',
|
||||
'Size',
|
||||
'Gekommen',
|
||||
'Aktiv',
|
||||
'force_active',
|
||||
'Tshirt',
|
||||
'lastLogIn'
|
||||
)))
|
||||
if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns()))
|
||||
$order_by = $_REQUEST['OrderBy'];
|
||||
|
||||
$users = Users($order_by);
|
||||
if ($users === false)
|
||||
engelsystem_error('Unable to load users.');
|
||||
|
||||
foreach ($users as &$user) {
|
||||
$user['freeloads'] = sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1 AND `UID` = " . sql_escape($user['UID']));
|
||||
}
|
||||
|
||||
$arrived_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1");
|
||||
$active_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1");
|
||||
$force_active_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1");
|
||||
$freeloads_count = sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
|
||||
$tshirts_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1");
|
||||
foreach ($users as &$user)
|
||||
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
|
||||
|
||||
return array(
|
||||
_('All users'),
|
||||
Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count)
|
||||
Users_view($users, $order_by, User_arrived_count(), User_active_count(), User_force_active_count(), ShiftEntries_freeleaded_count(), User_tshirts_count())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Counts all freeloaded shifts.
|
||||
*/
|
||||
function ShiftEntries_freeleaded_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns next (or current) shifts of given user.
|
||||
* @param User $user
|
||||
|
|
|
@ -4,6 +4,45 @@
|
|||
* User model
|
||||
*/
|
||||
|
||||
/**
|
||||
* Counts all forced active users.
|
||||
*/
|
||||
function User_force_active_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1");
|
||||
}
|
||||
|
||||
function User_active_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1");
|
||||
}
|
||||
|
||||
function User_arrived_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1");
|
||||
}
|
||||
|
||||
function User_tshirts_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all column names for sorting in an array.
|
||||
*/
|
||||
function User_sortable_columns() {
|
||||
return array(
|
||||
'Nick',
|
||||
'Name',
|
||||
'Vorname',
|
||||
'Alter',
|
||||
'DECT',
|
||||
'email',
|
||||
'Size',
|
||||
'Gekommen',
|
||||
'Aktiv',
|
||||
'force_active',
|
||||
'Tshirt',
|
||||
'lastLogIn'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users, ordered by Nick by default or by given param.
|
||||
*
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
function myshifts_title() {
|
||||
return _("My shifts");
|
||||
}
|
||||
|
@ -64,7 +65,7 @@ function user_myshifts() {
|
|||
LIMIT 1");
|
||||
engelsystem_log("Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] . " from " . date("y-m-d H:i", $shift['start']) . " to " . date("y-m-d H:i", $shift['end']) . " with comment " . $comment);
|
||||
success(_("Shift saved."));
|
||||
redirect(page_link_to('user_myshifts'));
|
||||
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
|
||||
}
|
||||
|
||||
return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment'], $shift['freeloaded'], $shift['freeload_comment'], in_array("user_shifts_admin", $privileges));
|
||||
|
|
|
@ -21,6 +21,7 @@ $tshirt_sizes = array(
|
|||
|
||||
function Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count) {
|
||||
foreach ($users as &$user) {
|
||||
$user['Nick'] = User_Nick_render($user);
|
||||
$user['Gekommen'] = glyph_bool($user['Gekommen']);
|
||||
$user['Aktiv'] = glyph_bool($user['Aktiv']);
|
||||
$user['force_active'] = glyph_bool($user['force_active']);
|
||||
|
|
Loading…
Reference in New Issue