From 97928ddf00529906df69c5f04c26ad5bedb39088 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 26 Aug 2007 15:30:51 +0000 Subject: [PATCH] MDL-11003 adding of first activity on frontpage does not work - incorrect section --- course/lib.php | 19 +++++++++++++++++++ course/modedit.php | 4 +--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/course/lib.php b/course/lib.php index 8781332781..22dae509d2 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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 diff --git a/course/modedit.php b/course/modedit.php index 1792d0fb9e..0b9e9d40c6 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -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"); -- 2.39.5