diff --git a/datamodels/tincanlib.php b/datamodels/tincanlib.php index 992eca8..ccedcea 100644 --- a/datamodels/tincanlib.php +++ b/datamodels/tincanlib.php @@ -96,7 +96,7 @@ function scorm_get_tincan_manifest($blocks, $scoes) { } break; case 'ACTIVITY': - if (empty($course_id) && isset($block['attrs']['TYPE']) && $block['attrs']['TYPE'] == 'course') { + if (empty($course_id) && isset($block['attrs']['TYPE']) && strpos($block['attrs']['TYPE'],'course') > 0) { $org = $parent = array_pop($parents); array_push($parents, $parent); diff --git a/db/install.xml b/db/install.xml index 1ebc2ec..a2cc22b 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,47 +1,47 @@ - - +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -50,171 +50,183 @@
- +
- - - - - - - - - + + + + + + + + + - - + +
- +
- - - - + + + + - - + +
- +
- - - - - - - - + + + + + + + + - - - + + + - - - + + +
- +
+ + + + + + + + + + + + + +
+ - - - - - - + + + + + + + + - - - + + + +
- +
- - - - - - - - + + + + + - - - - + + +
- +
- - - - - + + + + + + + - - - + + + +
- +
- - - - - - - + + + + + + + - - - - + + +
- +
- - - - - - - + + + + + - - - + + + +
- +
- - - - - + + + + + + + + + + + + - - - - + + +
- +
- - - - - - - - - - - - + + + + + - - - +
diff --git a/db/upgrade.php b/db/upgrade.php index faac4e1..04ee6df 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -80,6 +80,33 @@ function xmldb_scorm_upgrade($oldversion) { // Put any upgrade step following this + if ($oldversion < 2015101301) { + + // Define table scorm_scoes_item to be created. + $table = new xmldb_table('scorm_scoes_item'); + + // Adding fields to table scorm_scoes_item. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('scorm_scoes_track_id', XMLDB_TYPE_INTEGER, '10', null, null, null, null); + $table->add_field('field_id', XMLDB_TYPE_CHAR, '255', null, null, null, null); + $table->add_field('field_text', XMLDB_TYPE_CHAR, '255', null, null, null, null); + $table->add_field('field_value', XMLDB_TYPE_CHAR, '255', null, null, null, null); + + // Adding keys to table scorm_scoes_item. + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + // Conditionally launch create table for scorm_scoes_item. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Scorm savepoint reached. + upgrade_mod_savepoint(true, 2015101301, 'scorm'); + } + + + + return true; } diff --git a/locallib.php b/locallib.php index 993cd33..09f59bd 100644 --- a/locallib.php +++ b/locallib.php @@ -538,11 +538,12 @@ function scorm_insert_track($userid, $scormid, $scoid, $attempt, $element, $valu 'scoid' => $scoid, 'attempt' => $attempt, 'element' => $element))) { - if ($element != 'x.start.time' ) { // Don't update x.start.time - keep the original value. + if ($element != 'x.start.time' ) { // Don't update x.start.time - keep the original value $track->value = $value; $track->timemodified = time(); $DB->update_record('scorm_scoes_track', $track); $id = $track->id; + hlc_scoes_item($track, $value, $id); //HLC Change } } else { $track = new stdClass(); @@ -554,6 +555,7 @@ function scorm_insert_track($userid, $scormid, $scoid, $attempt, $element, $valu $track->value = $value; $track->timemodified = time(); $id = $DB->insert_record('scorm_scoes_track', $track); + hlc_scoes_item($track, $value, $id); //HLC Change } if (strstr($element, '.score.raw') || @@ -567,6 +569,55 @@ function scorm_insert_track($userid, $scormid, $scoid, $attempt, $element, $valu return $id; } +/* + * HLC Change + * When suspend data is sent back to the database its stored in a difficult way for dataforms to compute. + * Here we grab the suspend data, and put it into a neater system so dataforms can generate reports. + * Only certain data is sent each time theres a call to /activites and the TCAPI end point - so we will have multiple entries for each course + * + * Fun fact - the data isn't human readable http://en-uk.articulate.com/support/storyline/suspend-data-isnt-human-readable so this is why we have this crazy stuff going on below + * + * $track + * scorm_scoes_track data + * + * $value + * the value being sent to the database + * + * $track_id + * mdl_scorm_scoes_track id + */ +function hlc_scoes_item($track, $value, $track_id) { + global $DB; + + $data = json_decode($value); + $re = "/\\{(.*?)\\}/"; + preg_match_all($re, $data->data, $matches); + //$matches[1] is an array of strings matched by the first parenthesized subpattern, and so on. + $suspendData = array_unique($matches[1]); + foreach($suspendData as $sd) { + $sdItem = new stdClass(); + $dta = explode(':',$sd); + // Possible data formats (Ideally this would compile into proper json but were using it with dataforms!) + // t3011field1:January = label > text + // t3011field1:Low:4 = label > text > value + $sdItem->scorm_scoes_track_id = $track_id; + $sdItem->field_id = (isset($dta[0])) ? trim($dta[0]) : ''; + $sdItem->field_text = (isset($dta[1])) ? trim($dta[1]) : ''; + $sdItem->field_value = (isset($dta[2])) ? trim($dta[2]) : ''; + + + $items = $DB->get_record('scorm_scoes_item', array('scorm_scoes_track_id' => $track_id, 'field_id' => $sdItem->field_id)); + if($items) { + $sdItem->id = $items->id; + $id = $DB->update_record('scorm_scoes_item', $sdItem); + } + else { + $id = $DB->insert_record('scorm_scoes_item', $sdItem); + } + } + +} + /** * simple quick function to return true/false if this user has tracks in this scorm * diff --git a/report/interactions/version.php b/report/interactions/version.php index 9a89486..29fe02c 100644 --- a/report/interactions/version.php +++ b/report/interactions/version.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$module->version = 2015101301; // The current module version (Date: YYYYMMDDXX) defined('MOODLE_INTERNAL') || die(); $plugin->version = 2012112900; // The current plugin version (Date: YYYYMMDDXX)