Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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   * @package    backup-convert
  19   * @subpackage cc-library
  20   * @copyright  2012 Darko Miletic <dmiletic@moodlerooms.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  require_once ('cc_converters.php');
  25  require_once ('cc_general.php');
  26  require_once ('cc_asssesment.php');
  27  require_once ('cc_assesment_truefalse.php');
  28  require_once ('cc_assesment_essay.php');
  29  require_once ('cc_assesment_sfib.php');
  30  
  31  class cc_converter_quiz extends cc_converter {
  32  
  33      public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path) {
  34          $this->cc_type     = cc_version11::assessment;
  35          $this->defaultfile = 'quiz.xml';
  36          $this->defaultname = assesment11_resurce_file::deafultname;
  37          parent::__construct($item, $manifest, $rootpath, $path);
  38      }
  39  
  40      public function convert($outdir) {
  41          $rt = new assesment11_resurce_file();
  42          $title = $this->doc->nodeValue('/activity/quiz/name');
  43          $rt->set_title($title);
  44  
  45          // Metadata.
  46          $metadata = new cc_assesment_metadata();
  47          $rt->set_metadata($metadata);
  48          $metadata->enable_feedback();
  49          $metadata->enable_hints();
  50          $metadata->enable_solutions();
  51          // Attempts.
  52          $max_attempts = (int)$this->doc->nodeValue('/activity/quiz/attempts_number');
  53          if ($max_attempts > 0) {
  54              // Qti does not support number of specific attempts bigger than 5 (??)
  55              if ($max_attempts > 5) {
  56                  $max_attempts = cc_qti_values::unlimited;
  57              }
  58              $metadata->set_maxattempts($max_attempts);
  59          }
  60          // Time limit must be converted into minutes.
  61          $timelimit = (int)floor((int)$this->doc->nodeValue('/activity/quiz/timelimit') / 60);
  62          if ($timelimit > 0) {
  63              $metadata->set_timelimit($timelimit);
  64              $metadata->enable_latesubmissions(false);
  65          }
  66  
  67          $contextid = $this->doc->nodeValue('/activity/@contextid');
  68          $result = cc_helpers::process_linked_files( $this->doc->nodeValue('/activity/quiz/intro'),
  69                                                      $this->manifest,
  70                                                      $this->rootpath,
  71                                                      $contextid,
  72                                                      $outdir);
  73          cc_assesment_helper::add_assesment_description($rt, $result[0], cc_qti_values::htmltype);
  74  
  75          // Section.
  76          $section = new cc_assesment_section();
  77          $rt->set_section($section);
  78  
  79          // Process the actual questions.
  80          $ndeps = cc_assesment_helper::process_questions($this->doc,
  81                                                          $this->manifest,
  82                                                          $section,
  83                                                          $this->rootpath,
  84                                                          $contextid,
  85                                                          $outdir);
  86          if ($ndeps === false) {
  87              // No exportable questions in quiz or quiz has no questions
  88              // so just skip it.
  89              return true;
  90          }
  91          // Store any additional dependencies.
  92          $deps = array_merge($result[1], $ndeps);
  93  
  94          // Store everything.
  95          $this->store($rt, $outdir, $title, $deps);
  96          return true;
  97      }
  98  }