Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'MDL-35776_23' of git://github.com/timhunt/moodle into M…

…OODLE_23_STABLE
  • Loading branch information...
commit 34983250b16c6368627d7b9d99d129edfec4fa0f 2 parents ae48ff8 + 1381537
Aparup Banerjee authored October 09, 2012
8  enrol/ajax.php
@@ -54,9 +54,9 @@
54 54
 
55 55
 $manager = new course_enrolment_manager($PAGE, $course);
56 56
 
57  
-$outcome = new stdClass;
  57
+$outcome = new stdClass();
58 58
 $outcome->success = true;
59  
-$outcome->response = new stdClass;
  59
+$outcome->response = new stdClass();
60 60
 $outcome->error = '';
61 61
 
62 62
 switch ($action) {
@@ -99,6 +99,10 @@
99 99
             $user->fullname = fullname($user);
100 100
             unset($user->id);
101 101
         }
  102
+        // Chrome will display users in the order of the array keys, so we need
  103
+        // to ensure that the results ordered array keys. Fortunately, the JavaScript
  104
+        // does not care what the array keys are. It uses user.id where necessary.
  105
+        $outcome->response['users'] = array_values($outcome->response['users']);
102 106
         $outcome->success = true;
103 107
         break;
104 108
     default:
10  enrol/manual/ajax.php
@@ -53,9 +53,9 @@
53 53
 
54 54
 $manager = new course_enrolment_manager($PAGE, $course);
55 55
 
56  
-$outcome = new stdClass;
  56
+$outcome = new stdClass();
57 57
 $outcome->success = true;
58  
-$outcome->response = new stdClass;
  58
+$outcome->response = new stdClass();
59 59
 $outcome->error = '';
60 60
 
61 61
 switch ($action) {
@@ -79,6 +79,10 @@
79 79
             }
80 80
             $user->extrafields = implode(', ', $fieldvalues);
81 81
         }
  82
+        // Chrome will display users in the order of the array keys, so we need
  83
+        // to ensure that the results ordered array keys. Fortunately, the JavaScript
  84
+        // does not care what the array keys are. It uses user.id where necessary.
  85
+        $outcome->response['users'] = array_values($outcome->response['users']);
82 86
         $outcome->success = true;
83 87
         break;
84 88
     case 'enrol':
@@ -135,4 +139,4 @@
135 139
         throw new enrol_ajax_exception('unknowajaxaction');
136 140
 }
137 141
 
138  
-echo json_encode($outcome);
  142
+echo json_encode($outcome);
14  user/selector/module.js
@@ -221,8 +221,9 @@ M.core_user.init_user_selector = function (Y, name, hash, extrafields, lastsearc
221 221
 
222 222
             // Output each optgroup.
223 223
             var count = 0;
224  
-            for (var groupname in data.results) {
225  
-                this.output_group(groupname, data.results[groupname], selectedusers, true);
  224
+            for (var key in data.results) {
  225
+                var groupdata = data.results[key];
  226
+                this.output_group(groupdata.name, groupdata.users, selectedusers, true);
226 227
                 count++;
227 228
             }
228 229
             if (!count) {
@@ -248,13 +249,14 @@ M.core_user.init_user_selector = function (Y, name, hash, extrafields, lastsearc
248 249
         output_group : function(groupname, users, selectedusers, processsingle) {
249 250
             var optgroup = Y.Node.create('<optgroup></optgroup>');
250 251
             var count = 0;
251  
-            for (var userid in users) {
252  
-                var user = users[userid];
253  
-                var option = Y.Node.create('<option value="'+userid+'">'+user.name+'</option>');
  252
+            for (var key in users) {
  253
+                var user = users[key];
  254
+                var option = Y.Node.create('<option value="'+user.id+'">'+user.name+'</option>');
254 255
                 if (user.disabled) {
255 256
                     option.set('disabled', true);
256  
-                } else if (selectedusers===true || selectedusers[userid]) {
  257
+                } else if (selectedusers===true || selectedusers[user.id]) {
257 258
                     option.set('selected', true);
  259
+                    delete selectedusers[user.id];
258 260
                 } else {
259 261
                     option.set('selected', false);
260 262
                 }
13  user/selector/search.php
@@ -78,17 +78,20 @@
78 78
 $userselector = new $classname($name, $options);
79 79
 
80 80
 // Do the search and output the results.
81  
-$users = $userselector->find_users($search);
82  
-foreach ($users as &$group) {
83  
-    foreach ($group as $user) {
  81
+$results = $userselector->find_users($search);
  82
+$json = array();
  83
+foreach ($results as $groupname => $users) {
  84
+    $groupdata = array('name' => $groupname, 'users' => array());
  85
+    foreach ($users as $user) {
84 86
         $output = new stdClass;
85 87
         $output->id = $user->id;
86 88
         $output->name = $userselector->output_user($user);
87 89
         if (!empty($user->disabled)) {
88 90
             $output->disabled = true;
89 91
         }
90  
-        $group[$user->id] = $output;
  92
+        $groupdata['users'][] = $output;
91 93
     }
  94
+    $json[] = $groupdata;
92 95
 }
93 96
 
94  
-echo json_encode(array('results' => $users));
  97
+echo json_encode(array('results' => $json));

0 notes on commit 3498325

Please sign in to comment.
Something went wrong with that request. Please try again.