|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |