Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 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   * Rest endpoint for ajax editing for paging operations on the quiz structure.
  19   *
  20   * @package   mod_quiz
  21   * @copyright 2014 The Open University
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../config.php');
  26  require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  27  
  28  $quizid = required_param('quizid', PARAM_INT);
  29  $slotnumber = required_param('slot', PARAM_INT);
  30  $repagtype = required_param('repag', PARAM_INT);
  31  
  32  require_sesskey();
  33  $quizobj = quiz::create($quizid);
  34  require_login($quizobj->get_course(), false, $quizobj->get_cm());
  35  require_capability('mod/quiz:manage', $quizobj->get_context());
  36  if (quiz_has_attempts($quizid)) {
  37      $reportlink = quiz_attempt_summary_link_to_reports($quizobj->get_quiz(),
  38                      $quizobj->get_cm(), $quizobj->get_context());
  39      throw new \moodle_exception('cannoteditafterattempts', 'quiz',
  40              new moodle_url('/mod/quiz/edit.php', array('cmid' => $quizobj->get_cmid())), $reportlink);
  41  }
  42  
  43  $slotnumber++;
  44  $repage = new \mod_quiz\repaginate($quizid);
  45  $repage->repaginate_slots($slotnumber, $repagtype);
  46  
  47  $structure = $quizobj->get_structure();
  48  $slots = $structure->refresh_page_numbers_and_update_db();
  49  
  50  redirect(new moodle_url('edit.php', array('cmid' => $quizobj->get_cmid())));