Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * mod_scorm data generator. 19 * 20 * @package mod_scorm 21 * @category test 22 * @copyright 2013 Marina Glancy 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * mod_scorm data generator class. 30 * 31 * @package mod_scorm 32 * @category test 33 * @copyright 2013 Marina Glancy 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class mod_scorm_generator extends testing_module_generator { 37 38 public function create_instance($record = null, array $options = null) { 39 global $CFG, $USER; 40 require_once($CFG->dirroot.'/mod/scorm/lib.php'); 41 require_once($CFG->dirroot.'/mod/scorm/locallib.php'); 42 $cfgscorm = get_config('scorm'); 43 44 // Add default values for scorm. 45 $record = (array)$record + array( 46 'scormtype' => SCORM_TYPE_LOCAL, 47 'packagefile' => '', 48 'packageurl' => '', 49 'updatefreq' => SCORM_UPDATE_NEVER, 50 'popup' => 0, 51 'width' => $cfgscorm->framewidth, 52 'height' => $cfgscorm->frameheight, 53 'skipview' => $cfgscorm->skipview, 54 'hidebrowse' => $cfgscorm->hidebrowse, 55 'displaycoursestructure' => $cfgscorm->displaycoursestructure, 56 'hidetoc' => $cfgscorm->hidetoc, 57 'nav' => $cfgscorm->nav, 58 'navpositionleft' => $cfgscorm->navpositionleft, 59 'navpositiontop' => $cfgscorm->navpositiontop, 60 'displayattemptstatus' => $cfgscorm->displayattemptstatus, 61 'timeopen' => 0, 62 'timeclose' => 0, 63 'grademethod' => GRADESCOES, 64 'maxgrade' => $cfgscorm->maxgrade, 65 'maxattempt' => $cfgscorm->maxattempt, 66 'whatgrade' => $cfgscorm->whatgrade, 67 'forcenewattempt' => $cfgscorm->forcenewattempt, 68 'lastattemptlock' => $cfgscorm->lastattemptlock, 69 'forcecompleted' => $cfgscorm->forcecompleted, 70 'masteryoverride' => $cfgscorm->masteryoverride, 71 'auto' => $cfgscorm->auto, 72 'displayactivityname' => $cfgscorm->displayactivityname 73 ); 74 if (empty($record['packagefilepath'])) { 75 $record['packagefilepath'] = $CFG->dirroot.'/mod/scorm/tests/packages/singlescobasic.zip'; 76 } 77 if (strpos($record['packagefilepath'], $CFG->dirroot) !== 0) { 78 $record['packagefilepath'] = "{$CFG->dirroot}/{$record['packagefilepath']}"; 79 } 80 81 // The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath. 82 if (empty($record['packagefile']) && $record['scormtype'] === SCORM_TYPE_LOCAL) { 83 if (!isloggedin() || isguestuser()) { 84 throw new coding_exception('Scorm generator requires a current user'); 85 } 86 if (!file_exists($record['packagefilepath'])) { 87 throw new coding_exception("File {$record['packagefilepath']} does not exist"); 88 } 89 $usercontext = context_user::instance($USER->id); 90 91 // Pick a random context id for specified user. 92 $record['packagefile'] = file_get_unused_draft_itemid(); 93 94 // Add actual file there. 95 $filerecord = array('component' => 'user', 'filearea' => 'draft', 96 'contextid' => $usercontext->id, 'itemid' => $record['packagefile'], 97 'filename' => basename($record['packagefilepath']), 'filepath' => '/'); 98 $fs = get_file_storage(); 99 $fs->create_file_from_pathname($filerecord, $record['packagefilepath']); 100 } 101 102 return parent::create_instance($record, (array)$options); 103 } 104 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body