Adding number of sessions, courses and users in the admin/usergroup.php table see BT#2019

skala
Julio Montoya 14 years ago
parent 76df06c1c9
commit 4147f594fe
  1. 2
      main/admin/add_sessions_to_usergroup.php
  2. 12
      main/admin/usergroups.php
  3. 22
      main/inc/ajax/model.ajax.php
  4. 31
      main/inc/lib/array.lib.php
  5. 8
      main/inc/lib/usergroup.lib.php

@ -34,7 +34,7 @@ $interbreadcrumb[]=array('url' => 'usergroups.php','name' => get_lang('Groups'))
// Database Table Definitions
// setting the name of the tool
$tool_name=get_lang('SubscribeSessionsToUser');
$tool_name=get_lang('SubscribeSessionsToGroup');
$add_type = 'multiple';
if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){

@ -42,12 +42,16 @@ if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups';
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Name'),get_lang('Description'),get_lang('Actions'));
$columns = array(get_lang('Name'), get_lang('Users'), get_lang('Courses'), get_lang('Sessions'), get_lang('Actions'));
//Column config
$column_model = array(array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left'),
array('name'=>'actions', 'index'=>'actions', 'formatter'=>'action_formatter','width'=>'100', 'align'=>'left'),
$column_model = array(
array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
//array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left'),
array('name'=>'users', 'index'=>'users', 'width'=>'200', 'align'=>'left'),
array('name'=>'courses', 'index'=>'courses', 'width'=>'200', 'align'=>'left'),
array('name'=>'sessions', 'index'=>'sessions', 'width'=>'200', 'align'=>'left'),
array('name'=>'actions', 'index'=>'actions', 'formatter'=>'action_formatter','width'=>'100', 'align'=>'left','sortable'=>'false'),
);
//Autowidth
$extra_params['autowidth'] = 'true';

@ -6,6 +6,7 @@ $action = $_GET['a'];
require_once '../global.inc.php';
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'array.lib.php';
// 1. Setting variables needed by jqgrid
@ -64,6 +65,8 @@ if ($_REQUEST['oper'] == 'del') {
$obj->delete($_REQUEST['id']);
}
//4. Querying the DB for the elements
$columns = array();
switch ($action) {
@ -81,12 +84,25 @@ switch ($action) {
}
$result = Database::select('p.id,p.name, p.description, c.name as career', "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
break;
case 'get_usergroups':
$columns = array('name', 'description', 'actions');
case 'get_usergroups':
$columns = array('name', 'users', 'courses','sessions','actions');
$result = Database::select('*', $obj->table, array('order'=>"name $sord", 'LIMIT'=> "$start , $limit"));
$new_result = array();
if (!empty($result)) {
foreach ($result as $group) {
$group['sessions'] = count($obj->get_sessions_by_usergroup($group['id']));
$group['courses'] = count($obj->get_courses_by_usergroup($group['id']));
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
$new_result[] = $group;
}
$result = $new_result;
}
$columns = array('name', 'users', 'courses','sessions');
if(!in_array($sidx, $columns)) {
$sidx = 'name';
}
$result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
//Multidimensional sort
msort($result, $sidx);
break;
default:
exit;

@ -13,6 +13,7 @@
*
* @param array a dimensional array
* @return array an array with unique values
*
*/
function array_unique_dimensional($array) {
if(!is_array($array))
@ -29,4 +30,32 @@ function array_unique_dimensional($array) {
}
return $array;
}
?>
/**
*
* Sort multidimensional arrays
*
* @param array unsorted multidimensional array
* @param string key
* @return array result array
* @author founded in http://php.net/manual/en/function.sort.php
*/
function msort($array, $id="id") {
if (empty($array)) {
return $array;
}
$temp_array = array();
while (count($array)>0) {
$lowest_id = 0;
$index=0;
foreach ($array as $item) {
if ($item[$id]<$array[$lowest_id][$id]) {
$lowest_id = $index;
}
$index++;
}
$temp_array[] = $array[$lowest_id];
$array = array_merge(array_slice($array, 0, $lowest_id), array_slice($array, $lowest_id+1));
}
return $temp_array;
}

@ -38,7 +38,7 @@ class UserGroup extends Model {
* @return array
*/
public function get_courses_by_usergroup($id) {
$results = Database::select('*',$this->usergroup_rel_course_table, array('where'=>array('usergroup_id = ?'=>$id)));
$results = Database::select('course_id',$this->usergroup_rel_course_table, array('where'=>array('usergroup_id = ?'=>$id)));
$array = array();
if (!empty($results)) {
foreach($results as $row) {
@ -54,7 +54,7 @@ class UserGroup extends Model {
* @return array
*/
public function get_sessions_by_usergroup($id) {
$results = Database::select('*',$this->usergroup_rel_session_table, array('where'=>array('usergroup_id = ?'=>$id)));
$results = Database::select('session_id',$this->usergroup_rel_session_table, array('where'=>array('usergroup_id = ?'=>$id)));
$array = array();
if (!empty($results)) {
foreach($results as $row) {
@ -70,7 +70,7 @@ class UserGroup extends Model {
* @return array with a list of user ids
*/
public function get_users_by_usergroup($id) {
$results = Database::select('*',$this->usergroup_rel_user_table, array('where'=>array('usergroup_id = ?'=>$id)));
$results = Database::select('user_id',$this->usergroup_rel_user_table, array('where'=>array('usergroup_id = ?'=>$id)));
$array = array();
if (!empty($results)) {
foreach($results as $row) {
@ -85,7 +85,7 @@ class UserGroup extends Model {
* @param int user id
*/
public function get_usergroup_by_user($id) {
$results = Database::select('*',$this->usergroup_rel_user_table, array('where'=>array('user_id = ?'=>$id)));
$results = Database::select('usergroup_id',$this->usergroup_rel_user_table, array('where'=>array('user_id = ?'=>$id)));
$array = array();
if (!empty($results)) {
foreach($results as $row) {

Loading…
Cancel
Save