Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       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              'auto' => $cfgscorm->auto,
      72              'displayactivityname' => $cfgscorm->displayactivityname
      73          );
      74  
      75          // The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath.
      76          if (empty($record['packagefile']) && $record['scormtype'] === SCORM_TYPE_LOCAL) {
      77              if (!isloggedin() || isguestuser()) {
      78                  throw new coding_exception('Scorm generator requires a current user');
      79              }
      80              if (!file_exists($record['packagefilepath'])) {
      81                  throw new coding_exception("File {$record['packagefilepath']} does not exist");
      82              }
      83              $usercontext = context_user::instance($USER->id);
      84  
      85              // Pick a random context id for specified user.
      86              $record['packagefile'] = file_get_unused_draft_itemid();
      87  
      88              // Add actual file there.
      89              $filerecord = array('component' => 'user', 'filearea' => 'draft',
      90                      'contextid' => $usercontext->id, 'itemid' => $record['packagefile'],
      91                      'filename' => basename($record['packagefilepath']), 'filepath' => '/');
      92              $fs = get_file_storage();
      93              $fs->create_file_from_pathname($filerecord, $record['packagefilepath']);
      94          }
      95  
      96          return parent::create_instance($record, (array)$options);
      97      }
      98  }
    

    Search This Site: