Skip to content

Commit

Permalink
MDL-18910 normalised module intro and introformat
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Apr 20, 2009
1 parent 18b5df9 commit 8b6c22a
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 38 deletions.
2 changes: 1 addition & 1 deletion mod/resource/backuplib.php
Expand Up @@ -51,7 +51,7 @@ function resource_backup_one_mod($bf,$preferences,$resource) {
fwrite ($bf,full_tag("NAME",4,false,$resource->name));
fwrite ($bf,full_tag("TYPE",4,false,$resource->type));
fwrite ($bf,full_tag("REFERENCE",4,false,$resource->reference));
fwrite ($bf,full_tag("SUMMARY",4,false,$resource->summary));
fwrite ($bf,full_tag("SUMMARY",4,false,$resource->intro));
fwrite ($bf,full_tag("ALLTEXT",4,false,$resource->alltext));
fwrite ($bf,full_tag("POPUP",4,false,$resource->popup));
fwrite ($bf,full_tag("OPTIONS",4,false,$resource->options));
Expand Down
13 changes: 7 additions & 6 deletions mod/resource/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/resource/db" VERSION="20070120" COMMENT="XMLDB file for Moodle mod/resource"
<XMLDB PATH="mod/resource/db" VERSION="20090420" COMMENT="XMLDB file for Moodle mod/resource"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -10,19 +10,20 @@
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="type"/>
<FIELD NAME="type" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="reference"/>
<FIELD NAME="reference" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="type" NEXT="summary"/>
<FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="reference" NEXT="alltext"/>
<FIELD NAME="alltext" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="summary" NEXT="popup"/>
<FIELD NAME="reference" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="type" NEXT="intro"/>
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="reference" NEXT="introformat"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="intro" NEXT="alltext"/>
<FIELD NAME="alltext" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="introformat" NEXT="popup"/>
<FIELD NAME="popup" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="alltext" NEXT="options"/>
<FIELD NAME="options" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="popup" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="options"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
29 changes: 29 additions & 0 deletions mod/resource/db/upgrade.php
Expand Up @@ -28,6 +28,35 @@ function xmldb_resource_upgrade($oldversion) {

//===== 1.9.0 upgrade line ======//

if ($result && $oldversion < 2009042000) {

/// Rename field summary on table resource to intro
$table = new xmldb_table('resource');
$field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'reference');

/// Launch rename field summary
$dbman->rename_field($table, $field, 'intro');

/// resource savepoint reached
upgrade_mod_savepoint($result, 2009042000, 'resource');
}

if ($result && $oldversion < 2009042001) {

/// Define field introformat to be added to resource
$table = new xmldb_table('resource');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'intro');

/// Launch add field introformat
$dbman->add_field($table, $field);

/// set format to current
$DB->set_field('resource', 'introformat', FORMAT_MOODLE, array());

/// resource savepoint reached
upgrade_mod_savepoint($result, 2009042001, 'resource');
}

return $result;
}

Expand Down
5 changes: 3 additions & 2 deletions mod/resource/index.php
Expand Up @@ -48,6 +48,7 @@

$currentsection = "";
$options->para = false;
$options->noclean = true;
foreach ($resources as $resource) {
if ($course->format == "weeks" or $course->format == "topics") {
$printsection = "";
Expand All @@ -71,12 +72,12 @@
if (!$resource->visible) { // Show dimmed if the mod is hidden
$table->data[] = array ($printsection,
"<a class=\"dimmed\" $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
format_text($resource->summary, FORMAT_MOODLE, $options) );
format_text($resource->intro, $resource->introformat, $options) );

} else { //Show normal if the mod is visible
$table->data[] = array ($printsection,
"<a $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
format_text($resource->summary, FORMAT_MOODLE, $options) );
format_text($resource->intro, $resource->introformat, $options) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions mod/resource/mod_form.php
Expand Up @@ -38,9 +38,9 @@ function definition() {
}
$mform->addRule('name', null, 'required', null, 'client');

$mform->addElement('htmleditor', 'summary', get_string('summary'));
$mform->setType('summary', PARAM_RAW);
$mform->setHelpButton('summary', array('summary', get_string('summary'), 'resource'));
$mform->addElement('htmleditor', 'intro', get_string('summary'));
$mform->setType('intro', PARAM_RAW);
$mform->setHelpButton('intro', array('summary', get_string('summary'), 'resource'));
// summary should be optional again MDL-9485
//$mform->addRule('summary', get_string('required'), 'required', null, 'client');

Expand Down
8 changes: 4 additions & 4 deletions mod/resource/restorelib.php
Expand Up @@ -37,7 +37,7 @@ function resource_restore_mods($mod,$restore) {
$resource->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
$resource->type = $info['MOD']['#']['TYPE']['0']['#'];
$resource->reference = backup_todb($info['MOD']['#']['REFERENCE']['0']['#']);
$resource->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
$resource->intro = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
$resource->alltext = backup_todb($info['MOD']['#']['ALLTEXT']['0']['#']);
$resource->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
$resource->options = backup_todb($info['MOD']['#']['OPTIONS']['0']['#']);
Expand Down Expand Up @@ -203,14 +203,14 @@ function resource_decode_content_links_caller($restore) {
global $CFG, $DB;
$status = true;

if ($resources = $DB->get_records('resource', array('course'=>$restore->course_id), '', "id, alltext, summary, reference")) {
if ($resources = $DB->get_records('resource', array('course'=>$restore->course_id), '', "id, alltext, intro, reference")) {

$i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($resources as $resource) {
//Increment counter
$i++;
$content1 = $resource->alltext;
$content2 = $resource->summary;
$content2 = $resource->intro;
$content3 = $resource->reference;
$result1 = restore_decode_content_links_worker($content1,$restore);
$result2 = restore_decode_content_links_worker($content2,$restore);
Expand All @@ -219,7 +219,7 @@ function resource_decode_content_links_caller($restore) {
if ($result1 != $content1 || $result2 != $content2 || $result3 != $content3) {
//Update record
$resource->alltext = $result1;
$resource->summary = $result2;
$resource->intro = $result2;
$resource->reference = $result3;
$status = $DB->update_record("resource",$resource);
if (debugging()) {
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/type/directory/resource.class.php
Expand Up @@ -90,8 +90,8 @@ function display() {
navmenu($course, $cm));


if (trim(strip_tags($resource->summary))) {
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_spacer(10,10);
}

Expand Down
19 changes: 10 additions & 9 deletions mod/resource/type/file/resource.class.php
Expand Up @@ -364,8 +364,8 @@ function display() {
echo "\n-->\n";
echo '</script>';

if (trim(strip_tags($resource->summary))) {
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center");
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
}

$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" "
Expand Down Expand Up @@ -427,7 +427,7 @@ function display() {
function resizeEmbeddedHtml() {
//calculate new embedded html height size
';
if (!empty($resource->summary)) {
if (!empty($resource->intro)) {
echo' objectheight = YAHOO.util.Dom.getViewportHeight() - 230;
';
}
Expand All @@ -449,9 +449,9 @@ function resizeEmbeddedHtml() {
</script>
';

///print the summary
if (!empty($resource->summary)) {
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
///print the intro
if (!empty($resource->intro)) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
}
echo "</body></html>";
exit;
Expand Down Expand Up @@ -491,7 +491,8 @@ function resizeEmbeddedHtml() {

$options = new object();
$options->para = false;
echo '<div class="summary">'.format_text($resource->summary, FORMAT_HTML, $options).'</div>';
$options->noclean = true;
echo '<div class="summary">'.format_text($resource->intro, $resource->introformat, $options).'</div>';
if (!empty($localpath)) { // Show some help
echo '<div class="mdl-right helplink">';
link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
Expand Down Expand Up @@ -704,8 +705,8 @@ function resizeEmbeddedHtml() {
echo '</div>';
}

if (trim($resource->summary)) {
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
if (trim($resource->intro)) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
}

if ($inpopup) {
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/type/html/resource.class.php
Expand Up @@ -102,8 +102,8 @@ function display() {
echo "\n//]]>\n";
echo '</script>';

if (trim(strip_tags($resource->summary))) {
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center clearfix");
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
}

$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/type/ims/resource.class.php
Expand Up @@ -434,8 +434,8 @@ function display() {
echo "\n-->\n";
echo '</script>';

if (trim(strip_tags($resource->summary))) {
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center");
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
}

$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
Expand Down
6 changes: 3 additions & 3 deletions mod/resource/type/repository/resource.class.php
Expand Up @@ -313,9 +313,9 @@ function display() {
echo "\n-->\n";
echo '</script>';

if (trim(strip_tags($resource->summary))) {
if (trim(strip_tags($resource->intro))) {
$formatoptions->noclean = true;
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center");
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
}

$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
Expand Down Expand Up @@ -365,7 +365,7 @@ function display() {
print_header($pagetitle, $course->fullname, $navigation, "", "", true,
update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));

echo '<div class="summary">'.format_text($resource->summary, FORMAT_HTML, $formatoptions).'</div>';
echo '<div class="summary">'.format_text($resource->intro, $resource->introformat, $formatoptions).'</div>';
if (!empty($localpath)) { // Show some help
echo '<div class="mdl-right helplink">';
link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/type/text/resource.class.php
Expand Up @@ -100,8 +100,8 @@ function display() {
echo "\n//]]>\n";
echo '</script>';

if (trim(strip_tags($resource->summary))) {
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
}

$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/version.php
Expand Up @@ -5,8 +5,8 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////

$module->version = 2008081100;
$module->requires = 2008080701; // Requires this Moodle version
$module->version = 2009042001;
$module->requires = 2009041700; // Requires this Moodle version
$module->cron = 0;

?>

0 comments on commit 8b6c22a

Please sign in to comment.