]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11003 adding of first activity on frontpage does not work - incorrect section
authorskodak <skodak>
Sun, 26 Aug 2007 15:30:51 +0000 (15:30 +0000)
committerskodak <skodak>
Sun, 26 Aug 2007 15:30:51 +0000 (15:30 +0000)
course/lib.php
course/modedit.php

index 87813327813feab85960e13a5ad0a79a9ccacef3..22dae509d247e05bf9d0831f133a81411d0a57e4 100644 (file)
@@ -2007,6 +2007,25 @@ function add_course_module($mod) {
     return insert_record("course_modules", $mod);
 }
 
+/**
+ * Returns course section - creates new if does not exist yet.
+ * @param int $relative section number
+ * @param int $courseid
+ * @return object $course_section object
+ */
+function get_course_section($section, $courseid) {
+    if ($cw = get_record("course_sections", "section", $section, "course", $courseid)) {
+        return $cw;
+    }
+    $cw = new object();
+    $cw->course = $courseid;
+    $cw->section = $section;
+    $cw->summary = "";
+    $cw->sequence = "";
+    $id = insert_record("course_sections", $cw);
+    return get_record("course_sections", "id", $id);
+}
+
 function add_mod_to_section($mod, $beforemod=NULL) {
 /// Given a full mod object with section and course already defined
 /// If $before is specified, then this is an existing ID which we
index 1792d0fb9e1a5a8df1dd5536a6c5e6263471f4b5..0b9e9d40c60a8f81a6ed972bafe874898c1ab6fc 100644 (file)
@@ -29,9 +29,7 @@
             error("This module type doesn't exist");
         }
 
-        if (! $cw = get_record("course_sections", "section", $section, "course", $course->id)) {
-            error("This course section doesn't exist");
-        }
+        $cw = get_course_section($section, $course->id);
 
         if (!course_allowed_module($course, $module->id)) {
             error("This module has been disabled for this particular course");