1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-24 09:55:33 +02:00

course-section MDL-22262 Added a summaryformat field to the database and implemented it when editing/viewing sections and backup

This commit is contained in:
Sam Hemelryk 2010-05-27 03:07:54 +00:00
parent 277d7732c2
commit e34a326f72
10 changed files with 40 additions and 25 deletions

@ -184,7 +184,7 @@ class backup_section_structure_step extends backup_structure_step {
// Define each element separated
$section = new backup_nested_element('section', array('id'), array(
'number', 'name', 'summary', 'sequence', 'visible'));
'number', 'name', 'summary', 'summaryformat', 'sequence', 'visible'));
// Define sources

@ -44,18 +44,11 @@ require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:update', $context);
$draftitemid = file_get_submitted_draft_itemid('summary');
$currenttext = file_prepare_draft_area($draftitemid, $context->id, 'course_section', $section->id, array('subdirs'=>true), $section->summary);
$mform = new editsection_form(null, $course);
$data = array(
'id'=>$section->id,
'usedefaultname'=>(is_null($section->name)),
'name'=>$section->name,
'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid)
);
$mform->set_data($data); // set defaults
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
$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
/// If data submitted, then process and store.
if ($mform->is_cancelled()){
@ -85,6 +78,7 @@ if ($course->format == 'site') {
}
$PAGE->set_title($stredit);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($stredit);
echo $OUTPUT->header();

@ -12,7 +12,7 @@ class editsection_form extends moodleform {
global $CFG, $DB;
$mform = $this->_form;
$course = $this->_customdata;
$course = $this->_customdata['course'];
$mform->addElement('checkbox', 'usedefaultname', get_string('sectionusedefaultname'));
$mform->setDefault('usedefaultname', true);
@ -21,7 +21,9 @@ class editsection_form extends moodleform {
$mform->setType('name', PARAM_TEXT);
$mform->disabledIf('name','usedefaultname','checked');
$mform->addElement('editor', 'summary', get_string('summary'), null, array('changeformat'=>false, 'maxfiles'=>-1));
/// Prepare course and the editor
$mform->addElement('editor', 'summary', get_string('summary'), null, $this->_customdata['editoroptions']);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);

@ -106,7 +106,7 @@ if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing())
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
echo '<a title="'.$streditsummary.'" '.
@ -232,7 +232,7 @@ while ($section <= $course->numsections) {
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
} else {
echo '&nbsp;';
}

@ -97,7 +97,7 @@
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo '<p><a title="'.$streditsummary.'" '.
@ -226,7 +226,7 @@
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.

@ -1177,7 +1177,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
function get_all_sections($courseid) {
global $DB;
return $DB->get_records("course_sections", array("course"=>"$courseid"), "section",
"section, id, course, name, summary, sequence, visible");
"section, id, course, name, summary, summaryformat, sequence, visible");
}
function course_set_display($courseid, $display=0) {
@ -2498,6 +2498,7 @@ function get_course_section($section, $courseid) {
$cw->course = $courseid;
$cw->section = $section;
$cw->summary = "";
$cw->summaryformat = FORMAT_MOODLE;
$cw->sequence = "";
$id = $DB->insert_record("course_sections", $cw);
return $DB->get_record("course_sections", array("id"=>$id));
@ -2545,6 +2546,7 @@ function add_mod_to_section($mod, $beforemod=NULL) {
$section->course = $mod->course;
$section->section = $mod->section;
$section->summary = "";
$section->summaryformat = FORMAT_MOODLE;
$section->sequence = $mod->coursemodule;
return $DB->insert_record("course_sections", $section);
}

@ -98,6 +98,7 @@
$section->course = $SITE->id;
$section->section = 1;
$section->summary = '';
$section->summaryformat = '0';
$section->sequence = '';
$section->visible = 1;
$section->id = $DB->insert_record('course_sections', $section);
@ -119,7 +120,7 @@
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
if ($editing) {
$streditsummary = get_string('editsummary');

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20100525" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20100527" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@ -341,8 +341,9 @@
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="section"/>
<FIELD NAME="section" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="course" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="section" NEXT="summary"/>
<FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="sequence"/>
<FIELD NAME="sequence" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="summary" NEXT="visible"/>
<FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="summaryformat"/>
<FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summary" NEXT="sequence"/>
<FIELD NAME="sequence" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="summaryformat" NEXT="visible"/>
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" PREVIOUS="sequence"/>
</FIELDS>
<KEYS>

@ -4142,6 +4142,21 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
upgrade_main_savepoint($result, 2010052401);
}
if ($result && $oldversion < 2010052700) {
/// Define field summaryformat to be added to course sections table
$table = new xmldb_table('course_sections');
$field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'summary');
/// Conditionally launch add field summaryformat
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2010052700);
}
return $result;
}

@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2010052401; // YYYYMMDD = date of the last version bump
$version = 2010052700; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 Preview 2 (Build: 20100527)'; // Human-friendly version name