Skip to content

Commit

Permalink
Merge branch 'MDL-45763-27' of https://github.com/merrill-oakland/moodle
Browse files Browse the repository at this point in the history
 into MOODLE_27_STABLE
  • Loading branch information
Damyon Wiese committed Jun 10, 2014
2 parents d420bf9 + 5f86aa9 commit 6a92766
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 3 deletions.
4 changes: 2 additions & 2 deletions mod/quiz/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number,
SELECT *
FROM {quiz_slots}
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.
while (($existingquestion = array_shift($existingquestions)) && $number > 0) {
quiz_add_quiz_question($existingquestion->id, $quiz, $addonpage);
Expand All @@ -228,7 +228,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number,
// More random questions are needed, create them.
for ($i = 0; $i < $number; $i += 1) {
$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->defaultmark = 1;
$form->hidden = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
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
* recoded pointing to all the restored stuff for random questions
Expand Down Expand Up @@ -69,4 +96,23 @@ public function recode_legacy_state_answer($state) {
}
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 changes: 68 additions & 0 deletions question/type/random/db/upgrade.php
Original file line number Diff line number Diff line change
@@ -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 < 2014051201) {
$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, 2014051201, 'qtype', 'random');
}

return true;
}
5 changes: 5 additions & 0 deletions question/type/random/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ protected function set_selected_question_name($question, $randomname) {

public function save_question($question, $form) {
$form->name = '';
if ($form->questiontext) {
$form->questiontext = '1';
} else {
$form->questiontext = '0';
}
$form->questiontextformat = FORMAT_MOODLE;
$form->tags = array();

Expand Down
2 changes: 1 addition & 1 deletion question/type/random/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'qtype_random';
$plugin->version = 2014051200;
$plugin->version = 2014051201;

$plugin->requires = 2014050800;

Expand Down

0 comments on commit 6a92766

Please sign in to comment.