Skip to content

Commit

Permalink
MDL-22729 Course sections can be re-edited again
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mudrd8mz committed Jun 10, 2010
1 parent 33b1a40 commit 09eb215
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
15 changes: 6 additions & 9 deletions course/editsection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@

$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);
Expand All @@ -48,7 +43,7 @@
$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()){
Expand All @@ -60,7 +55,9 @@
} 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");
Expand Down
5 changes: 3 additions & 2 deletions course/editsection_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ function definition() {
$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);
Expand Down
5 changes: 3 additions & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions enrol/database/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ function create_course ($course,$skip_fix_course_sortorder=0){
$section = new object();
$section->course = $newcourseid; // Create a default section.
$section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record("course_sections", $section);
$course = $DB->get_record('course', array('id' => $newcourseid));
blocks_add_default_course_blocks($course);
Expand Down
1 change: 1 addition & 0 deletions enrol/imsenterprise/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ function process_group_tag($tagcontents){
$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);

add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
Expand Down
1 change: 1 addition & 0 deletions enrol/ldap/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ function create_course ($course_ext,$skip_fix_course_sortorder=0){
$section = new object();
$section->course = $newcourseid; // Create a default section.
$section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record("course_sections", $section);
$course = $DB->get_record('course', array('id' => $newcourseid));
blocks_add_default_course_blocks($course);
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
$section->course = $SITE->id;
$section->section = 1;
$section->summary = '';
$section->summaryformat = '0';
$section->summaryformat = FORMAT_HTML;
$section->sequence = '';
$section->visible = 1;
$section->id = $DB->insert_record('course_sections', $section);
Expand Down

0 comments on commit 09eb215

Please sign in to comment.