Add group filter see BT#4301

1.10.x
Julio Montoya 10 years ago
parent 6c208e09d4
commit cab5e96359
  1. 2
      main/group/group_creation.php
  2. 14
      main/inc/ajax/model.ajax.php
  3. 2
      main/inc/lib/groupmanager.lib.php
  4. 84
      main/inc/lib/usergroup.lib.php
  5. 24
      main/user/class.php

@ -255,7 +255,7 @@ EOT;
*/ */
$options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id()); $options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id());
$obj = new UserGroup(); $obj = new UserGroup();
$classes = $obj->get_usergroup_in_course($options); $classes = $obj->getUserGroupInCourse($options);
if (count($classes) > 0) { if (count($classes) > 0) {
echo '<b>'.get_lang('GroupsFromClasses').'</b>'; echo '<b>'.get_lang('GroupsFromClasses').'</b>';
echo '<blockquote>'; echo '<blockquote>';

@ -474,11 +474,13 @@ switch ($action) {
case 'get_usergroups_teacher': case 'get_usergroups_teacher':
$obj = new UserGroup(); $obj = new UserGroup();
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered'; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
$groupFilter = isset($_REQUEST['group_filter']) ? intval($_REQUEST['group_filter']) : 0;
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
if ($type == 'registered') { if ($type == 'registered') {
$count = $obj->get_usergroup_by_course_with_data_count($course_id); $count = $obj->getUserGroupByCourseWithDataCount($course_id, $groupFilter);
} else { } else {
$count = $obj->get_count(); $count = $obj->get_count($groupFilter);
} }
break; break;
default: default:
@ -1392,11 +1394,11 @@ switch ($action) {
switch ($type) { switch ($type) {
case 'not_registered': case 'not_registered':
$options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id); $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
$result = $obj->get_usergroup_not_in_course($options); $result = $obj->getUserGroupNotInCourse($options, $groupFilter);
break; break;
case 'registered': case 'registered':
$options['where'] = array(" usergroup.course_id = ? " => $course_id); $options['where'] = array(" usergroup.course_id = ? " => $course_id);
$result = $obj->get_usergroup_in_course($options); $result = $obj->getUserGroupInCourse($options);
break; break;
} }
@ -1422,8 +1424,10 @@ switch ($action) {
} }
$role = $obj->getUserRoleToString(api_get_user_id(), $group['id']); $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
$group['status'] = $role; $group['status'] = $role;
$group['actions'] = Display::url($icon, $url);
$group['actions'] = Display::url(get_lang('reg'), $url, ['class' => 'btn btn-primary']);
$new_result[] = $group; $new_result[] = $group;
} }
$result = $new_result; $result = $new_result;

@ -326,7 +326,7 @@ class GroupManager
{ {
$options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id()); $options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id());
$obj = new UserGroup(); $obj = new UserGroup();
$classes = $obj->get_usergroup_in_course($options); $classes = $obj->getUserGroupInCourse($options);
$group_ids = array(); $group_ids = array();
foreach ($classes as $class) { foreach ($classes as $class) {
$users_ids = $obj->get_users_by_usergroup($class['id']); $users_ids = $obj->get_users_by_usergroup($class['id']);

@ -71,7 +71,7 @@ class UserGroup extends Model
/** /**
* @return int * @return int
*/ */
public function get_count() public function get_count($type = -1)
{ {
if ($this->useMultipleUrl) { if ($this->useMultipleUrl) {
$urlId = api_get_current_access_url_id(); $urlId = api_get_current_access_url_id();
@ -89,22 +89,40 @@ class UserGroup extends Model
return 0; return 0;
} else { } else {
return $this->getTotalCount();
$typeCondition = '';
if ($type != -1) {
$type = intval($type);
$typeCondition = " WHERE group_type = $type ";
}
$sql = "SELECT count(a.id) as count
FROM {$this->table} a
$typeCondition
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);
return $row['count'];
}
} }
} }
/** /**
* @param int $course_id * @param int $course_id
* @param int $type
* *
* @return mixed * @return mixed
*/ */
public function get_usergroup_by_course_with_data_count($course_id) public function getUserGroupByCourseWithDataCount($course_id, $type = -1)
{ {
if ($this->useMultipleUrl) { if ($this->useMultipleUrl) {
$course_id = intval($course_id); $course_id = intval($course_id);
$urlId = api_get_current_access_url_id(); $urlId = api_get_current_access_url_id();
$sql = "SELECT count(c.usergroup_id) as count FROM {$this->usergroup_rel_course_table} c $sql = "SELECT count(c.usergroup_id) as count
INNER JOIN {$this->access_url_rel_usergroup} a ON (c.usergroup_id = a.usergroup_id) FROM {$this->usergroup_rel_course_table} c
INNER JOIN {$this->access_url_rel_usergroup} a
ON (c.usergroup_id = a.usergroup_id)
WHERE access_url_id = $urlId AND course_id = $course_id WHERE access_url_id = $urlId AND course_id = $course_id
"; ";
$result = Database::query($sql); $result = Database::query($sql);
@ -115,14 +133,26 @@ class UserGroup extends Model
return 0; return 0;
} else { } else {
$row = Database::select( $typeCondition = '';
'count(*) as count', if ($type != -1) {
$this->usergroup_rel_course_table, $type = intval($type);
array('where' => array('course_id = ?' => $course_id)), $typeCondition = " AND group_type = $type ";
'first' }
); $sql = "SELECT count(c.usergroup_id) as count
FROM {$this->usergroup_rel_course_table} c
INNER JOIN {$this->table} a
ON (c.usergroup_id = a.id)
WHERE
course_id = $course_id
$typeCondition
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);
return $row['count'];
}
return $row['count']; return 0;
} }
} }
@ -231,7 +261,7 @@ class UserGroup extends Model
* *
* @return array * @return array
*/ */
public function get_usergroup_in_course($options = array()) public function getUserGroupInCourse($options = array())
{ {
if ($this->useMultipleUrl) { if ($this->useMultipleUrl) {
$sql = "SELECT u.* FROM {$this->usergroup_rel_course_table} usergroup $sql = "SELECT u.* FROM {$this->usergroup_rel_course_table} usergroup
@ -239,7 +269,8 @@ class UserGroup extends Model
ON (u.id = usergroup.usergroup_id) ON (u.id = usergroup.usergroup_id)
INNER JOIN {$this->table_course} c INNER JOIN {$this->table_course} c
ON (usergroup.course_id = c.id) ON (usergroup.course_id = c.id)
INNER JOIN {$this->access_url_rel_usergroup} a ON (a.usergroup_id = u.id) INNER JOIN {$this->access_url_rel_usergroup} a
ON (a.usergroup_id = u.id)
"; ";
} else { } else {
$sql = "SELECT u.* FROM {$this->usergroup_rel_course_table} usergroup $sql = "SELECT u.* FROM {$this->usergroup_rel_course_table} usergroup
@ -249,13 +280,22 @@ class UserGroup extends Model
ON (usergroup.course_id = c.id) ON (usergroup.course_id = c.id)
"; ";
} }
$conditions = Database::parse_conditions($options); $conditions = Database::parse_conditions($options);
if (empty($conditions)) {
$conditions .= "WHERE 1 = 1 $typeCondition ";
} else {
$conditions .= " $typeCondition ";
}
$sql .= $conditions; $sql .= $conditions;
if ($this->useMultipleUrl) { if ($this->useMultipleUrl) {
$urlId = api_get_current_access_url_id(); $urlId = api_get_current_access_url_id();
$sql .= " AND access_url_id = $urlId "; $sql .= " AND access_url_id = $urlId ";
} }
if (isset($options['LIMIT'])) { if (isset($options['LIMIT'])) {
$limits = explode(',', $options['LIMIT']); $limits = explode(',', $options['LIMIT']);
$limits = array_map('intval', $limits); $limits = array_map('intval', $limits);
@ -272,10 +312,11 @@ class UserGroup extends Model
/** /**
* @param array $options * @param array $options
* @param int $type
* *
* @return array|bool * @return array|bool
*/ */
public function get_usergroup_not_in_course($options = array()) public function getUserGroupNotInCourse($options = array(), $type = -1)
{ {
$course_id = null; $course_id = null;
if (isset($options['course_id'])) { if (isset($options['course_id'])) {
@ -287,6 +328,12 @@ class UserGroup extends Model
return false; return false;
} }
$typeCondition = '';
if ($type != -1) {
$type = intval($type);
$typeCondition = " AND group_type = $type ";
}
if ($this->useMultipleUrl) { if ($this->useMultipleUrl) {
$urlId = api_get_current_access_url_id(); $urlId = api_get_current_access_url_id();
$sql = "SELECT DISTINCT u.* $sql = "SELECT DISTINCT u.*
@ -304,6 +351,13 @@ class UserGroup extends Model
"; ";
} }
$conditions = Database::parse_conditions($options); $conditions = Database::parse_conditions($options);
if (empty($conditions)) {
$conditions .= "WHERE 1 = 1 $typeCondition ";
} else {
$conditions .= " $typeCondition ";
}
$sql .= $conditions; $sql .= $conditions;
if ($this->useMultipleUrl) { if ($this->useMultipleUrl) {

@ -23,6 +23,18 @@ $htmlHeadXtra[] = api_get_jqgrid_js();
$interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("ToolUser")); $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("ToolUser"));
$type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : 'registered'; $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : 'registered';
$groupFilter = isset($_GET['group_filter']) ? intval($_GET['group_filter']) : 0;
$htmlHeadXtra[] = '
<script>
$(document).ready( function() {
$("#group_filter").change(function() {
window.location = "class.php?'.api_get_cidreq().'&type='.$type.'" +"&group_filter=" + $(this).val();
});
});
</script>
';
Display :: display_header($tool_name, "User"); Display :: display_header($tool_name, "User");
@ -36,6 +48,16 @@ if (api_is_allowed_to_edit()) {
} else { } else {
echo '<a href="class.php?'.api_get_cidreq().'&type=registered">'. echo '<a href="class.php?'.api_get_cidreq().'&type=registered">'.
Display::return_icon('empty_evaluation.png', get_lang("Classes"), array(), ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('empty_evaluation.png', get_lang("Classes"), array(), ICON_SIZE_MEDIUM).'</a>';
$form = new FormValidator('groups', 'post', api_get_self(), '', '', FormValidator::LAYOUT_INLINE);
$options = [
-1 => get_lang('All'),
1 => get_lang('SocialGroups'),
0 => get_lang('Classes'),
];
$form->addSelect('group_filter', get_lang('Groups'), $options, ['id' => 'group_filter']);
$form->setDefaults(['group_filter' => $groupFilter]);
$form->display();
} }
echo '</div>'; echo '</div>';
} }
@ -69,7 +91,7 @@ if (api_is_allowed_to_edit()) {
//jqgrid will use this URL to do the selects //jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type; $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter;
//The order is important you need to check the the $column variable in the model.ajax.php file //The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array( $columns = array(

Loading…
Cancel
Save