Skip to content

Commit

Permalink
Add conf variable 'session_list_show_count_users' see BT#12471
Browse files Browse the repository at this point in the history
Shows the number of users in session.
  • Loading branch information
jmontoyaa committed May 4, 2017
1 parent 9207a76 commit 9757d82
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 12 deletions.
5 changes: 2 additions & 3 deletions main/inc/ajax/model.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ function getWhereClause($col, $oper, $val)

$searchByGroups = true;
} elseif (api_is_platform_admin()) {


//get students with course or session
$userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
'admin',
Expand Down Expand Up @@ -1170,7 +1168,8 @@ function getWhereClause($col, $oper, $val)
'extra' => $extra_fields,
'limit' => "$start , $limit",
),
false
false,
$session_columns
);
} else {
$result = SessionManager::get_sessions_admin_complete(
Expand Down
94 changes: 85 additions & 9 deletions main/inc/lib/sessionmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,11 @@ public static function get_count_admin($where_condition = '')
* Gets the admin session list callback of the session/session_list.php page
* @param array $options order and limit keys
* @param boolean $get_count Whether to get all the results or only the count
* @param array $columns
* @return mixed Integer for number of rows, or array of results
* @assert (array(),true) !== false
*/
public static function get_sessions_admin($options = array(), $get_count = false)
public static function get_sessions_admin($options = array(), $get_count = false, $columns = [])
{
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$sessionCategoryTable = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
Expand Down Expand Up @@ -461,10 +462,19 @@ public static function get_sessions_admin($options = array(), $get_count = false
$limit = $conditions['limit'];

$isMakingOrder = false;
$showCountUsers = false;

if ($get_count == true) {
$select = " SELECT count(DISTINCT s.id) as total_rows";
} else {
if (!empty($columns['column_model'])) {
foreach ($columns['column_model'] as $column) {
if ($column['name'] == 'users') {
$showCountUsers = true;
}
}
}

$select =
"SELECT DISTINCT
s.name,
Expand All @@ -478,6 +488,10 @@ public static function get_sessions_admin($options = array(), $get_count = false
s.id
";

if ($showCountUsers) {
$select .= ', count(su.user_id) users';
}

$isMakingOrder = strpos($options['order'], 'category_name') === 0;
}

Expand All @@ -496,10 +510,16 @@ public static function get_sessions_admin($options = array(), $get_count = false
}
}

if ($showCountUsers) {
$table = Database::get_main_table(TABLE_MAIN_SESSION_USER);
//$tableUserUrl = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$inject_joins .= " LEFT JOIN $table su ON (su.session_id = s.id)";
}

$query = "$select FROM $tbl_session s $inject_joins $where $inject_where";

if (api_is_multiple_url_enabled()) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id ";
Expand All @@ -510,6 +530,9 @@ public static function get_sessions_admin($options = array(), $get_count = false
}
}

if ($showCountUsers) {
$query .= ' GROUP by s.id';
}
$query .= $order;
$query .= $limit;
$result = Database::query($query);
Expand Down Expand Up @@ -583,6 +606,7 @@ public static function get_sessions_admin($options = array(), $get_count = false
$formatted_sessions[$session_id]['category_name'] = $categoryName;
}
}

return $formatted_sessions;
}

Expand Down Expand Up @@ -3760,7 +3784,6 @@ public static function get_users_by_session($id, $status = null, $getCount = fal
$sql .= api_sort_by_first_name() ? ' firstname, lastname' : ' lastname, firstname';

$result = Database::query($sql);

if ($getCount) {
$count = Database::fetch_assoc($result);

Expand Down Expand Up @@ -7489,6 +7512,7 @@ static function get_count_admin_complete($options = array())
*/
public static function getGridColumns($list_type = 'simple')
{
$showCount = api_get_configuration_value('session_list_show_count_users');
// Column config
$operators = array('cn', 'nc');
$date_operators = array('gt', 'ge', 'lt', 'le');
Expand All @@ -7505,13 +7529,65 @@ public static function getGridColumns($list_type = 'simple')
//get_lang('CourseTitle'),
get_lang('Visibility'),
);
$column_model = array (
array('name'=>'name', 'index'=>'s.name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)),
array('name'=>'category_name', 'index'=>'category_name', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)),
array('name'=>'display_start_date', 'index'=>'display_start_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_today', 'sopt' => $date_operators)),
array('name'=>'display_end_date', 'index'=>'display_end_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_one_month', 'sopt' => $date_operators)),
array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'),

$column_model = array(
array(
'name' => 'name',
'index' => 's.name',
'width' => '160',
'align' => 'left',
'search' => 'true',
'searchoptions' => array('sopt' => $operators),
),
array(
'name' => 'category_name',
'index' => 'category_name',
'width' => '40',
'align' => 'left',
'search' => 'true',
'searchoptions' => array('sopt' => $operators),
),
array(
'name' => 'display_start_date',
'index' => 'display_start_date',
'width' => '50',
'align' => 'left',
'search' => 'true',
'searchoptions' => array(
'dataInit' => 'date_pick_today',
'sopt' => $date_operators,
),
),
array(
'name' => 'display_end_date',
'index' => 'display_end_date',
'width' => '50',
'align' => 'left',
'search' => 'true',
'searchoptions' => array(
'dataInit' => 'date_pick_one_month',
'sopt' => $date_operators,
),
),
array(
'name' => 'visibility',
'index' => 'visibility',
'width' => '40',
'align' => 'left',
'search' => 'false',
),
);

if ($showCount) {
$columns[] = get_lang('Users');
$column_model[] = array(
'name' => 'users',
'index' => 'users',
'width' => '20',
'align' => 'left',
'search' => 'false',
);
}
break;
case 'complete':
$columns = array(
Expand Down
2 changes: 2 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,5 @@
//$_configuration['full_ckeditor_toolbar_set'] = false;
// Allow change the orientation when export a single (course progress) thematic to pdf. Portrait or landscape
//$_configuration['single_thematic_pdf_orientation'] = 'landscape';
// Show number of users in session list
//$_configuration['session_list_show_count_users'] = false;

0 comments on commit 9757d82

Please sign in to comment.