mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Merge branch 'MDL-45763-master' of https://github.com/merrill-oakland/moodle
This commit is contained in:
commit
2d8d99ab5b
5 changed files with 122 additions and 3 deletions
|
@ -213,7 +213,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number,
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM {quiz_slots}
|
FROM {quiz_slots}
|
||||||
WHERE questionid = q.id)
|
WHERE questionid = q.id)
|
||||||
ORDER BY id", array($category->id, $includesubcategories))) {
|
ORDER BY id", array($category->id, ($includesubcategories ? '1' : '0')))) {
|
||||||
// Take as many of these as needed.
|
// Take as many of these as needed.
|
||||||
while (($existingquestion = array_shift($existingquestions)) && $number > 0) {
|
while (($existingquestion = array_shift($existingquestions)) && $number > 0) {
|
||||||
quiz_add_quiz_question($existingquestion->id, $quiz, $addonpage);
|
quiz_add_quiz_question($existingquestion->id, $quiz, $addonpage);
|
||||||
|
@ -228,7 +228,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number,
|
||||||
// More random questions are needed, create them.
|
// More random questions are needed, create them.
|
||||||
for ($i = 0; $i < $number; $i += 1) {
|
for ($i = 0; $i < $number; $i += 1) {
|
||||||
$form = new stdClass();
|
$form = new stdClass();
|
||||||
$form->questiontext = array('text' => $includesubcategories, 'format' => 0);
|
$form->questiontext = array('text' => ($includesubcategories ? '1' : '0'), 'format' => 0);
|
||||||
$form->category = $category->id . ',' . $category->contextid;
|
$form->category = $category->id . ',' . $category->contextid;
|
||||||
$form->defaultmark = 1;
|
$form->defaultmark = 1;
|
||||||
$form->hidden = 1;
|
$form->hidden = 1;
|
||||||
|
|
|
@ -33,6 +33,33 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class restore_qtype_random_plugin extends restore_qtype_plugin {
|
class restore_qtype_random_plugin extends restore_qtype_plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the plugin structure.
|
||||||
|
*
|
||||||
|
* @return array Array of {@link restore_path_elements}.
|
||||||
|
*/
|
||||||
|
protected function define_question_plugin_structure() {
|
||||||
|
$paths = array();
|
||||||
|
|
||||||
|
// We have to specify a path here if we want after_execute_question to be called.
|
||||||
|
$elename = 'donothing';
|
||||||
|
$elepath = $this->get_pathfor('/');
|
||||||
|
|
||||||
|
$paths[] = new restore_path_element($elename, $elepath);
|
||||||
|
|
||||||
|
return $paths; // And we return the interesting paths.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required function to process path. Should never be called.
|
||||||
|
*
|
||||||
|
* @param object $data Data elements.
|
||||||
|
*/
|
||||||
|
public function process_donothing($data) {
|
||||||
|
// Intentionally blank.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given one question_states record, return the answer
|
* Given one question_states record, return the answer
|
||||||
* recoded pointing to all the restored stuff for random questions
|
* recoded pointing to all the restored stuff for random questions
|
||||||
|
@ -69,4 +96,23 @@ class restore_qtype_random_plugin extends restore_qtype_plugin {
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After restoring, make sure questiontext is set properly.
|
||||||
|
*/
|
||||||
|
public function after_execute_question() {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Update any blank random questiontexts to 0.
|
||||||
|
$sql = "UPDATE {question}
|
||||||
|
SET questiontext = '0'
|
||||||
|
WHERE qtype = 'random'
|
||||||
|
AND " . $DB->sql_compare_text('questiontext') . " = ?
|
||||||
|
AND id IN (SELECT bi.newitemid
|
||||||
|
FROM {backup_ids_temp} AS bi
|
||||||
|
WHERE bi.backupid = ?
|
||||||
|
AND bi.itemname = 'question_created')";
|
||||||
|
|
||||||
|
$DB->execute($sql, array('', $this->get_restoreid()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
68
question/type/random/db/upgrade.php
Normal file
68
question/type/random/db/upgrade.php
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle 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.
|
||||||
|
//
|
||||||
|
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Random question type upgrade code.
|
||||||
|
*
|
||||||
|
* @package qtype_random
|
||||||
|
* @copyright 2014 Eric Merrill
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade code for the random question type.
|
||||||
|
* @param int $oldversion the version we are upgrading from.
|
||||||
|
*/
|
||||||
|
function xmldb_qtype_random_upgrade($oldversion) {
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
$dbman = $DB->get_manager();
|
||||||
|
|
||||||
|
// Moodle v2.2.0 release upgrade line
|
||||||
|
// Put any upgrade step following this.
|
||||||
|
|
||||||
|
// Moodle v2.3.0 release upgrade line
|
||||||
|
// Put any upgrade step following this.
|
||||||
|
|
||||||
|
// Moodle v2.4.0 release upgrade line
|
||||||
|
// Put any upgrade step following this.
|
||||||
|
|
||||||
|
// Moodle v2.5.0 release upgrade line.
|
||||||
|
// Put any upgrade step following this.
|
||||||
|
|
||||||
|
// Moodle v2.6.0 release upgrade line.
|
||||||
|
// Put any upgrade step following this.
|
||||||
|
|
||||||
|
// Moodle v2.7.0 release upgrade line.
|
||||||
|
// Put any upgrade step following this.
|
||||||
|
|
||||||
|
if ($oldversion < 2014060200) {
|
||||||
|
$sql = "UPDATE {question}
|
||||||
|
SET questiontext = '0'
|
||||||
|
WHERE qtype = 'random'
|
||||||
|
AND " . $DB->sql_compare_text('questiontext') . " = ?";
|
||||||
|
$DB->execute($sql, array(''));
|
||||||
|
|
||||||
|
// Record that qtype_random savepoint was reached.
|
||||||
|
upgrade_plugin_savepoint(true, 2014060200, 'qtype', 'random');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -151,6 +151,11 @@ class qtype_random extends question_type {
|
||||||
|
|
||||||
public function save_question($question, $form) {
|
public function save_question($question, $form) {
|
||||||
$form->name = '';
|
$form->name = '';
|
||||||
|
if ($form->questiontext) {
|
||||||
|
$form->questiontext = '1';
|
||||||
|
} else {
|
||||||
|
$form->questiontext = '0';
|
||||||
|
}
|
||||||
$form->questiontextformat = FORMAT_MOODLE;
|
$form->questiontextformat = FORMAT_MOODLE;
|
||||||
$form->tags = array();
|
$form->tags = array();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$plugin->component = 'qtype_random';
|
$plugin->component = 'qtype_random';
|
||||||
$plugin->version = 2014051200;
|
$plugin->version = 2014060200;
|
||||||
|
|
||||||
$plugin->requires = 2014050800;
|
$plugin->requires = 2014050800;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue