[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 'packagefilepath' => $CFG->dirroot.'/mod/scorm/tests/packages/singlescobasic.zip', 49 'packageurl' => '', 50 'updatefreq' => SCORM_UPDATE_NEVER, 51 'popup' => 0, 52 'width' => $cfgscorm->framewidth, 53 'height' => $cfgscorm->frameheight, 54 'skipview' => $cfgscorm->skipview, 55 'hidebrowse' => $cfgscorm->hidebrowse, 56 'displaycoursestructure' => $cfgscorm->displaycoursestructure, 57 'hidetoc' => $cfgscorm->hidetoc, 58 'nav' => $cfgscorm->nav, 59 'navpositionleft' => $cfgscorm->navpositionleft, 60 'navpositiontop' => $cfgscorm->navpositiontop, 61 'displayattemptstatus' => $cfgscorm->displayattemptstatus, 62 'timeopen' => 0, 63 'timeclose' => 0, 64 'grademethod' => GRADESCOES, 65 'maxgrade' => $cfgscorm->maxgrade, 66 'maxattempt' => $cfgscorm->maxattempt, 67 'whatgrade' => $cfgscorm->whatgrade, 68 'forcenewattempt' => $cfgscorm->forcenewattempt, 69 'lastattemptlock' => $cfgscorm->lastattemptlock, 70 'forcecompleted' => $cfgscorm->forcecompleted, 71 'masteryoverride' => $cfgscorm->masteryoverride, 72 'auto' => $cfgscorm->auto, 73 'displayactivityname' => $cfgscorm->displayactivityname 74 ); 75 76 // The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath. 77 if (empty($record['packagefile']) && $record['scormtype'] === SCORM_TYPE_LOCAL) { 78 if (!isloggedin() || isguestuser()) { 79 throw new coding_exception('Scorm generator requires a current user'); 80 } 81 if (!file_exists($record['packagefilepath'])) { 82 throw new coding_exception("File {$record['packagefilepath']} does not exist"); 83 } 84 $usercontext = context_user::instance($USER->id); 85 86 // Pick a random context id for specified user. 87 $record['packagefile'] = file_get_unused_draft_itemid(); 88 89 // Add actual file there. 90 $filerecord = array('component' => 'user', 'filearea' => 'draft', 91 'contextid' => $usercontext->id, 'itemid' => $record['packagefile'], 92 'filename' => basename($record['packagefilepath']), 'filepath' => '/'); 93 $fs = get_file_storage(); 94 $fs->create_file_from_pathname($filerecord, $record['packagefilepath']); 95 } 96 97 return parent::create_instance($record, (array)$options); 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |