Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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    moodlecore
  19   * @subpackage backup-moodle2
  20   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  
  28  require_once($CFG->dirroot .
  29          '/question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php');
  30  
  31  /**
  32   * restore plugin class that provides the necessary information
  33   * needed to restore one calculatedmulti qtype plugin.
  34   *
  35   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class restore_qtype_calculatedmulti_plugin extends restore_qtype_calculated_plugin {
  39  
  40      public function recode_response($questionid, $sequencenumber, array $response) {
  41          return $this->step->questions_recode_response_data('multichoice',
  42                  $questionid, $sequencenumber, $response);
  43      }
  44  
  45      /**
  46       * Given one question_states record, return the answer
  47       * recoded pointing to all the restored stuff for calculatedmulti questions
  48       *
  49       * answer format is datasetxx-yy:zz, where xx is the itemnumber in the dataset
  50       * (doesn't need conversion), and both yy and zz are two (hypen speparated)
  51       * lists of comma separated question_answers, the first to specify the order
  52       * of the answers and the second to specify the responses.
  53       *
  54       * in fact, this qtype behaves exactly like the multichoice one, so we'll delegate
  55       * recoding of those yy:zz to it
  56       */
  57      public function recode_legacy_state_answer($state) {
  58          $answer = $state->answer;
  59          $result = '';
  60          // Datasetxx-yy:zz format.
  61          if (preg_match('~^dataset([0-9]+)-(.*)$~', $answer, $matches)) {
  62              $itemid = $matches[1];
  63              $subanswer  = $matches[2];
  64              // Delegate subanswer recode to multichoice qtype, faking one question_states record.
  65              $substate = new stdClass();
  66              $substate->answer = $subanswer;
  67              $newanswer = $this->step->restore_recode_legacy_answer($substate, 'multichoice');
  68              $result = 'dataset' . $itemid . '-' . $newanswer;
  69          }
  70          return $result ? $result : $answer;
  71      }
  72  }