<?php
$string['configselectmanualquestions'] = 'Can the random question type select a manually graded question when it is making its random choice of a question from a category?';
+$string['randomqname'] = 'Random ($a)';
+$string['randomqplusname'] = 'Random ($a and sub-categories)';
$string['selectmanualquestions'] = 'Random questions can use manually graded questions';
?>
$string['categorycurrentuse'] = 'Use This Category';
$string['categorymoveto'] = 'Save in Category';
$string['changepublishstatuscat'] = '<a href=\"$a->caturl\">Category \"$a->name\"</a> in course \"$a->coursename\" will have it\'s sharing status changed from <strong>$a->changefrom to $a->changeto</strong>.';
+$string['chooseqtypetoadd'] = 'Choose a question type to add';
$string['clicktoflag'] = 'Click to flag this question';
$string['clicktounflag'] = 'Click to un-flag this question';
$string['cwrqpfs'] = 'Random questions selecting questions from sub categories.';
$string['quizwillopen'] = 'This quiz will open $a';
$string['random'] = 'Random Question';
$string['randomcreate'] = 'Create Random Questions';
+$string['randomfromcategory'] = 'Random question from all of category:';
+$string['randomfromcategoryonly'] = 'Random question from just category:';
+$string['randomnosubcat'] = 'Questions from this category only, not its subcategories.';
$string['randomsamatch'] = 'Random Short-Answer Matching';
$string['randomsamatchcreate'] = 'Create Random Short-Answer Matching questions';
$string['randomsamatchintro'] = 'For each of the following questions, select the matching answer from the menu.';
$string['randomsamatchnumber'] = 'Number of questions to select';
+$string['randomwithsubcat'] = 'Questions from this category and its subcategories.';
$string['readytosend'] = 'You are about to send your whole quiz to be graded. Are you sure you want to continue?';
$string['reattemptquiz'] = 'Re-attempt quiz';
$string['recentlyaddedquestion'] = 'Recently added question!';
$string['withsummary'] = 'with Summary Statistics';
$string['wronggrade'] = 'Wrong grade (after line $a) :';
$string['wronguse'] = 'You can not use this page like that';
-$string['xfromcategory'] = '$a from category:';
$string['xhtml'] = 'XHTML Format';
$string['xml'] = 'Moodle XML format';
$string['xmlimportnoname'] = 'Missing question name in xml file';
echo '<div class="randomquestionfromcategory">';
print_question_icon($question);
- echo ' ' . get_string('xfromcategory', 'quiz', get_string('random', 'quiz')) . '</div>';
+ print_random_option_icon($question);
+ if (!empty($question->questiontext)) {
+ $string = 'randomfromcategory';
+ } else {
+ $string = 'randomfromcategoryonly';
+ }
+ echo ' ' . get_string($string, 'quiz') . '</div>';
$a = new stdClass;
$a->arrow = $THEME->rarrow;
quiz_question_action_icons($quiz, $quiz->cmid, $question, $returnurl) . '</span>';
echo "</div>\n";
}
+
/**
* Print a given random question in quiz for the reordertool tab of edit.php.
* Meant to be used from quiz_print_question_list()
* @param object $questionurl The url of the question editing page as a moodle_url object
* @param object $quiz The quiz in the context of which the question is being displayed
*/
-
function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz){
global $DB, $QTYPES;
echo '<div class="randomquestionfromcategory">';
echo $reordercheckboxlabel;
print_question_icon($question);
+ print_random_option_icon($question);
if ($questioncount == 0) {
echo '<span class="error">';
echo '</div>';
}
+
+/**
+ * Print an icon to indicate the 'include subcategories' state of a random question.
+ * @param $question the random question.
+ */
+function print_random_option_icon($question) {
+ global $CFG;
+ if (!empty($question->questiontext)) {
+ $icon = 'withsubcat';
+ $tooltip = get_string('randomwithsubcat', 'quiz');
+ } else {
+ $icon = 'nosubcat';
+ $tooltip = get_string('randomnosubcat', 'quiz');
+ }
+ echo '<img src="' . $CFG->pixpath . '/i/' . $icon . '.png" alt="' .
+ $tooltip . '" title="' . $tooltip . '" />';
+
+}
+
/**
* Creates a textual representation of a question for display.
*
// If the category name has changed, rename any random questions in that category.
if ($oldcat->name != $cat->name) {
- $randomqname = $QTYPES[RANDOM]->question_name($cat);
- $DB->set_field('question', 'name', $randomqname, array('category' => $cat->id), 'qtype', RANDOM);
- // Ignore errors here. It is not a big deal if the questions are not renamed.
+ $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";
+
+ $randomqname = $QTYPES[RANDOM]->question_name($cat, false);
+ $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
+
+ $randomqname = $QTYPES[RANDOM]->question_name($cat, true);
+ $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
}
// Then redirect to an appropriate place.
$dbman = $DB->get_manager();
$result = true;
+ // This upgrade actually belongs to the random question type,
+ // but that does not have a DB upgrade script. Therefore, multichoice
+ // is doing it.
+ // Rename random questions to give them more helpful names.
+ if ($result && $oldversion < 2008021800) {
+ require_once($CFG->libdir . '/questionlib.php');
+ // Get all categories containing random questions.
+ $categories = $DB->get_recordset_sql("
+ SELECT qc.id, qc.name
+ FROM {question_categories} qc
+ JOIN {question} q ON q.category = qc.id
+ WHERE q.qtype = 'random'
+ GROUP BY qc.id, qc.name");
+
+ // Rename the random qusetions in those categories.
+ $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";
+ foreach ($categories as $cat) {
+ $randomqname = $QTYPES[RANDOM]->question_name($cat, false);
+ $result = $result && $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
+
+ $randomqname = $QTYPES[RANDOM]->question_name($cat, true);
+ $result = $result && $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
+ }
+
+ upgrade_plugin_savepoint($result, 2008021800, 'qtype', 'multichoice');
+ }
+
return $result;
}
<?PHP // $Id$
-$plugin->version = 2007081700;
+$plugin->version = 2009021800;
$plugin->requires = 2007101000;
?>
/**
* Random questions always get a question name that is Random (cateogryname).
* This function is a centralised place to calculate that, given the category.
+ * @param object $category the category this question picks from. (Only $category->name is used.)
+ * @param boolean $includesubcategories whether this question also picks from subcategories.
+ * @return string the name this question should have.
*/
- function question_name($category) {
- return get_string('random', 'quiz') .' ('. $category->name .')';
+ function question_name($category, $includesubcategories) {
+ if ($includesubcategories) {
+ $string = 'randomqplusname';
+ } else {
+ $string = 'randomqname';
+ }
+ return get_string($string, 'qtype_random', $category->name);
}
function save_question($question, $form, $course) {
if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
print_error('cannotretrieveqcat', 'question');
}
- $updateobject->name = $this->question_name($category);
+ $updateobject->name = $this->question_name($category, !empty($question->questiontext));
return $DB->update_record('question', $updateobject);
}