Julio Montoya 12 роки тому
батько
коміт
798e8ecd65
3 змінених файлів з 16 додано та 16 видалено
  1. 3 3
      main/inc/ajax/model.ajax.php
  2. 12 6
      main/inc/lib/usergroup.lib.php
  3. 1 7
      main/user/class.php

+ 3 - 3
main/inc/ajax/model.ajax.php

@@ -406,10 +406,10 @@ switch ($action) {
         break;   
     case 'get_usergroups_teacher':
         $columns = array('name', 'users', 'actions');    
-        $options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
+        $options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");        
         switch ($type) {
             case 'not_registered':                
-                $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
+                $options['course_id'] = $course_id;
                 $result = $obj->get_usergroup_not_in_course($options);
                 break;
             case 'registered':
@@ -419,7 +419,7 @@ switch ($action) {
         }        
         $new_result = array();        
         if (!empty($result)) {
-            foreach ($result as $group) {                
+            foreach ($result as $group) {
                 $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'];

+ 12 - 6
main/inc/lib/usergroup.lib.php

@@ -87,17 +87,23 @@ class UserGroup extends Model {
                ";                
         $conditions = Database::parse_conditions($options);
         $sql .= $conditions;        
-        $result = Database::query($sql);
+        $result = Database::query($sql);        
         $array = Database::store_result($result, 'ASSOC');        
         return $array;
     }
     
     public function get_usergroup_not_in_course($options = array()) {        
-        $sql = "SELECT DISTINCT * 
-                FROM {$this->usergroup_rel_course_table} urc
-                RIGHT JOIN {$this->table} u 
-                ON (u.id = urc.usergroup_id)                
-               ";              
+        $course_id = intval($options['course_id']);        
+        unset($options['course_id']);
+        if (empty($course_id)) {
+            return false;
+        }
+        $sql = "SELECT DISTINCT u.id, name 
+                FROM {$this->table} u
+                LEFT OUTER JOIN {$this->usergroup_rel_course_table} urc
+                ON (u.id = urc.usergroup_id AND course_id = $course_id)
+                WHERE course_id is NULL
+        ";
         $conditions = Database::parse_conditions($options);
         $sql .= $conditions;        
         $result = Database::query($sql);

+ 1 - 7
main/user/class.php

@@ -11,9 +11,6 @@ $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') {
@@ -68,7 +65,6 @@ if (api_is_allowed_to_edit()) {
 
 //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;
 
 //The order is important you need to check the the $column variable in the model.ajax.php file
@@ -103,7 +99,5 @@ $(function() {
 });
 </script>
 <?php
-
 $usergroup->display_teacher_view();
-
-Display :: display_footer();
+Display :: display_footer();