/** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @global stdClass * @global object * @uses CONTEXT_MODULE * @uses SCORM_TYPE_LOCAL * @uses SCORM_TYPE_LOCALSYNC * @uses SCORM_TYPE_EXTERNAL * @param object $scorm Form data * @param object $mform * @return bool */ function scorm_update_instance($scorm, $mform=null) { global $CFG, $DB; require_once($CFG->dirroot.'/mod/scorm/locallib.php'); if (empty($scorm->timeopen)) { $scorm->timeopen = 0; } if (empty($scorm->timeclose)) { $scorm->timeclose = 0; } $cmid = $scorm->coursemodule; $cmidnumber = $scorm->cmidnumber; $courseid = $scorm->course; $scorm->id = $scorm->instance; $context = context_module::instance($cmid); if ($scorm->scormtype === SCORM_TYPE_LOCAL) { if (!empty($scorm->packagefile)) { $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_scorm', 'package'); file_save_draft_area_files($scorm->packagefile, $context->id, 'mod_scorm', 'package', 0, array('subdirs' => 0, 'maxfiles' => 1)); // Get filename of zip that was uploaded. $files = $fs->get_area_files($context->id, 'mod_scorm', 'package', 0, '', false); $file = reset($files); $filename = $file->get_filename(); if ($filename !== false) { $scorm->reference = $filename; } } } else if ($scorm->scormtype === SCORM_TYPE_LOCALSYNC) { $scorm->reference = $scorm->packageurl; } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) { $scorm->reference = $scorm->packageurl; } else if ($scorm->scormtype === SCORM_TYPE_AICCURL) { $scorm->reference = $scorm->packageurl; $scorm->hidetoc = SCORM_TOC_DISABLED; // TOC is useless for direct AICCURL so disable it. } else { return false; } $scorm = scorm_option2text($scorm); $scorm->width = (int)str_replace('%', '', $scorm->width); $scorm->height = (int)str_replace('%', '', $scorm->height); $scorm->timemodified = time(); if (!isset($scorm->whatgrade)) { $scorm->whatgrade = 0; } $DB->update_record('scorm', $scorm); $scorm = $DB->get_record('scorm', array('id' => $scorm->id)); // Extra fields required in grade related functions. $scorm->course = $courseid; $scorm->idnumber = $cmidnumber; $scorm->cmid = $cmid; scorm_parse($scorm, (bool)$scorm->updatefreq); scorm_grade_item_update($scorm); scorm_update_grades($scorm); return true; }
/** * Given an object containing all the necessary data, * (defined by the form in mod.html) this function * will update an existing instance with new data. * * @param mixed $scorm Form data * @return int */ function scorm_update_instance($scorm) { global $CFG; require_once 'locallib.php'; $scorm->parse = 0; if (($packagedata = scorm_check_package($scorm)) != null) { $scorm->pkgtype = $packagedata->pkgtype; if ($packagedata->launch == 0) { $scorm->launch = $packagedata->launch; $scorm->datadir = $packagedata->datadir; $scorm->parse = 1; if (!scorm_external_link($scorm->reference)) { $scorm->md5hash = md5_file($CFG->dataroot . '/' . $scorm->course . '/' . $scorm->reference); } else { $scorm->dir = $CFG->dataroot . '/' . $scorm->course . '/moddata/scorm'; $scorm->md5hash = md5_file($scorm->dir . $scorm->datadir . '/' . basename($scorm->reference)); } } } $scorm->timemodified = time(); $scorm->id = $scorm->instance; $scorm = scorm_option2text($scorm); $scorm->width = str_replace('%', '', $scorm->width); $scorm->height = str_replace('%', '', $scorm->height); if (!isset($scorm->whatgrade)) { $scorm->whatgrade = 0; } $scorm->grademethod = $scorm->whatgrade * 10 + $scorm->grademethod; // Check if scorm manifest needs to be reparsed if ($scorm->parse == 1) { $scorm->dir = $CFG->dataroot . '/' . $scorm->course . '/moddata/scorm'; if (is_dir($scorm->dir . '/' . $scorm->id)) { scorm_delete_files($scorm->dir . '/' . $scorm->id); } if (isset($scorm->datadir) && $scorm->datadir != $scorm->id && (scorm_external_link($scorm->reference) || basename($scorm->reference) != 'imsmanifest.xml' && $scorm->reference[0] != '#')) { rename($scorm->dir . $scorm->datadir, $scorm->dir . '/' . $scorm->id); } $scorm->launch = scorm_parse($scorm); } else { $oldscorm = get_record('scorm', 'id', $scorm->id); $scorm->reference = $oldscorm->reference; // This fix a problem with Firefox when the teacher choose Cancel on overwrite question } if ($result = update_record('scorm', $scorm)) { scorm_grade_item_update(stripslashes_recursive($scorm)); } return $result; }
/** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @global stdClass * @global object * @uses CONTEXT_MODULE * @uses SCORM_TYPE_LOCAL * @uses SCORM_TYPE_LOCALSYNC * @uses SCORM_TYPE_EXTERNAL * @uses SCORM_TYPE_IMSREPOSITORY * @param object $scorm Form data * @param object $mform * @return bool */ function scorm_update_instance($scorm, $mform = null) { global $CFG, $DB; require_once $CFG->dirroot . '/mod/scorm/locallib.php'; if (empty($scorm->timeopen)) { $scorm->timeopen = 0; } if (empty($scorm->timeclose)) { $scorm->timeclose = 0; } $cmid = $scorm->coursemodule; $cmidnumber = $scorm->cmidnumber; $courseid = $scorm->course; $scorm->id = $scorm->instance; $context = get_context_instance(CONTEXT_MODULE, $cmid); if ($scorm->scormtype === SCORM_TYPE_LOCAL) { if ($mform) { $filename = $mform->get_new_filename('packagefile'); if ($filename !== false) { $scorm->reference = $filename; $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_scorm', 'package'); $mform->save_stored_file('packagefile', $context->id, 'mod_scorm', 'package', 0, '/', $filename); } } } else { if ($scorm->scormtype === SCORM_TYPE_LOCALSYNC) { $scorm->reference = $scorm->packageurl; } else { if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) { $scorm->reference = $scorm->packageurl; } else { if ($scorm->scormtype === SCORM_TYPE_IMSREPOSITORY) { $scorm->reference = $scorm->packageurl; } else { return false; } } } } $scorm = scorm_option2text($scorm); $scorm->width = (int) str_replace('%', '', $scorm->width); $scorm->height = (int) str_replace('%', '', $scorm->height); $scorm->timemodified = time(); if (!isset($scorm->whatgrade)) { $scorm->whatgrade = 0; } $DB->update_record('scorm', $scorm); $scorm = $DB->get_record('scorm', array('id' => $scorm->id)); /// extra fields required in grade related functions $scorm->course = $courseid; $scorm->idnumber = $cmidnumber; $scorm->cmid = $cmid; scorm_parse($scorm, (bool) $scorm->updatefreq); scorm_grade_item_update($scorm); scorm_update_grades($scorm); return true; }