MDL-27001 'Show description' feature part 1: infrastructure that allows modules to support feature

The 'Show description' feature is about optionally including module description on the course page. This change include the necessary infrastructure - new database field, new FEATURE constant, changes to forms to display it, new language strings for it, backup and restore, and old course conversion. (I found the places to change by searching for an existing field in course_modules).

Documentation for the field is included in install.xml and in modinfolib.
This commit is contained in:
sam marshall 2011-07-20 17:24:55 +01:00
parent 9805fb9f17
commit 8c40662e22
12 changed files with 62 additions and 5 deletions

View File

@ -800,6 +800,7 @@ class moodle1_course_outline_handler extends moodle1_xml_handler {
'showavailability' => 0,
'availability_info' => array(),
'visibleold' => 1,
'showdescription' => 0,
),
'dropfields' => array(
'instance',

View File

@ -310,7 +310,7 @@ class backup_module_structure_step extends backup_structure_step {
'added', 'score', 'indent', 'visible',
'visibleold', 'groupmode', 'groupingid', 'groupmembersonly',
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
'availablefrom', 'availableuntil', 'showavailability'));
'availablefrom', 'availableuntil', 'showavailability', 'showdescription'));
$availinfo = new backup_nested_element('availability_info');
$availability = new backup_nested_element('availability', array('id'), array(

View File

@ -2164,6 +2164,12 @@ class restore_module_structure_step extends restore_structure_step {
$data->availablefrom = $this->apply_date_offset($data->availablefrom);
$data->availableuntil= $this->apply_date_offset($data->availableuntil);
}
// Backups that did not include showdescription, set it to default 0
// (this is not totally necessary as it has a db default, but just to
// be explicit).
if (!isset($data->showdescription)) {
$data->showdescription = 0;
}
$data->instance = 0; // Set to 0 for now, going to create it soon (next step)
// course_module record ready, insert it

View File

@ -1106,6 +1106,7 @@ function get_array_of_activities($courseid) {
$mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom;
$mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil;
$mod[$seq]->showavailability = $rawmods[$seq]->showavailability;
$mod[$seq]->showdescription = $rawmods[$seq]->showdescription;
if (!empty($CFG->enableavailability)) {
condition_info::fill_availability_conditions($rawmods[$seq]);
$mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion;
@ -1162,11 +1163,12 @@ function get_array_of_activities($courseid) {
// Minimise the database size by unsetting default options when they are
// 'empty'. This list corresponds to code in the cm_info constructor.
foreach(array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly',
foreach (array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly',
'indent', 'completion', 'extra', 'extraclasses', 'onclick', 'content',
'icon', 'iconcomponent', 'customdata', 'showavailability', 'availablefrom',
'availableuntil', 'conditionscompletion', 'conditionsgrade',
'completionview', 'completionexpected', 'score') as $property) {
'completionview', 'completionexpected', 'score', 'showdescription')
as $property) {
if (property_exists($mod[$seq], $property) &&
empty($mod[$seq]->{$property})) {
unset($mod[$seq]->{$property});

View File

@ -135,6 +135,7 @@ if (!empty($add)) {
$data->completionview = $cm->completionview;
$data->completionexpected = $cm->completionexpected;
$data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1;
$data->showdescription = $cm->showdescription;
if (!empty($CFG->enableavailability)) {
$data->availablefrom = $cm->availablefrom;
$data->availableuntil = $cm->availableuntil;
@ -310,6 +311,11 @@ if ($mform->is_cancelled()) {
$cm->showavailability = $fromform->showavailability;
condition_info::update_cm_from_form($cm,$fromform,true);
}
if (isset($fromform->showdescription)) {
$cm->showdescription = $fromform->showdescription;
} else {
$cm->showdescription = 0;
}
$DB->update_record('course_modules', $cm);
@ -395,6 +401,11 @@ if ($mform->is_cancelled()) {
}
$newcm->showavailability = $fromform->showavailability;
}
if (isset($fromform->showdescription)) {
$newcm->showdescription = $fromform->showdescription;
} else {
$newcm->showdescription = 0;
}
if (!$fromform->coursemodule = add_course_module($newcm)) {
print_error('cannotaddcoursemodule');

View File

@ -84,6 +84,7 @@ abstract class moodleform_mod extends moodleform {
$this->_features->introeditor = plugin_supports('mod', $this->_modname, FEATURE_MOD_INTRO, true);
$this->_features->defaultcompletion = plugin_supports('mod', $this->_modname, FEATURE_MODEDIT_DEFAULT_COMPLETION, true);
$this->_features->rating = plugin_supports('mod', $this->_modname, FEATURE_RATE, false);
$this->_features->showdescription = plugin_supports('mod', $this->_modname, FEATURE_SHOW_DESCRIPTION, false);
$this->_features->gradecat = ($this->_features->outcomes or $this->_features->hasgrades);
}
@ -674,6 +675,13 @@ abstract class moodleform_mod extends moodleform {
if ($required) {
$mform->addRule('introeditor', get_string('required'), 'required', null, 'client');
}
// If the 'show description' feature is enabled, this checkbox appears
// below the intro.
if ($this->_features->showdescription) {
$mform->addElement('checkbox', 'showdescription', get_string('showdescription'));
$mform->addHelpButton('showdescription', 'showdescription');
}
}
/**

View File

@ -1487,6 +1487,8 @@ $string['showallweeks'] = 'Show all weeks';
$string['showblockcourse'] = 'Show list of courses containing block';
$string['showcomments'] = 'Show/hide comments';
$string['showcommentsnonjs'] = 'Show comments';
$string['showdescription'] = 'Display description on course page';
$string['showdescription_help'] = 'If enabled, the introduction / description above will be displayed on the course page just below the link to the activity / resource.';
$string['showgrades'] = 'Show gradebook to students';
$string['showgrades_help'] = 'Many activities in the course allow grades to be set. This setting determines whether a student can view a list of all their grades for the course via a grades link in the course administration block.';
$string['showlistofcourses'] = 'Show list of courses';

View File

@ -323,7 +323,8 @@
<FIELD NAME="completionexpected" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Date at which students are expected to complete this activity. This field is used when displaying student progress." PREVIOUS="completionview" NEXT="availablefrom"/>
<FIELD NAME="availablefrom" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set non-zero, the activity only becomes available from the time given here." PREVIOUS="completionexpected" NEXT="availableuntil"/>
<FIELD NAME="availableuntil" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set non-zero, the activity is only available until the time given here." PREVIOUS="availablefrom" NEXT="showavailability"/>
<FIELD NAME="showavailability" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1 and the activity is not available because the 'availablefrom' date has not been reached, or one of the conditions in course_modules_availability is not matched, then the item will be displayed greyed-out (unclickable) with an information message such as 'Available from (date)'. Otherwise, the item will not be displayed to students at all." PREVIOUS="availableuntil"/>
<FIELD NAME="showavailability" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1 and the activity is not available because the 'availablefrom' date has not been reached, or one of the conditions in course_modules_availability is not matched, then the item will be displayed greyed-out (unclickable) with an information message such as 'Available from (date)'. Otherwise, the item will not be displayed to students at all." PREVIOUS="availableuntil" NEXT="showdescription"/>
<FIELD NAME="showdescription" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Some module types support a 'description' which shows within the module pages. This option controls whether it also displays on the course main page. 0 = does not display (default), 1 = displays" PREVIOUS="showavailability"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="groupingid"/>

View File

@ -6675,6 +6675,20 @@ FROM
upgrade_main_savepoint(true, 2011081700.02);
}
if ($oldversion < 2011083100.01) {
// Define field showdescription to be added to course_modules
$table = new xmldb_table('course_modules');
$field = new xmldb_field('showdescription', XMLDB_TYPE_INTEGER, '1',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'showavailability');
// Conditionally launch add field showdescription
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2011083100.01);
}
return true;
}

View File

@ -445,6 +445,14 @@ class cm_info extends stdClass {
*/
public $showavailability;
/**
* Controls whether the description of the activity displays on the course main page (in
* addition to anywhere it might display within the activity itself). 0 = do not show
* on main page, 1 = show on main page.
* @var int
*/
public $showdescription;
/**
* Extra HTML that is put in an unhelpful part of the HTML when displaying this module in
* course page - from cached data in modinfo field
@ -854,6 +862,7 @@ class cm_info extends stdClass {
$this->iconcomponent = isset($mod->iconcomponent) ? $mod->iconcomponent : '';
$this->customdata = isset($mod->customdata) ? $mod->customdata : '';
$this->context = get_context_instance(CONTEXT_MODULE, $mod->cm);
$this->showdescription = isset($mod->showdescription) ? $mod->showdescription : 0;
$this->state = self::STATE_BASIC;
// This special case handles old label data. Labels used to use the 'name' field for

View File

@ -383,6 +383,9 @@ define('FEATURE_RATE', 'rate');
/** True if module supports backup/restore of moodle2 format */
define('FEATURE_BACKUP_MOODLE2', 'backup_moodle2');
/** True if module can show description on course main page */
define('FEATURE_SHOW_DESCRIPTION', 'showdescription');
/** Unspecified module archetype */
define('MOD_ARCHETYPE_OTHER', 0);
/** Resource-like type module */

View File

@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
$version = 2011083100.00; // YYYYMMDD = weekly release date of this DEV branch
$version = 2011083100.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes