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)); $PAGE->set_url('/course/editsection.php', array('id'=>$id));
if (! $section = $DB->get_record("course_sections", array("id"=>$id))) { $section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
print_error("sectionnotexist"); $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
}
if (! $course = $DB->get_record("course", array("id"=>$section->course))) {
print_error("invalidcourseid");
}
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $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 = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course_section', $section->id);
$section->usedefaultname = (is_null($section->name)); $section->usedefaultname = (is_null($section->name));
$mform = new editsection_form(null, array('course'=>$course, 'editoroptions'=>$editoroptions)); $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 data submitted, then process and store.
if ($mform->is_cancelled()){ if ($mform->is_cancelled()){
@ -60,7 +55,9 @@ if ($mform->is_cancelled()){
} else { } else {
$section->name = null; $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); $DB->update_record('course_sections', $section);
add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section"); add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
redirect("view.php?id=$course->id"); redirect("view.php?id=$course->id");

View file

@ -23,7 +23,8 @@ class editsection_form extends moodleform {
/// Prepare course and the editor /// 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->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);

View file

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

View file

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

View file

@ -608,6 +608,7 @@ function create_course ($course,$skip_fix_course_sortorder=0){
$section = new object(); $section = new object();
$section->course = $newcourseid; // Create a default section. $section->course = $newcourseid; // Create a default section.
$section->section = 0; $section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record("course_sections", $section); $section->id = $DB->insert_record("course_sections", $section);
$course = $DB->get_record('course', array('id' => $newcourseid)); $course = $DB->get_record('course', array('id' => $newcourseid));
blocks_add_default_course_blocks($course); blocks_add_default_course_blocks($course);

View file

@ -545,6 +545,7 @@ function process_group_tag($tagcontents){
$section = new object(); $section = new object();
$section->course = $course->id; // Create a default section. $section->course = $course->id; // Create a default section.
$section->section = 0; $section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record("course_sections", $section); $section->id = $DB->insert_record("course_sections", $section);
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)"); add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");

View file

@ -597,6 +597,7 @@ function create_course ($course_ext,$skip_fix_course_sortorder=0){
$section = new object(); $section = new object();
$section->course = $newcourseid; // Create a default section. $section->course = $newcourseid; // Create a default section.
$section->section = 0; $section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record("course_sections", $section); $section->id = $DB->insert_record("course_sections", $section);
$course = $DB->get_record('course', array('id' => $newcourseid)); $course = $DB->get_record('course', array('id' => $newcourseid));
blocks_add_default_course_blocks($course); blocks_add_default_course_blocks($course);

View file

@ -98,7 +98,7 @@
$section->course = $SITE->id; $section->course = $SITE->id;
$section->section = 1; $section->section = 1;
$section->summary = ''; $section->summary = '';
$section->summaryformat = '0'; $section->summaryformat = FORMAT_HTML;
$section->sequence = ''; $section->sequence = '';
$section->visible = 1; $section->visible = 1;
$section->id = $DB->insert_record('course_sections', $section); $section->id = $DB->insert_record('course_sections', $section);