Splitted scoes optional data in a new table

This commit is contained in:
bobopinna 2006-11-21 16:12:19 +00:00
parent 9c03bbaa04
commit b3659259fd
19 changed files with 633 additions and 378 deletions

View file

@ -23,14 +23,61 @@ function xmldb_scorm_upgrade($oldversion=0) {
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
if ($result && $oldversion < 2006103100) {
/// Create the new sco optionals data table
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
/// Define table scorm_scoes_data to be created
$table = new XMLDBTable('scorm_scoes_data');
/// Adding fields to table scorm_scoes_data
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table scorm_scoes_data
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table scorm_scoes_data
$table->addIndexInfo('scoid', XMLDB_INDEX_NOTUNIQUE, array('scoid'));
/// Launch create table for scorm_scoes_data
$result = $result && create_table($table);
/// The old fields used in scorm_scoes
$fields = array('parameters' => '',
'prerequisites' => '',
'maxtimeallowed' => '',
'timelimitaction' => '',
'datafromlms' => '',
'masteryscore' => '',
'next' => '0',
'previous' => '0');
/// Retrieve old datas
if ($olddatas = get_records('scorm_scoes')) {
foreach ($olddatas as $olddata) {
$newdata = new stdClass();
$newdata->scoid = $olddata->id;
foreach ($fields as $field => $value) {
if ($olddata->$field != $value) {
$newdata->name = addslashes($field);
$newdata->value = addslashes($olddata->$field);
$id = insert_record('scorm_scoes_data', $newdata);
$result = $result && ($id != 0);
}
}
}
}
/// Remove no more used fields
$table = new XMLDBTable('scorm_scoes');
foreach ($fields as $field => $value) {
$field = new XMLDBField($field);
$result = $result && drop_field($table, $field);
}
}
return $result;
}