]> git.mjollnir.org Git - moodle.git/commitdiff
if the user has no capability, after creating a course we add him to the first role...
authortoyomoyo <toyomoyo>
Mon, 18 Sep 2006 09:10:03 +0000 (09:10 +0000)
committertoyomoyo <toyomoyo>
Mon, 18 Sep 2006 09:10:03 +0000 (09:10 +0000)
course/edit.php

index 2d1ff3dea041b2eb484a35b6d40066eccec57ed2..1a04be17af634fc9725628fc8ba002a3cffca48a 100644 (file)
 
                     } else {         // Add current teacher and send to course
 
-                        $newteacher = NULL;
-                        $newteacher->userid = $USER->id;
-                        $newteacher->course = $newcourseid;
-                        $newteacher->authority = 1;   // First teacher is the main teacher
-                        $newteacher->editall = 1;     // Course creator can edit their own course
-                        $newteacher->enrol = 'manual';// enrol the teacher too - bug #6120
-
-                        if (!$newteacher->id = insert_record("user_teachers", $newteacher)) {
-                            error("Could not add you to this new course!");
+                        // find a role with legacy:edittingteacher
+                        
+                        if ($teacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, $context)) {
+                            // assign the role to this user
+                            $teachereditrole = array_shift($teacherroles);
+                            role_assign($teachereditrole->id, $USER->id, 0, $context->id);
                         }
-
-                        $USER->teacher[$newcourseid] = true;
-                        $USER->teacheredit[$newcourseid] = true;
-
-                        fix_course_sortorder();
-
+                        
                         redirect("view.php?id=$newcourseid", get_string("changessaved"));
                     }