feat: add intro fields to exp360 module

Added 'intro' and 'introformat' fields to the exp360 module for enhanced activity descriptions. Updated database schema and upgrade script to accommodate new fields. Modified add and update instance functions and the form to manage intro fields. Bumped module version to 2024070503.
This commit is contained in:
Kumi 2024-07-05 11:38:10 +02:00
parent 688e44ef2b
commit 3247092e59
Signed by: kumi
GPG key ID: ECBCC9082395383F
5 changed files with 52 additions and 6 deletions

View file

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/exp360/db" VERSION="2024070500" COMMENT="exp360 module"> <XMLDB PATH="mod/exp360/db" VERSION="2024070503" COMMENT="exp360 module description">
<TABLES> <TABLES>
<TABLE NAME="exp360" COMMENT="Table containing data on exp360 activities"> <TABLE NAME="exp360" COMMENT="Table for storing exp360 activity instances">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary key"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary key"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Course ID"/> <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Course ID"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Activity name"/> <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Activity name"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="false" COMMENT="Introduction text"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" COMMENT="Format of the intro field (e.g., HTML)"/>
<FIELD NAME="content_id" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Content ID"/> <FIELD NAME="content_id" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Content ID"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Last modified time"/> <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Last modified time"/>
</FIELDS> </FIELDS>

33
db/upgrade.php Normal file
View file

@ -0,0 +1,33 @@
<?php
defined('MOODLE_INTERNAL') || die();
function xmldb_exp360_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2024070503) {
// Define field intro to be added to exp360.
$table = new xmldb_table('exp360');
$field = new xmldb_field('intro', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name');
// Conditionally launch add field intro.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field introformat to be added to exp360.
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro');
// Conditionally launch add field introformat.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Exp360 savepoint reached.
upgrade_mod_savepoint(true, 2024070503, 'exp360');
}
return true;
}

View file

@ -9,6 +9,10 @@ function exp360_add_instance($exp360)
$exp360->timemodified = time(); $exp360->timemodified = time();
$exp360->timecreated = time(); $exp360->timecreated = time();
// Process standard intro fields.
$exp360->introformat = FORMAT_HTML;
$exp360->intro = '';
return $DB->insert_record('exp360', $exp360); return $DB->insert_record('exp360', $exp360);
} }
@ -19,6 +23,10 @@ function exp360_update_instance($exp360)
$exp360->timemodified = time(); $exp360->timemodified = time();
$exp360->id = $exp360->instance; $exp360->id = $exp360->instance;
// Process standard intro fields.
$exp360->introformat = FORMAT_HTML;
$exp360->intro = '';
return $DB->update_record('exp360', $exp360); return $DB->update_record('exp360', $exp360);
} }

View file

@ -2,8 +2,10 @@
require_once("$CFG->dirroot/course/moodleform_mod.php"); require_once("$CFG->dirroot/course/moodleform_mod.php");
class mod_exp360_mod_form extends moodleform_mod { class mod_exp360_mod_form extends moodleform_mod
public function definition() { {
public function definition()
{
$mform = $this->_form; $mform = $this->_form;
$mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('header', 'general', get_string('general', 'form'));
@ -13,6 +15,7 @@ class mod_exp360_mod_form extends moodleform_mod {
$mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', null, 'maxlength', 255, 'client'); $mform->addRule('name', null, 'maxlength', 255, 'client');
// Add the standard intro elements.
$this->standard_intro_elements(); $this->standard_intro_elements();
$mform->addElement('text', 'content_id', get_string('contentid', 'exp360'), array('size' => '64')); $mform->addElement('text', 'content_id', get_string('contentid', 'exp360'), array('size' => '64'));
@ -23,4 +26,4 @@ class mod_exp360_mod_form extends moodleform_mod {
$this->add_action_buttons(); $this->add_action_buttons();
} }
} }

View file

@ -2,6 +2,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024070502; // The current module version (Date: YYYYMMDDXX) $plugin->version = 2024070503; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2021051700; // Requires this Moodle version $plugin->requires = 2021051700; // Requires this Moodle version
$plugin->component = 'mod_exp360'; // Full name of the plugin (used for diagnostics) $plugin->component = 'mod_exp360'; // Full name of the plugin (used for diagnostics)