MDL-48962 mod-lesson: maxtime should use a duration form element

This commit is contained in:
Jean-Michel Vedrine 2015-02-02 12:58:42 +01:00
parent dba564c7db
commit a1acc00177
13 changed files with 76 additions and 43 deletions

View file

@ -137,5 +137,45 @@ function xmldb_lesson_upgrade($oldversion) {
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2014122900, 'lesson');
}
if ($oldversion < 2015022400) {
// Creating new field timelimit in lesson table.
$table = new xmldb_table('lesson');
$field = new xmldb_field('timelimit', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'maxpages');
// Conditionally launch add field timelimit.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2015022400, 'lesson');
}
if ($oldversion < 2015022401) {
// Convert maxtime (minutes) to timelimit (seconds).
$table = new xmldb_table('lesson');
$oldfield = new xmldb_field('maxtime');
$newfield = new xmldb_field('timelimit');
if ($dbman->field_exists($table, $oldfield) && $dbman->field_exists($table, $newfield)) {
$sql = 'UPDATE {lesson} SET timelimit = 60 * maxtime';
$DB->execute($sql);
// Drop field maxtime.
$dbman->drop_field($table, $oldfield);
}
$oldfield = new xmldb_field('timed');
if ($dbman->field_exists($table, $oldfield) && $dbman->field_exists($table, $newfield)) {
// Set timelimit to 0 for non timed lessons.
$DB->set_field_select('lesson', 'timelimit', 0, 'timed = 0');
// Drop field timed.
$dbman->drop_field($table, $oldfield);
}
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2015022401, 'lesson');
}
return true;
}