Skip to content
Snippets Groups Projects
Select Git revision
  • 20a875b84d84ca4aa295c59f60471f53d4559c4d
  • master default protected
  • pymilter-1.0.4
  • pymilter-1.0.3
  • pymilter-1.0.2
  • pymilter-1.0.1
  • pymilter-1_0
  • milter-0_8_18
  • pymilter-0_9_8
  • pymilter-0_9_7
  • pymilter-0_9_6
  • pymilter-0_9_5
  • pymilter-0_9_4
  • pymilter-0_9_2
  • pymilter-0_9_1
  • pymilter-0_9_0
  • pymilter-0_8_12
  • pymilter-0_8_11
  • pymilter-0_8_10
  • pymilter-0_8_9
  • milter-0_8_8
  • milter-0_8_7
22 results

sample.py

Blame
  • questiontestrun.php 25.99 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 test a question using any question tests defined
     * in the database. It also displays some of the internal workins of questions.
     *
     * Users with moodle/question:view capability can use this script to view the
     * results of the tests.
     *
     * Users with moodle/question:edit can edit the test cases and deployed variant,
     * as well as just run them.
     *
     * The script takes one parameter id which is a questionid as a parameter.
     * In can optionally also take a random seed.
     *
     * @copyright  2012 the Open University
     * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     */
    
    define('NO_OUTPUT_BUFFERING', true);
    
    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__ . '/stack/questiontest.php');
    require_once(__DIR__ . '/stack/bulktester.class.php');
    
    // Get the parameters from the URL.
    $questionid = required_param('questionid', PARAM_INT);
    
    $qversion = null;
    if (stack_determine_moodle_version() >= 400) {
        // We should always run tests on the latest version of the question.
        // This means we can refresh/reload the page even if the question has been edited and saved in another window.
        // When we click "edit question" button we automatically jump to the last version, and don't edit this version.
        $query = 'SELECT qv.questionid, qv.version FROM {question_versions} qv
                      JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
                      WHERE qbe.id = (SELECT be.id FROM {question_bank_entries} be
                                      JOIN {question_versions} v ON v.questionbankentryid = be.id
                                      WHERE v.questionid = ' . $questionid . ')
                  ORDER BY qv.questionid';
        global $DB;
        $result = $DB->get_records_sql($query);
        $result = end($result);
        $qversion = $result->version;
        $questionid = $result->questionid;
    }
    
    // Load the necessary data.
    $questiondata = question_bank::load_question_data($questionid);
    if (!$questiondata) {
        throw new stack_exception('questiondoesnotexist');
    }
    $question = question_bank::load_question($questionid);