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.

Differences Between: [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   * @package    mod_quiz
  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  require_once($CFG->dirroot . '/mod/quiz/backup/moodle2/restore_quiz_stepslib.php');
  28  
  29  
  30  /**
  31   * quiz restore task that provides all the settings and steps to perform one
  32   * complete restore of the activity
  33   *
  34   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class restore_quiz_activity_task extends restore_activity_task {
  38  
  39      /**
  40       * Define (add) particular settings this activity can have
  41       */
  42      protected function define_my_settings() {
  43          // No particular settings for this activity.
  44      }
  45  
  46      /**
  47       * Define (add) particular steps this activity can have
  48       */
  49      protected function define_my_steps() {
  50          // Quiz only has one structure step.
  51          $this->add_step(new restore_quiz_activity_structure_step('quiz_structure', 'quiz.xml'));
  52      }
  53  
  54      /**
  55       * Define the contents in the activity that must be
  56       * processed by the link decoder
  57       */
  58      public static function define_decode_contents() {
  59          $contents = array();
  60  
  61          $contents[] = new restore_decode_content('quiz', array('intro'), 'quiz');
  62          $contents[] = new restore_decode_content('quiz_feedback',
  63                  array('feedbacktext'), 'quiz_feedback');
  64  
  65          return $contents;
  66      }
  67  
  68      /**
  69       * Define the decoding rules for links belonging
  70       * to the activity to be executed by the link decoder
  71       */
  72      public static function define_decode_rules() {
  73          $rules = array();
  74  
  75          $rules[] = new restore_decode_rule('QUIZVIEWBYID',
  76                  '/mod/quiz/view.php?id=$1', 'course_module');
  77          $rules[] = new restore_decode_rule('QUIZVIEWBYQ',
  78                  '/mod/quiz/view.php?q=$1', 'quiz');
  79          $rules[] = new restore_decode_rule('QUIZINDEX',
  80                  '/mod/quiz/index.php?id=$1', 'course');
  81  
  82          return $rules;
  83  
  84      }
  85  
  86      /**
  87       * Define the restore log rules that will be applied
  88       * by the {@link restore_logs_processor} when restoring
  89       * quiz logs. It must return one array
  90       * of {@link restore_log_rule} objects
  91       */
  92      public static function define_restore_log_rules() {
  93          $rules = array();
  94  
  95          $rules[] = new restore_log_rule('quiz', 'add',
  96                  'view.php?id={course_module}', '{quiz}');
  97          $rules[] = new restore_log_rule('quiz', 'update',
  98                  'view.php?id={course_module}', '{quiz}');
  99          $rules[] = new restore_log_rule('quiz', 'view',
 100                  'view.php?id={course_module}', '{quiz}');
 101          $rules[] = new restore_log_rule('quiz', 'preview',
 102                  'view.php?id={course_module}', '{quiz}');
 103          $rules[] = new restore_log_rule('quiz', 'report',
 104                  'report.php?id={course_module}', '{quiz}');
 105          $rules[] = new restore_log_rule('quiz', 'editquestions',
 106                  'view.php?id={course_module}', '{quiz}');
 107          $rules[] = new restore_log_rule('quiz', 'delete attempt',
 108                  'report.php?id={course_module}', '[oldattempt]');
 109          $rules[] = new restore_log_rule('quiz', 'edit override',
 110                  'overrideedit.php?id={quiz_override}', '{quiz}');
 111          $rules[] = new restore_log_rule('quiz', 'delete override',
 112                  'overrides.php.php?cmid={course_module}', '{quiz}');
 113          $rules[] = new restore_log_rule('quiz', 'addcategory',
 114                  'view.php?id={course_module}', '{question_category}');
 115          $rules[] = new restore_log_rule('quiz', 'view summary',
 116                  'summary.php?attempt={quiz_attempt}', '{quiz}');
 117          $rules[] = new restore_log_rule('quiz', 'manualgrade',
 118                  'comment.php?attempt={quiz_attempt}&question={question}', '{quiz}');
 119          $rules[] = new restore_log_rule('quiz', 'manualgrading',
 120                  'report.php?mode=grading&q={quiz}', '{quiz}');
 121          // All the ones calling to review.php have two rules to handle both old and new urls
 122          // in any case they are always converted to new urls on restore.
 123          // TODO: In Moodle 2.x (x >= 5) kill the old rules.
 124          // Note we are using the 'quiz_attempt' mapping because that is the
 125          // one containing the quiz_attempt->ids old an new for quiz-attempt.
 126          $rules[] = new restore_log_rule('quiz', 'attempt',
 127                  'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
 128                  null, null, 'review.php?attempt={quiz_attempt}');
 129          $rules[] = new restore_log_rule('quiz', 'attempt',
 130                  'review.php?attempt={quiz_attempt}', '{quiz}',
 131                  null, null, 'review.php?attempt={quiz_attempt}');
 132          // Old an new for quiz-submit.
 133          $rules[] = new restore_log_rule('quiz', 'submit',
 134                  'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
 135                  null, null, 'review.php?attempt={quiz_attempt}');
 136          $rules[] = new restore_log_rule('quiz', 'submit',
 137                  'review.php?attempt={quiz_attempt}', '{quiz}');
 138          // Old an new for quiz-review.
 139          $rules[] = new restore_log_rule('quiz', 'review',
 140                  'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
 141                  null, null, 'review.php?attempt={quiz_attempt}');
 142          $rules[] = new restore_log_rule('quiz', 'review',
 143                  'review.php?attempt={quiz_attempt}', '{quiz}');
 144          // Old an new for quiz-start attemp.
 145          $rules[] = new restore_log_rule('quiz', 'start attempt',
 146                  'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
 147                  null, null, 'review.php?attempt={quiz_attempt}');
 148          $rules[] = new restore_log_rule('quiz', 'start attempt',
 149                  'review.php?attempt={quiz_attempt}', '{quiz}');
 150          // Old an new for quiz-close attemp.
 151          $rules[] = new restore_log_rule('quiz', 'close attempt',
 152                  'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
 153                  null, null, 'review.php?attempt={quiz_attempt}');
 154          $rules[] = new restore_log_rule('quiz', 'close attempt',
 155                  'review.php?attempt={quiz_attempt}', '{quiz}');
 156          // Old an new for quiz-continue attempt.
 157          $rules[] = new restore_log_rule('quiz', 'continue attempt',
 158                  'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
 159                  null, null, 'review.php?attempt={quiz_attempt}');
 160          $rules[] = new restore_log_rule('quiz', 'continue attempt',
 161                  'review.php?attempt={quiz_attempt}', '{quiz}');
 162          // Old an new for quiz-continue attemp.
 163          $rules[] = new restore_log_rule('quiz', 'continue attemp',
 164                  'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
 165                  null, 'continue attempt', 'review.php?attempt={quiz_attempt}');
 166          $rules[] = new restore_log_rule('quiz', 'continue attemp',
 167                  'review.php?attempt={quiz_attempt}', '{quiz}',
 168                  null, 'continue attempt');
 169  
 170          return $rules;
 171      }
 172  
 173      /**
 174       * Define the restore log rules that will be applied
 175       * by the {@link restore_logs_processor} when restoring
 176       * course logs. It must return one array
 177       * of {@link restore_log_rule} objects
 178       *
 179       * Note this rules are applied when restoring course logs
 180       * by the restore final task, but are defined here at
 181       * activity level. All them are rules not linked to any module instance (cmid = 0)
 182       */
 183      public static function define_restore_log_rules_for_course() {
 184          $rules = array();
 185  
 186          $rules[] = new restore_log_rule('quiz', 'view all', 'index.php?id={course}', null);
 187  
 188          return $rules;
 189      }
 190  }