Adding "classes not added" and "classes added" pages in the course see #5619

skala
Julio Montoya 12 years ago
parent 3fdf7cbbc7
commit f603b0d8f1
  1. 42
      main/inc/ajax/model.ajax.php
  2. 89
      main/inc/lib/usergroup.lib.php
  3. 31
      main/user/class.php

@ -162,10 +162,19 @@ switch ($action) {
$count = $obj->get_count();
break;
case 'get_usergroups':
case 'get_usergroups_teacher':
$obj = new UserGroup();
$count = $obj->get_count();
break;
case 'get_usergroups_teacher':
$obj = new UserGroup();
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
$course_id = api_get_course_int_id();
if ($type == 'registered') {
$count = $obj->get_usergroup_by_course_with_data_count($course_id);
} else {
$count = $obj->get_count();
}
break;
default:
exit;
}
@ -396,15 +405,22 @@ switch ($action) {
msort($result, $sidx);
break;
case 'get_usergroups_teacher':
$columns = array('name', 'users', 'actions');
$result = Database::select('*', $obj->table, array('order'=>"name $sord", 'LIMIT'=> "$start , $limit"));
$new_result = array();
$course_id = api_get_course_int_id();
$columns = array('name', 'users', 'actions');
$options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
switch ($type) {
case 'not_registered':
$options['where'] = array(" usergroup.course_id IS NULL" => ' ');
$result = $obj->get_usergroup_not_in_course($options);
break;
case 'registered':
$options['where'] = array(" usergroup.course_id = ? " => $course_id);
$result = $obj->get_usergroup_in_course($options);
break;
}
$new_result = array();
if (!empty($result)) {
foreach ($result as $group) {
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
$url = 'class.php?action=remove_class_from_course&id='.$group['id'];
$icon = Display::return_icon('delete.png', get_lang('Remove'));
@ -412,13 +428,13 @@ switch ($action) {
$url = 'class.php?action=add_class_to_course&id='.$group['id'];
$icon = Display::return_icon('add.png', get_lang('Add'));
}
$group['actions'] = Display::url($icon, $url);
$group['actions'] = Display::url($icon, $url);
$new_result[] = $group;
}
$result = $new_result;
}
if(!in_array($sidx, $columns)) {
$result = $new_result;
}
if (!in_array($sidx, $columns)) {
$sidx = 'name';
}
//Multidimensional sort

@ -14,14 +14,15 @@ require_once 'model.lib.php';
* @package chamilo.library
*/
class UserGroup extends Model {
var $columns = array('id', 'name','description');
public function __construct() {
$this->table = Database::get_main_table(TABLE_USERGROUP);
$this->usergroup_rel_user_table = Database::get_main_table(TABLE_USERGROUP_REL_USER);
$this->usergroup_rel_course_table = Database::get_main_table(TABLE_USERGROUP_REL_COURSE);
$this->usergroup_rel_session_table = Database::get_main_table(TABLE_USERGROUP_REL_SESSION);
$this->table = Database::get_main_table(TABLE_USERGROUP);
$this->usergroup_rel_user_table = Database::get_main_table(TABLE_USERGROUP_REL_USER);
$this->usergroup_rel_course_table = Database::get_main_table(TABLE_USERGROUP_REL_COURSE);
$this->usergroup_rel_session_table = Database::get_main_table(TABLE_USERGROUP_REL_SESSION);
$this->table_course = Database::get_main_table(TABLE_MAIN_COURSE);
}
public function get_count() {
@ -29,6 +30,11 @@ class UserGroup extends Model {
return $row['count'];
}
public function get_usergroup_by_course_with_data_count($course_id) {
$row = Database::select('count(*) as count', $this->usergroup_rel_course_table, array('where' => array('course_id = ?' => $course_id)), 'first');
return $row['count'];
}
public function get_id_by_name($name) {
$row = Database::select('id', $this->table, array('where' => array('name = ?' => $name)),'first');
return $row['id'];
@ -52,28 +58,55 @@ class UserGroup extends Model {
}
function display_teacher_view() {
// action links
// action links
echo Display::grid_html('usergroups');
}
/**
/**
* Gets a list of course ids by user group
* @param int user group id
* @param int user group id
* @return array
*/
public function get_courses_by_usergroup($id) {
$results = Database::select('course_id',$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) {
$array[]= $row['course_id'];
$array[] = $row['course_id'];
}
}
return $array;
}
public function get_usergroup_in_course($options = array()) {
$sql = "SELECT u.* FROM {$this->usergroup_rel_course_table} usergroup
INNER JOIN {$this->table} u
ON (u.id = usergroup.usergroup_id)
INNER JOIN {$this->table_course} c
ON (usergroup.course_id = c.id)
";
$conditions = Database::parse_conditions($options);
$sql .= $conditions;
$result = Database::query($sql);
$array = Database::store_result($result, 'ASSOC');
return $array;
}
public function get_usergroup_not_in_course($options = array()) {
$sql = "SELECT DISTINCT u.* FROM {$this->usergroup_rel_course_table} usergroup
RIGHT JOIN {$this->table} u
ON (u.id = usergroup.usergroup_id)
";
$conditions = Database::parse_conditions($options);
$sql .= $conditions;
$result = Database::query($sql);
$array = Database::store_result($result, 'ASSOC');
return $array;
}
public function get_usergroup_by_course($course_id) {
$results = Database::select('usergroup_id', $this->usergroup_rel_course_table, array('where'=>array('course_id = ?'=> $course_id)));
$options = array('where' => array('course_id = ?' => $course_id));
$results = Database::select('usergroup_id', $this->usergroup_rel_course_table, $options);
$array = array();
if (!empty($results)) {
foreach($results as $row) {
@ -88,8 +121,7 @@ class UserGroup extends Model {
if (empty($results)) {
return false;
}
return true;
return true;
}
/**
@ -98,7 +130,7 @@ class UserGroup extends Model {
* @return array
*/
public function get_sessions_by_usergroup($id) {
$results = Database::select('session_id',$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) {
@ -134,7 +166,7 @@ class UserGroup extends Model {
* @param int user id
*/
public function get_usergroup_by_user($id) {
$results = Database::select('usergroup_id',$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) {
@ -175,13 +207,7 @@ class UserGroup extends Model {
foreach($delete_items as $session_id) {
if (!empty($user_list)) {
foreach($user_list as $user_id) {
SessionManager::unsubscribe_user_from_session($session_id, $user_id);
/*foreach ($course_list as $course_data) {
foreach($user_list as $user_id) {
CourseManager::subscribe_user($user_id, $course_data['code'], $session_id);
}
}*/
SessionManager::unsubscribe_user_from_session($session_id, $user_id);
}
}
Database::delete($this->usergroup_rel_session_table, array('usergroup_id = ? AND session_id = ?'=>array($usergroup_id, $session_id)));
@ -191,19 +217,12 @@ class UserGroup extends Model {
//Addding new relationships
if (!empty($new_items)) {
foreach($new_items as $session_id) {
$params = array('session_id'=>$session_id, 'usergroup_id'=>$usergroup_id);
$params = array('session_id'=>$session_id, 'usergroup_id' => $usergroup_id);
Database::insert($this->usergroup_rel_session_table, $params);
if (!empty($user_list)) {
SessionManager::suscribe_users_to_session($session_id, $user_list, null, false);
}
/*
$course_list = SessionManager::get_course_list_by_session_id($id);
foreach ($course_list as $course_data) {
foreach($user_list as $user_id) {
CourseManager::subscribe_user($user_id, $course_data['code'], $id);
}
}*/
}
}
}
}
@ -214,7 +233,6 @@ class UserGroup extends Model {
* @param array list of course ids (integers)
*/
function subscribe_courses_to_usergroup($usergroup_id, $list) {
$current_list = self::get_courses_by_usergroup($usergroup_id);
$user_list = self::get_users_by_usergroup($usergroup_id);
@ -256,7 +274,7 @@ class UserGroup extends Model {
function unsubscribe_courses_from_usergroup($usergroup_id, $delete_items) {
//Deleting items
if (!empty($delete_items)) {
$user_list = self::get_users_by_usergroup($usergroup_id);
$user_list = self::get_users_by_usergroup($usergroup_id);
foreach ($delete_items as $course_id) {
$course_info = api_get_course_info_by_id($course_id);
if (!empty($user_list)) {
@ -325,6 +343,7 @@ class UserGroup extends Model {
SessionManager::suscribe_users_to_session($session_id, $new_items, null, false);
}
}
foreach($new_items as $user_id) {
//Adding courses
if (!empty($course_list)) {
@ -344,4 +363,4 @@ class UserGroup extends Model {
$res = Database::query($sql);
return Database::num_rows($res) != 0;
}
}
}

@ -10,27 +10,44 @@
$language_file = array('registration','admin');
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
/**
* MAIN CODE
*/
api_protect_course_script();
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'false') {
if (!api_is_platform_admin()) {
api_not_allowed(true);
}
}
$tool_name = get_lang("Classes");
$htmlHeadXtra[] = api_get_jqgrid_js();
//extra entries in breadcrumb
$interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("ToolUser"));
Display :: display_header($tool_name, "User");
echo Display::page_header($tool_name);
$type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : 'registered';
Display :: display_header($tool_name, "User");
$usergroup = new UserGroup();
if (api_is_allowed_to_edit()) {
//echo '<a class="btn" href="subscribe_class.php?'.api_get_cidreq().'">'.get_lang("AddClassesToACourse").'</a><br />';
echo '<div class="actions">';
if ($type == 'registered') {
echo '<a href="class.php?'.api_get_cidreq().'&type=not_registered">'.Display::return_icon('add.png', get_lang("AddClassesToACourse"), array(), ICON_SIZE_MEDIUM).'</a>';
} else {
echo '<a href="class.php?'.api_get_cidreq().'&type=registered">'.Display::return_icon('empty_evaluation.png', get_lang("Classes"), array(), ICON_SIZE_MEDIUM).'</a>';
}
echo '</div>';
}
echo Display::page_header($tool_name);
if (api_is_allowed_to_edit()) {
$action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) {
@ -48,15 +65,11 @@ if (api_is_allowed_to_edit()) {
break;
}
}
/*
SHOW LIST OF CLASSES
*/
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher';
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type;
//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('Users'), get_lang('Actions'));

Loading…
Cancel
Save