From: toyomoyo Date: Mon, 18 Sep 2006 09:10:03 +0000 (+0000) Subject: if the user has no capability, after creating a course we add him to the first role... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=65becbc3ef102cbf5a37592c7d9af1eab46190c0;p=moodle.git if the user has no capability, after creating a course we add him to the first role with legacy:edittingteacher, to make him a legacy editting teacher --- diff --git a/course/edit.php b/course/edit.php index 2d1ff3dea0..1a04be17af 100644 --- a/course/edit.php +++ b/course/edit.php @@ -144,22 +144,14 @@ } 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")); }