MDL-22729 Course sections can be re-edited again

By the way, the current style of creating course_sections is ugly. We
should probably have something like
make_sure_that_at_least_default_section_exists($courseid, $sectionid=null)
and not to insert it into database at many places as we do now.
This commit is contained in:
David Mudrak 2010-06-10 18:25:06 +00:00
parent 33b1a40639
commit 09eb215121
8 changed files with 17 additions and 14 deletions

View file

@ -32,13 +32,8 @@ $id = required_param('id',PARAM_INT); // Week/topic ID
$PAGE->set_url('/course/editsection.php', array('id'=>$id));
if (! $section = $DB->get_record("course_sections", array("id"=>$id))) {
print_error("sectionnotexist");
}
if (! $course = $DB->get_record("course", array("id"=>$section->course))) {
print_error("invalidcourseid");
}
$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
@ -48,7 +43,7 @@ $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->m
$section = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course_section', $section->id);
$section->usedefaultname = (is_null($section->name));
$mform = new editsection_form(null, array('course'=>$course, 'editoroptions'=>$editoroptions));
$mform->set_data($section); // set defaults
$mform->set_data($section); // set current value
/// If data submitted, then process and store.
if ($mform->is_cancelled()){
@ -60,7 +55,9 @@ if ($mform->is_cancelled()){
} else {
$section->name = null;
}
$section->summary = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']);
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course_section', $section->id);
$section->summary = $data->summary;
$section->summaryformat = $data->summaryformat;
$DB->update_record('course_sections', $section);
add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
redirect("view.php?id=$course->id");

View file

@ -22,8 +22,9 @@ class editsection_form extends moodleform {
$mform->disabledIf('name','usedefaultname','checked');
/// Prepare course and the editor
$mform->addElement('editor', 'summary', get_string('summary'), null, $this->_customdata['editoroptions']);
$mform->addElement('editor', 'summary_editor', get_string('summary'), null, $this->_customdata['editoroptions']);
$mform->setType('summary_editor', PARAM_RAW);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);

View file

@ -2515,7 +2515,7 @@ function get_course_section($section, $courseid) {
$cw->course = $courseid;
$cw->section = $section;
$cw->summary = "";
$cw->summaryformat = FORMAT_MOODLE;
$cw->summaryformat = FORMAT_HTML;
$cw->sequence = "";
$id = $DB->insert_record("course_sections", $cw);
return $DB->get_record("course_sections", array("id"=>$id));
@ -2563,7 +2563,7 @@ function add_mod_to_section($mod, $beforemod=NULL) {
$section->course = $mod->course;
$section->section = $mod->section;
$section->summary = "";
$section->summaryformat = FORMAT_MOODLE;
$section->summaryformat = FORMAT_HTML;
$section->sequence = $mod->coursemodule;
return $DB->insert_record("course_sections", $section);
}
@ -3451,6 +3451,7 @@ function create_course($data) {
$section = new object();
$section->course = $course->id; // Create a default section.
$section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record('course_sections', $section);
fix_course_sortorder();

View file

@ -229,6 +229,7 @@
$section->course = $course->id; // Create a default section.
$section->section = 0;
$section->visible = 1;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record('course_sections', $section);
}
if (! $sections = get_all_sections($course->id) ) { // Try again