Skip to content

Commit

Permalink
course-section MDL-22262 Added a summaryformat field to the database …
Browse files Browse the repository at this point in the history
…and implemented it when editing/viewing sections and backup
  • Loading branch information
Sam Hemelryk committed May 27, 2010
1 parent 277d773 commit e34a326
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function define_structure() {
// 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

Expand Down
18 changes: 6 additions & 12 deletions course/editsection.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,11 @@
$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()){
Expand Down Expand Up @@ -85,6 +78,7 @@
}

$PAGE->set_title($stredit);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($stredit);
echo $OUTPUT->header();

Expand Down
6 changes: 4 additions & 2 deletions course/editsection_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function definition() {
global $CFG, $DB;

$mform = $this->_form;
$course = $this->_customdata;
$course = $this->_customdata['course'];

$mform->addElement('checkbox', 'usedefaultname', get_string('sectionusedefaultname'));
$mform->setDefault('usedefaultname', true);
Expand All @@ -21,7 +21,9 @@ function definition() {
$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);
Expand Down
4 changes: 2 additions & 2 deletions course/format/topics/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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', $coursecontext)) {
echo '<a title="'.$streditsummary.'" '.
Expand Down Expand Up @@ -232,7 +232,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);
} else {
echo '&nbsp;';
}
Expand Down
4 changes: 2 additions & 2 deletions course/format/weeks/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'" '.
Expand Down Expand Up @@ -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.'">'.
Expand Down
4 changes: 3 additions & 1 deletion course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
@@ -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"
>
Expand Down Expand Up @@ -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>
Expand Down
15 changes: 15 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,21 @@ function xmldb_main_upgrade($oldversion) {
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;
}

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e34a326

Please sign in to comment.