first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+178
View File
@@ -0,0 +1,178 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides support for the conversion of moodle1 backup to the moodle2 format
*
* @package mod_scorm
* @copyright 2011 Aparup Banerjee <nebgor@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Scorm conversion handler
*/
class moodle1_mod_scorm_handler extends moodle1_mod_handler {
/** @var moodle1_file_manager */
protected $fileman = null;
/** @var int cmid */
protected $moduleid = null;
/**
* Declare the paths in moodle.xml we are able to convert
*
* The method returns list of {@link convert_path} instances.
* For each path returned, the corresponding conversion method must be
* defined.
*
* Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM does not
* actually exist in the file. The last element with the module name was
* appended by the moodle1_converter class.
*
* @return array of {@link convert_path} instances
*/
public function get_paths() {
return array(
new convert_path('scorm', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM',
array(
'newfields' => array(
'whatgrade' => 0,
'scormtype' => 'local',
'sha1hash' => null,
'revision' => '0',
'forcecompleted' => 0,
'forcenewattempt' => 0,
'lastattemptlock' => 0,
'masteryoverride' => 1,
'displayattemptstatus' => 1,
'displaycoursestructure' => 0,
'timeopen' => '0',
'timeclose' => '0',
'introformat' => '0',
'completionstatusallscos' => 0,
),
'renamefields' => array(
'summary' => 'intro'
)
)
),
new convert_path('scorm_sco', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM/SCOES/SCO')
);
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM
* data available
*/
public function process_scorm($data) {
global $CFG;
// get the course module id and context id
$instanceid = $data['id'];
$currentcminfo = $this->get_cminfo($instanceid);
$this->moduleid = $currentcminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// check 1.9 version where backup was created
$backupinfo = $this->converter->get_stash('backup_info');
if ($backupinfo['moodle_version'] < 2007110503) {
// as we have no module version data, assume $currmodule->version <= $module->version
// - fix data as the source 1.9 build hadn't yet at time of backing up.
$data['grademethod'] = $data['grademethod']%10;
}
// update scormtype (logic is consistent as done in scorm/db/upgrade.php)
$ismanifest = preg_match('/imsmanifest\.xml$/', $data['reference']);
$iszippif = preg_match('/.(zip|pif)$/', $data['reference']);
$isurl = preg_match('/^((http|https):\/\/|www\.)/', $data['reference']);
if ($isurl) {
if ($ismanifest) {
$data['scormtype'] = 'external';
} else if ($iszippif) {
$data['scormtype'] = 'localtype';
}
}
// migrate scorm package file
$this->fileman->filearea = 'package';
$this->fileman->itemid = 0;
$this->fileman->migrate_file('course_files/'.$data['reference']);
// start writing scorm.xml
$this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
'modulename' => 'scorm', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('scorm', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field <> 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
$this->xmlwriter->begin_tag('scoes');
return $data;
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM/SCOES/SCO
* data available
*/
public function process_scorm_sco($data) {
$this->write_xml('sco', $data, array('/sco/id'));
}
/**
* This is executed when we reach the closing </MOD> tag of our 'scorm' path
*/
public function on_scorm_end() {
// close scorm.xml
$this->xmlwriter->end_tag('scoes');
$this->xmlwriter->end_tag('scorm');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml
$this->open_xml_writer("activities/scorm_{$this->moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($this->fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
}
}
@@ -0,0 +1,69 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines backup_scorm_activity_task class
*
* @package mod_scorm
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/scorm/backup/moodle2/backup_scorm_stepslib.php');
/**
* Provides the steps to perform one complete backup of the SCORM instance
*/
class backup_scorm_activity_task extends backup_activity_task {
/**
* No specific settings for this activity
*/
protected function define_my_settings() {
}
/**
* Defines a backup step to store the instance data in the scorm.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_scorm_activity_structure_step('scorm_structure', 'scorm.xml'));
}
/**
* Encodes URLs to the index.php and view.php scripts
*
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
* @return string the content with the URLs encoded
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot, "/");
// Link to the list of scorms
$search="/(".$base."\/mod\/scorm\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@SCORMINDEX*$2@$', $content);
// Link to scorm view by moduleid
$search="/(".$base."\/mod\/scorm\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@SCORMVIEWBYID*$2@$', $content);
return $content;
}
}
@@ -0,0 +1,163 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_scorm
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the backup steps that will be used by the backup_scorm_activity_task
*/
/**
* Define the complete scorm structure for backup, with file and id annotations
*/
class backup_scorm_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
$scorm = new backup_nested_element('scorm', array('id'), array(
'name', 'scormtype', 'reference', 'intro',
'introformat', 'version', 'maxgrade', 'grademethod',
'whatgrade', 'maxattempt', 'forcecompleted', 'forcenewattempt',
'lastattemptlock', 'masteryoverride', 'displayattemptstatus', 'displaycoursestructure', 'updatefreq',
'sha1hash', 'md5hash', 'revision', 'launch',
'skipview', 'hidebrowse', 'hidetoc', 'nav', 'navpositionleft', 'navpositiontop',
'auto', 'popup', 'options', 'width',
'height', 'timeopen', 'timeclose', 'timemodified',
'completionstatusrequired', 'completionscorerequired',
'completionstatusallscos',
'autocommit'));
$scoes = new backup_nested_element('scoes');
$sco = new backup_nested_element('sco', array('id'), array(
'manifest', 'organization', 'parent', 'identifier',
'launch', 'scormtype', 'title', 'sortorder'));
$scodatas = new backup_nested_element('sco_datas');
$scodata = new backup_nested_element('sco_data', array('id'), array(
'name', 'value'));
$seqruleconds = new backup_nested_element('seq_ruleconds');
$seqrulecond = new backup_nested_element('seq_rulecond', array('id'), array(
'conditioncombination', 'ruletype', 'action'));
$seqrulecondsdatas = new backup_nested_element('seq_rulecond_datas');
$seqrulecondsdata = new backup_nested_element('seq_rulecond_data', array('id'), array(
'refrencedobjective', 'measurethreshold', 'operator', 'cond'));
$seqrolluprules = new backup_nested_element('seq_rolluprules');
$seqrolluprule = new backup_nested_element('seq_rolluprule', array('id'), array(
'childactivityset', 'minimumcount', 'minimumpercent', 'conditioncombination',
'action'));
$seqrollupruleconds = new backup_nested_element('seq_rollupruleconds');
$seqrolluprulecond = new backup_nested_element('seq_rolluprulecond', array('id'), array(
'cond', 'operator'));
$seqobjectives = new backup_nested_element('seq_objectives');
$seqobjective = new backup_nested_element('seq_objective', array('id'), array(
'primaryobj', 'objectiveid', 'satisfiedbymeasure', 'minnormalizedmeasure'));
$seqmapinfos = new backup_nested_element('seq_mapinfos');
$seqmapinfo = new backup_nested_element('seq_mapinfo', array('id'), array(
'targetobjectiveid', 'readsatisfiedstatus', 'readnormalizedmeasure', 'writesatisfiedstatus',
'writenormalizedmeasure'));
$scotracks = new backup_nested_element('sco_tracks');
$scotrack = new backup_nested_element('sco_track', array('id'), array(
'userid', 'attempt', 'element', 'value',
'timemodified'));
// Build the tree
$scorm->add_child($scoes);
$scoes->add_child($sco);
$sco->add_child($scodatas);
$scodatas->add_child($scodata);
$sco->add_child($seqruleconds);
$seqruleconds->add_child($seqrulecond);
$seqrulecond->add_child($seqrulecondsdatas);
$seqrulecondsdatas->add_child($seqrulecondsdata);
$sco->add_child($seqrolluprules);
$seqrolluprules->add_child($seqrolluprule);
$seqrolluprule->add_child($seqrollupruleconds);
$seqrollupruleconds->add_child($seqrolluprulecond);
$sco->add_child($seqobjectives);
$seqobjectives->add_child($seqobjective);
$seqobjective->add_child($seqmapinfos);
$seqmapinfos->add_child($seqmapinfo);
$sco->add_child($scotracks);
$scotracks->add_child($scotrack);
// Define sources
$scorm->set_source_table('scorm', array('id' => backup::VAR_ACTIVITYID));
// Order is important for several SCORM calls (especially scorm_scoes) in the following calls to set_source_table
$sco->set_source_table('scorm_scoes', array('scorm' => backup::VAR_PARENTID), 'sortorder, id');
$scodata->set_source_table('scorm_scoes_data', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$seqrulecond->set_source_table('scorm_seq_ruleconds', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$seqrulecondsdata->set_source_table('scorm_seq_rulecond', array('ruleconditionsid' => backup::VAR_PARENTID), 'id ASC');
$seqrolluprule->set_source_table('scorm_seq_rolluprule', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$seqrolluprulecond->set_source_table('scorm_seq_rolluprulecond', array('rollupruleid' => backup::VAR_PARENTID), 'id ASC');
$seqobjective->set_source_table('scorm_seq_objective', array('scoid' => backup::VAR_PARENTID), 'id ASC');
$seqmapinfo->set_source_table('scorm_seq_mapinfo', array('objectiveid' => backup::VAR_PARENTID), 'id ASC');
// All the rest of elements only happen if we are including user info
if ($userinfo) {
$sql = 'SELECT v.id, a.userid, a.attempt, e.element, v.value, v.timemodified
FROM {scorm_attempt} a
JOIN {scorm_scoes_value} v ON v.attemptid = a.id
JOIN {scorm_element} e ON e.id = v.elementid
WHERE v.scoid = :scoid';
$scotrack->set_source_sql($sql, ['scoid' => backup::VAR_PARENTID], 'id ASC');
}
// Define id annotations
$scotrack->annotate_ids('user', 'userid');
// Define file annotations
$scorm->annotate_files('mod_scorm', 'intro', null); // This file area hasn't itemid
$scorm->annotate_files('mod_scorm', 'content', null); // This file area hasn't itemid
$scorm->annotate_files('mod_scorm', 'package', null); // This file area hasn't itemid
// Return the root element (scorm), wrapped into standard activity structure
return $this->prepare_activity_structure($scorm);
}
}
@@ -0,0 +1,112 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_scorm
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/scorm/backup/moodle2/restore_scorm_stepslib.php'); // Because it exists (must)
/**
* scorm restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_scorm_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// scorm only has one structure step
$this->add_step(new restore_scorm_activity_structure_step('scorm_structure', 'scorm.xml'));
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('scorm', array('intro'), 'scorm');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('SCORMVIEWBYID', '/mod/scorm/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('SCORMINDEX', '/mod/scorm/index.php?id=$1', 'course');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* scorm logs. It must return one array
* of {@link restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('scorm', 'add', 'view.php?id={course_module}', '{scorm}');
$rules[] = new restore_log_rule('scorm', 'update', 'view.php?id={course_module}', '{scorm}');
$rules[] = new restore_log_rule('scorm', 'view', 'player.php?cm={course_module}&scoid={scorm_sco}', '{scorm}');
$rules[] = new restore_log_rule('scorm', 'pre-view', 'view.php?id={course_module}', '{scorm}');
$rules[] = new restore_log_rule('scorm', 'report', 'report.php?id={course_module}', '{scorm}');
$rules[] = new restore_log_rule('scorm', 'launch', 'view.php?id={course_module}', '[result]');
$rules[] = new restore_log_rule('scorm', 'delete attempts', 'report.php?id={course_module}', '[oldattempts]');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link restore_log_rule} objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules[] = new restore_log_rule('scorm', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,227 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_scorm
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that will be used by the restore_scorm_activity_task
*/
/**
* Structure step to restore one scorm activity
*/
class restore_scorm_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$userinfo = $this->get_setting_value('userinfo');
$paths[] = new restore_path_element('scorm', '/activity/scorm');
$paths[] = new restore_path_element('scorm_sco', '/activity/scorm/scoes/sco');
$paths[] = new restore_path_element('scorm_sco_data', '/activity/scorm/scoes/sco/sco_datas/sco_data');
$paths[] = new restore_path_element('scorm_seq_objective', '/activity/scorm/scoes/sco/seq_objectives/seq_objective');
$paths[] = new restore_path_element('scorm_seq_rolluprule', '/activity/scorm/scoes/sco/seq_rolluprules/seq_rolluprule');
$paths[] = new restore_path_element('scorm_seq_rolluprulecond', '/activity/scorm/scoes/sco/seq_rollupruleconds/seq_rolluprulecond');
$paths[] = new restore_path_element('scorm_seq_rulecond', '/activity/scorm/scoes/sco/seq_ruleconds/seq_rulecond');
$paths[] = new restore_path_element('scorm_seq_rulecond_data', '/activity/scorm/scoes/sco/seq_rulecond_datas/seq_rulecond_data');
$paths[] = new restore_path_element('scorm_seq_mapinfo', '/activity/scorm/scoes/sco/seq_objectives/seq_objective/seq_mapinfos/seq_mapinfo');
if ($userinfo) {
$paths[] = new restore_path_element('scorm_sco_track', '/activity/scorm/scoes/sco/sco_tracks/sco_track');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_scorm($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
$data->timeopen = $this->apply_date_offset($data->timeopen);
$data->timeclose = $this->apply_date_offset($data->timeclose);
if (!isset($data->completionstatusallscos)) {
$data->completionstatusallscos = false;
}
// insert the scorm record
$newitemid = $DB->insert_record('scorm', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
protected function process_scorm_sco($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scorm = $this->get_new_parentid('scorm');
$newitemid = $DB->insert_record('scorm_scoes', $data);
$this->set_mapping('scorm_sco', $oldid, $newitemid);
}
protected function process_scorm_sco_data($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_sco');
$newitemid = $DB->insert_record('scorm_scoes_data', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_seq_objective($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_sco');
$newitemid = $DB->insert_record('scorm_seq_objective', $data);
$this->set_mapping('scorm_seq_objective', $oldid, $newitemid);
}
protected function process_scorm_seq_rolluprule($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_sco');
$newitemid = $DB->insert_record('scorm_seq_rolluprule', $data);
$this->set_mapping('scorm_seq_rolluprule', $oldid, $newitemid);
}
protected function process_scorm_seq_rolluprulecond($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_sco');
$data->ruleconditions = $this->get_new_parentid('scorm_seq_rolluprule');
$newitemid = $DB->insert_record('scorm_seq_rolluprulecond', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_seq_rulecond($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_sco');
$newitemid = $DB->insert_record('scorm_seq_ruleconds', $data);
$this->set_mapping('scorm_seq_ruleconds', $oldid, $newitemid);
}
protected function process_scorm_seq_rulecond_data($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_sco');
$data->ruleconditions = $this->get_new_parentid('scorm_seq_ruleconds');
$newitemid = $DB->insert_record('scorm_seq_rulecond', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_seq_mapinfo($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_sco');
$data->objectiveid = $this->get_new_parentid('scorm_seq_objective');
$newitemid = $DB->insert_record('scorm_scoes_data', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_sco_track($data) {
global $DB, $CFG;
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
$data = (object)$data;
$attemptobject = scorm_get_attempt($this->get_mappingid('user', $data->userid),
$this->get_new_parentid('scorm'),
$data->attempt);
$data->scoid = $this->get_new_parentid('scorm_sco');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->attemptid = $attemptobject->id;
$data->elementid = scorm_get_elementid($data->element);
$DB->insert_record('scorm_scoes_value', $data);
// No need to save this mapping as far as nothing depend on it.
}
protected function after_execute() {
global $DB;
// Add scorm related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_scorm', 'intro', null);
$this->add_related_files('mod_scorm', 'content', null);
$this->add_related_files('mod_scorm', 'package', null);
// Fix launch param in scorm table to use new sco id.
$scormid = $this->get_new_parentid('scorm');
$scorm = $DB->get_record('scorm', array('id' => $scormid));
$scorm->launch = $this->get_mappingid('scorm_sco', $scorm->launch, '');
if (!empty($scorm->launch)) {
// Check that this sco has a valid launch value.
$scolaunch = $DB->get_field('scorm_scoes', 'launch', array('id' => $scorm->launch));
if (empty($scolaunch)) {
// This is not a valid sco - set to empty so we can find a valid launch sco.
$scorm->launch = '';
}
}
if (empty($scorm->launch)) {
// This scorm has an invalid launch param - we need to calculate it and get the first launchable sco.
$sqlselect = 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true);
// We use get_records here as we need to pass a limit in the query that works cross db.
$scoes = $DB->get_records_select('scorm_scoes', $sqlselect, array($scormid), 'sortorder', 'id', 0, 1);
if (!empty($scoes)) {
$sco = reset($scoes); // We only care about the first record - the above query only returns one.
$scorm->launch = $sco->id;
}
}
if (!empty($scorm->launch)) {
$DB->update_record('scorm', $scorm);
}
}
}