Skip to content
Snippets Groups Projects
Select Git revision
  • 346f51b92bfa9ca1a518e796c42a7b8173df61f9
  • master default
  • fix-remote-url_v4.9.1
  • fix-remote-url_v4.8.3
  • fix-remote-url_v4.8.x
  • fix-remote-url_v4.7.x
  • fix-remote-url_v4.6.0
  • fix-remote-urls
8 results

tidyquestion.php

Blame
    • Chris Sangwin's avatar
      346f51b9
      Prototype support for Moodle 4.0. · 346f51b9
      Chris Sangwin authored
      Squashed commit of the following:
      
      commit ca5c2a34c95b63df46bca81cb4875e42425ddbe5
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 21:11:35 2022 +0100
      
          Support bulk tester in Moodle 4 and earlier.
      
      commit 9da5f96575acc6c378dd469b7390df1dae78bf0a
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 18:55:47 2022 +0100
      
          Make sure the testing page always tests the last question version.
          This allows the question author to reload the question testing page after a question has been saved.
      
      commit 3c3fcf09d38a5fc981850f037ba8221b21400c24
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 18:14:23 2022 +0100
      
          WIP commit for testing on both Moodle 4.0 and earlier.
      
      commit d00a6f11400fd6af29fb5a646cc83fbb6670ea20
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 17:51:40 2022 +0100
      
          Support on both Moodle 4 and earlier versions (WIP for testing).
      
      commit 07402d5c8249e6d320404973451b819b78a661ca
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 16:46:17 2022 +0100
      
          Support both Moodle 4.0 and previous versions (WIP for testing).
      
      commit 1dccc92e1b0805305505afc3b8a7174792b6dfd2
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 16:07:46 2022 +0100
      
          Add coverage information to unit tests.
      
      commit c8d16b1f829b62f1c8dd8ee7f99e725c178debe2
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 08:36:17 2022 +0100
      
          Add coverage information for auto-generated ast tests.
      
      commit 6ae39e5063fa5d2d4c0a78a10ad56343c78c8fa2
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 08:16:20 2022 +0100
      
          Fix broken unit tests.
      
      commit 38daee7cf0b54dbacf4016bc3fa15dba6adc4b27
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jun 14 20:02:36 2022 +0100
      
          Fix broken test case.
      
      commit ad2f8b04f6e4227c9f525e2650f03e891d69e0ad
      Author: Chris Sangwin <csangwin@coulomb.maths.ed.ac.uk>
      Date:   Tue Jun 14 18:22:16 2022 +0100
      
          Fix bug with test case & seed copying between versions.
      
      commit b4ce5ee24a6f12e724f7c74f9dd53207a426906c
      Merge: 9b325b9a 0e20187b
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sun Jun 12 19:20:03 2022 +0100
      
          Merge remote-tracking branch 'origin/dev' into moodle4
      
      commit 9b325b9aa2b5e01dd5fbd399931e62423262ee3f
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sun Jun 12 11:34:44 2022 +0100
      
          Update question basic useage report for Moodle 4.
      
      commit f57cffeba5dd643b107f7dbf3b478b4a48fc2af0
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sat Jun 11 18:26:09 2022 +0100
      
          Fix failing unit test (artefact of test case construction) + code tidy.
      
      commit e85d6508a3e9f6efcef666cab7cf59fd36c38c24
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sat Jun 11 17:01:01 2022 +0100
      
          Seeds copy over to a new version.
      
      commit 9bb4aec386b478468f8af04c515d598c029da932
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sat Jun 11 16:46:16 2022 +0100
      
          Fix to issue #805.
      
      commit 52828b431bcd01f59ea1401915962f8e039aba79
      Merge: e311ad72 cb8d8a74
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Fri Jun 10 14:41:54 2022 +0100
      
          Merge remote-tracking branch 'origin/dev' into moodle4
      
      commit e311ad72f63bc7d7605e0ec68bf2b9faa752bf78
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Fri Jun 10 11:44:39 2022 +0100
      
          WIP enable bulk tester to run with moodle 4 (unblocks question testing).
      
      commit 4145bb1064a5755c1fb2cb8a2b013ba34adf9d2f
      Merge: fc6a81cb 49f70d7f
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Thu Jun 9 15:46:28 2022 +0100
      
          Merge branch 'moodle4' of https://github.com/maths/moodle-qtype_stack into moodle4
      
      commit fc6a81cb011d9b74d8d4b1a5b63bc87abbe38b28
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Thu Jun 9 15:46:17 2022 +0100
      
          Update todo and developer docs.
      
      commit 49f70d7f9c71e887fe7a6266d40aea9a44a14769
      Author: Matti Harjula <aharjula@konsta.hut.fi>
      Date:   Tue Jun 7 09:19:22 2022 +0300
      
          Codestyle *castext*.
      
      commit d52180b635f2e6f2f18279b1f36ee28d2d509802
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Thu Jun 2 09:58:55 2022 +0100
      
          Audit very stack-specific issues when running on Moodle 4.0.
      346f51b9
      History
      Prototype support for Moodle 4.0.
      Chris Sangwin authored
      Squashed commit of the following:
      
      commit ca5c2a34c95b63df46bca81cb4875e42425ddbe5
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 21:11:35 2022 +0100
      
          Support bulk tester in Moodle 4 and earlier.
      
      commit 9da5f96575acc6c378dd469b7390df1dae78bf0a
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 18:55:47 2022 +0100
      
          Make sure the testing page always tests the last question version.
          This allows the question author to reload the question testing page after a question has been saved.
      
      commit 3c3fcf09d38a5fc981850f037ba8221b21400c24
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 18:14:23 2022 +0100
      
          WIP commit for testing on both Moodle 4.0 and earlier.
      
      commit d00a6f11400fd6af29fb5a646cc83fbb6670ea20
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 17:51:40 2022 +0100
      
          Support on both Moodle 4 and earlier versions (WIP for testing).
      
      commit 07402d5c8249e6d320404973451b819b78a661ca
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 16:46:17 2022 +0100
      
          Support both Moodle 4.0 and previous versions (WIP for testing).
      
      commit 1dccc92e1b0805305505afc3b8a7174792b6dfd2
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 16:07:46 2022 +0100
      
          Add coverage information to unit tests.
      
      commit c8d16b1f829b62f1c8dd8ee7f99e725c178debe2
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 08:36:17 2022 +0100
      
          Add coverage information for auto-generated ast tests.
      
      commit 6ae39e5063fa5d2d4c0a78a10ad56343c78c8fa2
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jul 5 08:16:20 2022 +0100
      
          Fix broken unit tests.
      
      commit 38daee7cf0b54dbacf4016bc3fa15dba6adc4b27
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Tue Jun 14 20:02:36 2022 +0100
      
          Fix broken test case.
      
      commit ad2f8b04f6e4227c9f525e2650f03e891d69e0ad
      Author: Chris Sangwin <csangwin@coulomb.maths.ed.ac.uk>
      Date:   Tue Jun 14 18:22:16 2022 +0100
      
          Fix bug with test case & seed copying between versions.
      
      commit b4ce5ee24a6f12e724f7c74f9dd53207a426906c
      Merge: 9b325b9a 0e20187b
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sun Jun 12 19:20:03 2022 +0100
      
          Merge remote-tracking branch 'origin/dev' into moodle4
      
      commit 9b325b9aa2b5e01dd5fbd399931e62423262ee3f
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sun Jun 12 11:34:44 2022 +0100
      
          Update question basic useage report for Moodle 4.
      
      commit f57cffeba5dd643b107f7dbf3b478b4a48fc2af0
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sat Jun 11 18:26:09 2022 +0100
      
          Fix failing unit test (artefact of test case construction) + code tidy.
      
      commit e85d6508a3e9f6efcef666cab7cf59fd36c38c24
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sat Jun 11 17:01:01 2022 +0100
      
          Seeds copy over to a new version.
      
      commit 9bb4aec386b478468f8af04c515d598c029da932
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Sat Jun 11 16:46:16 2022 +0100
      
          Fix to issue #805.
      
      commit 52828b431bcd01f59ea1401915962f8e039aba79
      Merge: e311ad72 cb8d8a74
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Fri Jun 10 14:41:54 2022 +0100
      
          Merge remote-tracking branch 'origin/dev' into moodle4
      
      commit e311ad72f63bc7d7605e0ec68bf2b9faa752bf78
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Fri Jun 10 11:44:39 2022 +0100
      
          WIP enable bulk tester to run with moodle 4 (unblocks question testing).
      
      commit 4145bb1064a5755c1fb2cb8a2b013ba34adf9d2f
      Merge: fc6a81cb 49f70d7f
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Thu Jun 9 15:46:28 2022 +0100
      
          Merge branch 'moodle4' of https://github.com/maths/moodle-qtype_stack into moodle4
      
      commit fc6a81cb011d9b74d8d4b1a5b63bc87abbe38b28
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Thu Jun 9 15:46:17 2022 +0100
      
          Update todo and developer docs.
      
      commit 49f70d7f9c71e887fe7a6266d40aea9a44a14769
      Author: Matti Harjula <aharjula@konsta.hut.fi>
      Date:   Tue Jun 7 09:19:22 2022 +0300
      
          Codestyle *castext*.
      
      commit d52180b635f2e6f2f18279b1f36ee28d2d509802
      Author: Chris Sangwin <C.J.Sangwin@ed.ac.uk>
      Date:   Thu Jun 2 09:58:55 2022 +0100
      
          Audit very stack-specific issues when running on Moodle 4.0.
    tidyquestion.php 5.06 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 rename parts of the question, which is not possible using
     * the standard editing form.
     *
     * @copyright  2013 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__ . '/locallib.php');
    require_once(__DIR__ . '/tidyquestionform.php');
    
    if (stack_determine_moodle_version() >= 400) {
        require_once(__DIR__ . 'vle_moodle4.php');
    }
    
    // Get the parameters from the URL.
    $questionid = required_param('questionid', PARAM_INT);
    
    // Load the necessary data.
    $questiondata = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST);
    $question = question_bank::load_question($questionid);
    
    // Process any other URL parameters, and do require_login.
    list($context, $notused, $urlparams) = qtype_stack_setup_question_test_page($question);
    
    // Check permissions.
    question_require_capability_on($questiondata, 'edit');
    
    // Initialise $PAGE.
    $PAGE->set_url('/question/type/stack/tidyquestion.php', $urlparams);
    $title = stack_string('tidyquestionx', format_string($question->name));
    $PAGE->set_title($title);
    $PAGE->set_heading($COURSE->fullname);
    $PAGE->set_pagelayout('admin');
    
    require_login();
    
    // The URL back to the preview page.
    $returnurl = helper::question_preview_url($questionid, null, null, null, null, $context);
    
    // Create the question usage we will use.
    $quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
    $quba->set_preferred_behaviour('adaptive');
    $slot = $quba->add_question($question, $question->defaultmark);
    $quba->start_question($slot);
    
    // Now we are going to display the question with each input box containing the
    // name of that input, and each feedback area displaying something like
    // "Feedback from PRT {name}". To do this, first we submit the right answer to
    // get the question into a state where all feedback will be displayed.
    $response = $question->get_correct_response();
    $response['-submit'] = 1;
    $quba->process_action($slot, $response);
    
    // Now we want to be able to display the question with the wrong input values
    // and PRT feedback. We do that by polluting the question's input state and
    // PRT result caches with the data we want to display, then the renderer will
    // display that.
    $question->setup_fake_feedback_and_input_validation();
    
    // Prepare the display options.
    $options = new question_display_options();
    $options->readonly = true;
    $options->flags = question_display_options::HIDDEN;
    $options->suppressruntestslink = true;
    
    // Create the form for renaming bits of the question.
    $form = new qtype_stack_tidy_question_form($PAGE->url, $question);
    
    if ($form->is_cancelled()) {
        redirect($returnurl);
    
    } else if ($data = $form->get_data()) {
        $qtype = question_bank::get_qtype('stack');
        $transaction = $DB->start_delegated_transaction();
    
        // Rename the inputs.
        $inputrenames = array();
        foreach ($question->inputs as $inputname => $notused) {
            $inputrenames[$inputname] = $data->{'inputname_' . $inputname};
        }
        foreach (stack_utils::decompose_rename_operation($inputrenames) as $from => $to) {
            $qtype->rename_input($question->id, $from, $to);
        }
    
        // Rename the PRT nodes.
        foreach ($question->prts as $prtname => $prt) {
            $noderenames = array();
            foreach ($prt->get_nodes_summary() as $nodekey => $notused) {
                $noderenames[$nodekey] = $data->{'nodename_' . $prtname . '_' . $nodekey} - 1;
            }
            foreach (stack_utils::decompose_rename_operation($noderenames) as $from => $to) {
                $qtype->rename_prt_node($question->id, $prtname, $from, $to);
            }
        }
    
        // Rename the PRTs. Much easier to do this after the nodes.
        $prtrenames = array();
        foreach ($question->prts as $prtname => $notused) {
            $prtrenames[$prtname] = $data->{'prtname_' . $prtname};
        }
        foreach (stack_utils::decompose_rename_operation($prtrenames) as $from => $to) {
            $qtype->rename_prt($question->id, $from, $to);
        }
    
        // Done.
        $transaction->allow_commit();
        redirect($returnurl);
    }
    
    // Start output.
    echo $OUTPUT->header();
    echo $OUTPUT->heading($title);
    
    // Display the question.
    echo $OUTPUT->heading(stack_string('questionpreview'), 3);
    echo $quba->render_question($slot, $options);
    
    // Display the form to rename bits of the question.
    $form->display();
    
    // Finish output.
    echo $OUTPUT->footer();