MDL-57759 mod_lesson: New settings for allowing offline attempts

This commit is contained in:
Juan Leyva 2017-01-24 17:06:28 +01:00
parent 79d5e88215
commit c6f9f06146
6 changed files with 49 additions and 4 deletions

View File

@ -77,7 +77,7 @@ class backup_lesson_activity_structure_step extends backup_activity_structure_st
'mediafile', 'mediaheight', 'mediawidth', 'mediaclose', 'slideshow',
'width', 'height', 'bgcolor', 'displayleft', 'displayleftif', 'progressbar',
'available', 'deadline', 'timemodified',
'completionendreached', 'completiontimespent'
'completionendreached', 'completiontimespent', 'allowofflineattempts'
));
// The lesson_pages table
@ -131,7 +131,7 @@ class backup_lesson_activity_structure_step extends backup_activity_structure_st
// Grouped by a `timers` element this is relational to the lesson and user.
$timers = new backup_nested_element('timers');
$timer = new backup_nested_element('timer', array('id'), array(
'userid', 'starttime', 'lessontime', 'completed'
'userid', 'starttime', 'lessontime', 'completed', 'timemodifiedoffline'
));
$overrides = new backup_nested_element('overrides');

View File

@ -47,6 +47,7 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="completionendreached" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="completiontimespent" TYPE="int" LENGTH="11" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="allowofflineattempts" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Whether to allow the lesson to be attempted offline in the mobile app"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@ -145,6 +146,7 @@
<FIELD NAME="starttime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="lessontime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="completed" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodifiedoffline" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Last modified time via web services (mobile app)."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>

View File

@ -390,5 +390,28 @@ function xmldb_lesson_upgrade($oldversion) {
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2016120515) {
// Define new fields to be added to lesson.
$table = new xmldb_table('lesson');
$field = new xmldb_field('allowofflineattempts', XMLDB_TYPE_INTEGER, '1', null, null, null, 0, 'completiontimespent');
// Conditionally launch add field allowofflineattempts.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2016120515, 'lesson');
}
if ($oldversion < 2016120516) {
// New field for lesson_timer.
$table = new xmldb_table('lesson_timer');
$field = new xmldb_field('timemodifiedoffline', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'completed');
// Conditionally launch add field timemodifiedoffline.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2016120516, 'lesson');
}
return true;
}

View File

@ -52,6 +52,10 @@ $string['addnewgroupoverride'] = 'Add group override';
$string['addnewuseroverride'] = 'Add user override';
$string['additionalattemptsremaining'] = 'Completed, You can re-attempt this lesson';
$string['addpage'] = 'Add a page';
$string['allowofflineattempts'] = 'Allow lesson to be attempted offline using the mobile app';
$string['allowofflineattempts_help'] = 'If enabled, a mobile app user can download the lesson and attempt it offline.
All the possible answers and correct responses will be downloaded as well.
Note: It is not possible for a lesson to be attempted offline if it has a time limit.';
$string['and'] = 'AND';
$string['anchortitle'] = 'Start of main content';
$string['answer'] = 'Answer';

View File

@ -49,7 +49,7 @@ class mod_lesson_mod_form extends moodleform_mod {
}
function definition() {
global $CFG, $COURSE, $DB;
global $CFG, $COURSE, $DB, $OUTPUT;
$mform = $this->_form;
@ -249,6 +249,22 @@ class mod_lesson_mod_form extends moodleform_mod {
'completed' => 0, 'gradebetterthan' => 0));
}
// Allow to enable offline lessons only if the Mobile services are enabled.
if ($CFG->enablemobilewebservice) {
$mform->addElement('selectyesno', 'allowofflineattempts', get_string('allowofflineattempts', 'lesson'));
$mform->addHelpButton('allowofflineattempts', 'allowofflineattempts', 'lesson');
$mform->setDefault('allowofflineattempts', 0);
$mform->setAdvanced('allowofflineattempts');
$mform->disabledIf('allowofflineattempts', 'timelimit[number]', 'neq', 0);
$mform->addElement('static', 'allowofflineattemptswarning', '',
$OUTPUT->notification(get_string('allowofflineattempts_help', 'lesson'), 'warning'));
$mform->setAdvanced('allowofflineattemptswarning');
} else {
$mform->addElement('hidden', 'allowofflineattempts', 0);
$mform->setType('allowofflineattempts', PARAM_INT);
}
// Flow control.
$mform->addElement('header', 'flowcontrol', get_string('flowcontrol', 'lesson'));

View File

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016120514; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2016120516; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2016112900; // Requires this Moodle version
$plugin->component = 'mod_lesson'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;