]> git.mjollnir.org Git - moodle.git/commitdiff
generator: Fix to use role_assign, rather than screwing with the role_assignments...
authortjhunt <tjhunt>
Thu, 6 Nov 2008 04:10:22 +0000 (04:10 +0000)
committertjhunt <tjhunt>
Thu, 6 Nov 2008 04:10:22 +0000 (04:10 +0000)
admin/generator.php

index 68a55b6b44baf894cd9112e7ec3999c7cfa4d478..cb87a60732ba37cf2d4b9a7d7f8da09df4400e71 100755 (executable)
@@ -673,17 +673,9 @@ class generator {
                 shuffle($users);
                 $users_to_assign = array_slice($users, 0, $this->get('students_per_course'));
 
+                $context = get_context_instance(CONTEXT_COURSE, $courseid);
                 foreach ($users_to_assign as $random_user) {
-
-                    $context = get_context_instance(CONTEXT_COURSE, $courseid);
-
-                    $newra = new stdClass();
-                    $newra->roleid = 5; // Student role
-                    $newra->contextid = $context->id;
-                    $newra->userid = $random_user;
-                    $newra->hidden = 0;
-                    $newra->enrol = 1;
-                    $success = $DB->insert_record('role_assignments', $newra);
+                    $success = role_assign(5, $random_user, 0, $context->id);
 
                     if ($success) {
                         $assigned_count++;