Skip to content
Snippets Groups Projects
Select Git revision
  • 5efdfdbdd7de643124f4f39816e4b3ead35c8239
  • master default protected
  • hsh_v4.5
  • hsh_v4-4
  • hsh_v4.4
  • hsh_v4.3
  • hsh_v4.1.x
  • hsh_v4.2
  • hsh_v4.1
  • hsh_v3.11
  • hsh_3.10
  • v3.11-r2-hsh
  • v3.11-r2
  • v3.11-r1
  • v3.10-r1
  • v3.9-r1
  • v3.8-r2
  • v3.8-r1
  • v3.7-r1
19 results

lib_manager.php

Blame
  • questiontestedit.php 7.04 KiB
    <?php
    // This file is part of Stack - http://stack.maths.ed.ac.uk/
    //
    // Stack is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation, either version 3 of the License, or
    // (at your option) any later version.
    //
    // Stack is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    //
    // You should have received a copy of the GNU General Public License
    // along with Stack.  If not, see <http://www.gnu.org/licenses/>.
    
    /**
     * This script lets the user create or edit question tests for a question.
     *
     * @copyright  2012 the Open University
     * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     */
    
    require_once(__DIR__.'/../../../config.php');
    
    require_once($CFG->libdir . '/questionlib.php');
    require_once(__DIR__ . '/vle_specific.php');
    require_once(__DIR__ . '/locallib.php');
    require_once(__DIR__ . '/questiontestform.php');
    require_once(__DIR__ . '/stack/questiontest.php');
    require_once(__DIR__ . '/stack/potentialresponsetreestate.class.php');
    
    
    // Get the parameters from the URL.
    $questionid = required_param('questionid', PARAM_INT);
    $testcase = optional_param('testcase', null, PARAM_INT);
    $confirmthistestcase = optional_param('confirmthistestcase', null, PARAM_INT);
    
    // Load the necessary data.
    $questiondata = $DB->get_record('question', ['id' => $questionid], '*', MUST_EXIST);
    $question = question_bank::load_question($questionid);
    // We hard-wire decimals to be a full stop when testing questions.
    $question->options->set_option('decimals', '.');
    if ($testcase || $confirmthistestcase) {
        $qtest = question_bank::get_qtype('stack')->load_question_test($questionid, $testcase);
    }
    
    // Process any other URL parameters, and do require_login.
    list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($question);
    
    // Check permissions.
    question_require_capability_on($questiondata, 'edit');
    
    // Work out whether we are adding or editing.
    if (!is_null($testcase)) {
        $title = stack_string('editingtestcase',
                ['no' => $testcase, 'question' => format_string($question->name)]);
        $submitlabel = get_string('savechanges');
    } else {
        $title = stack_string('addingatestcase', format_string($question->name));
        $submitlabel = stack_string('createtestcase');
    }
    
    // Create the question usage we will use.
    $quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
    $quba->set_preferred_behaviour('adaptive');
    if (!is_null($seed)) {
        // This is a bit of a hack to force the question to use a particular seed,
        // even if it is not one of the deployed seeds.
        $question->seed = $seed;