MDL-11003 adding of first activity on frontpage does not work - incorrect section

This commit is contained in:
skodak 2007-08-26 15:30:51 +00:00
parent b571c6b37b
commit 97928ddf00
2 changed files with 20 additions and 3 deletions

View 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

View 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");