MDL-24419 (4): Add conditional availability support to sections; section cache

Credit: original version done by Kirill Astashov of NetSpot (netspot.com.au),
finished and tweaked by sam.

This change adds conditional availability support for sections analagous to
that already available for activities. (Backend, UI, backup/restore.)

In order that this feature does not reduce performance, section cacheing has
also been added using a new course 'sectioncache' field analagous to modinfo.

The new feature integrates with activity availability so that activities
inside sections which are not available are automatically not available
themselves (meaning it works to restrict access).
This commit is contained in:
sam marshall
2012-05-14 11:19:25 +01:00
parent 637da99edb
commit ce4dfd2703
20 changed files with 1627 additions and 261 deletions
+68
View File
@@ -501,5 +501,73 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012050400.02);
}
if ($oldversion < 2012051100.01) {
// Amend course table to add sectioncache cache
$table = new xmldb_table('course');
$field = new xmldb_field('sectioncache', XMLDB_TYPE_TEXT, null, null, null, null, null, 'showgrades');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Amend course_sections to add date, time and groupingid availability
// conditions and a setting about whether to show them
$table = new xmldb_table('course_sections');
$field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', null,
XMLDB_NOTNULL, null, '0', 'visible');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', null,
XMLDB_NOTNULL, null, '0', 'availablefrom');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', null,
XMLDB_NOTNULL, null, '0', 'availableuntil');
// Conditionally launch add field showavailability
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('groupingid', XMLDB_TYPE_INTEGER, '10', null,
XMLDB_NOTNULL, null, '0', 'showavailability');
// Conditionally launch add field groupingid
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Add course_sections_availability to add completion & grade availability conditions
$table = new xmldb_table('course_sections_availability');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('coursesectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', null, null, null, null);
$table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
$table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('coursesectionid', XMLDB_KEY_FOREIGN,
array('coursesectionid'), 'course_sections', array('id'));
$table->add_key('sourcecmid', XMLDB_KEY_FOREIGN,
array('sourcecmid'), 'course_modules', array('id'));
$table->add_key('gradeitemid', XMLDB_KEY_FOREIGN,
array('gradeitemid'), 'grade_items', array('id'));
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Amend course table to add sectioncache
$table = new xmldb_table('course');
$field = new xmldb_field('sectioncache', XMLDB_TYPE_TEXT, null, null, null, null, null, 'showgrades');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2012051100.01);
}
return true;
}