quiz editing: MDL-18173 Make clear in the UI whether a random question selects from subcategories or not.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
<?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';
|
||||
?>
|
||||
|
||||
@@ -46,6 +46,7 @@ $string['categorycurrent'] = 'Current Category';
|
||||
$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.';
|
||||
|
||||
@@ -549,10 +549,14 @@ $string['quiztimer'] = 'Quiz Timer';
|
||||
$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!';
|
||||
@@ -722,7 +726,6 @@ $string['withselected'] = 'With selected';
|
||||
$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';
|
||||
|
||||
+28
-2
@@ -705,7 +705,13 @@ function quiz_print_randomquestion(&$question, &$pageurl, &$quiz,$quiz_qbanktool
|
||||
|
||||
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;
|
||||
@@ -792,6 +798,7 @@ function quiz_print_singlequestion_reordertool($question, $returnurl, $quiz){
|
||||
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()
|
||||
@@ -800,7 +807,6 @@ function quiz_print_singlequestion_reordertool($question, $returnurl, $quiz){
|
||||
* @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;
|
||||
|
||||
@@ -819,6 +825,7 @@ function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz){
|
||||
echo '<div class="randomquestionfromcategory">';
|
||||
echo $reordercheckboxlabel;
|
||||
print_question_icon($question);
|
||||
print_random_option_icon($question);
|
||||
|
||||
if ($questioncount == 0) {
|
||||
echo '<span class="error">';
|
||||
@@ -841,6 +848,25 @@ function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz){
|
||||
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.
|
||||
*
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 153 B |
Binary file not shown.
|
After Width: | Height: | Size: 138 B |
@@ -467,9 +467,13 @@ class question_category_object {
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -26,6 +26,33 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
$plugin->version = 2007081700;
|
||||
$plugin->version = 2009021800;
|
||||
$plugin->requires = 2007101000;
|
||||
|
||||
?>
|
||||
|
||||
@@ -103,9 +103,17 @@ class random_qtype extends default_questiontype {
|
||||
/**
|
||||
* 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) {
|
||||
@@ -129,7 +137,7 @@ class random_qtype extends default_questiontype {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user