Index: question/type/essay/questiontype.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/type/essay/questiontype.php,v retrieving revision 1.20.2.7 diff -u -r1.20.2.7 questiontype.php --- question/type/essay/questiontype.php 20 Aug 2008 09:46:03 -0000 1.20.2.7 +++ question/type/essay/questiontype.php 27 Nov 2008 03:08:23 -0000 @@ -10,6 +10,11 @@ * @subpackage questiontypes */ class question_essay_qtype extends default_questiontype { + var $usablebyrandom; + + function question_essay_qtype() { + $this->usablebyrandom = get_config('qtype_random', 'selectmanual'); + } function name() { return 'essay'; @@ -20,7 +25,7 @@ } function is_usable_by_random() { - return false; + return $this->usablebyrandom; } function save_question_options($question) { Index: admin/settings/misc.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/settings/Attic/misc.php,v retrieving revision 1.14.2.3 diff -u -r1.14.2.3 misc.php --- admin/settings/misc.php 25 Dec 2007 10:03:17 -0000 1.14.2.3 +++ admin/settings/misc.php 27 Nov 2008 03:08:21 -0000 @@ -12,6 +12,9 @@ $item->set_updatedcallback('reset_text_filters_cache'); $temp->add($item); $temp->add(new admin_setting_configcheckbox('enablegroupings', get_string('enablegroupings', 'admin'), get_string('configenablegroupings', 'admin'), 0)); + $rqsetting = new admin_setting_configcheckbox('selectmanual', get_string('selectmanualquestions', 'qtype_random'), get_string('configselectmanualquestions', 'qtype_random'), 0); + $rqsetting->plugin = 'qtype_random'; + $temp->add($rqsetting); $ADMIN->add('misc', $temp); Index: question/type/questiontype.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/type/questiontype.php,v retrieving revision 1.74.2.13 diff -u -r1.74.2.13 questiontype.php --- question/type/questiontype.php 8 Oct 2008 10:19:51 -0000 1.74.2.13 +++ question/type/questiontype.php 27 Nov 2008 03:08:23 -0000 @@ -61,13 +61,22 @@ } /** - * @return boolean true if this question can only be graded manually. + * @return boolean true if this question type sometimes requires manual grading. */ function is_manual_graded() { return false; } /** + * @param object $question a question of this type. + * @param string $otherquestionsinuse comma-separate list of other question ids in this attempt. + * @return boolean true if a particular instance of this question requires manual grading. + */ + function is_question_manual_graded($question, $otherquestionsinuse) { + return $this->is_manual_graded(); + } + + /** * @return boolean true if this question type can be used by the random question type. */ function is_usable_by_random() { Index: question/type/random/questiontype.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/type/random/questiontype.php,v retrieving revision 1.12.2.6 diff -u -r1.12.2.6 questiontype.php --- question/type/random/questiontype.php 10 Nov 2008 07:56:43 -0000 1.12.2.6 +++ question/type/random/questiontype.php 27 Nov 2008 03:08:23 -0000 @@ -11,6 +11,13 @@ * @subpackage questiontypes */ class random_qtype extends default_questiontype { + var $selectmanual; + var $excludedqtypes = null; + var $manualqtypes = array(); + + function random_qtype() { + $this->selectmanual = get_config('qtype_random', 'selectmanual'); + } // Caches questions available as randoms sorted by category // This is a 2-d array. The first key is question category, and the @@ -26,10 +33,60 @@ return false; } + function is_manual_graded($question = null, $otherquestionsinuse = '') { + return $this->selectmanual; + } + + function is_question_manual_graded($question, $otherquestionsinuse) { + if (!$this->selectmanual) { + return false; + } + // We take our best shot at working whether a particular question is manually + // graded follows: We look to see if any of the questions that this random + // question might select if of a manually graded type. If a category contains + // a mixture of manual and non-manual questions, and if all the attempts so + // far selected non-manual ones, this will give the wrong answer, but we + // don't care. Even so, this is an expensive calculation! + $this->init_qtype_arrays(); + if (count($this->manualqtypes) == 0) { + return false; + } + $manualqtypes = "'" . implode("','", $this->manualqtypes) . "'"; + if ($question->questiontext) { + $categorylist = question_categorylist($question->category); + } else { + $categorylist = $question->category; + } + return record_exists_select('question', + "category IN ($categorylist) + AND parent = 0 + AND hidden = 0 + AND id NOT IN ($otherquestionsinuse) + AND qtype IN ($manualqtypes)"); + } + function is_usable_by_random() { return false; } + /** + * This method needs to be called before the ->excludedqtypes and + * ->manualqtypes fields can be used. + */ + function init_qtype_arrays() { + global $QTYPES; + if (is_null($this->excludedqtypes)) { + $this->excludedqtypes = array(); + foreach ($QTYPES as $qtype) { + if (!$qtype->is_usable_by_random()) { + $this->excludedqtypes[] = $qtype->name(); + } else if ($this->selectmanual && $qtype->is_manual_graded()) { + $this->manualqtypes[] = $qtype->name(); + } + } + } + } + function get_question_options(&$question) { // Don't do anything here, because the random question has no options. // Everything is handled by the create- or restore_session_and_responses @@ -80,7 +137,8 @@ * @return array of question records. */ function get_usable_questions_from_category($categoryid, $subcategories, $questionsinuse) { - global $QTYPE_EXCLUDE_FROM_RANDOM; + $this->init_qtype_arrays(); + $excludedqtypes = "'" . implode("','", $this->excludedqtypes) . "'"; if ($subcategories) { $categorylist = question_categorylist($categoryid); } else { @@ -88,10 +146,10 @@ } if (!$catrandoms = get_records_select('question', "category IN ($categorylist) - AND parent = '0' - AND hidden = '0' + AND parent = 0 + AND hidden = 0 AND id NOT IN ($questionsinuse) - AND qtype NOT IN ($QTYPE_EXCLUDE_FROM_RANDOM)", '', 'id')) { + AND qtype NOT IN ($excludedqtypes)", '', 'id')) { $catrandoms = array(); } return $catrandoms; Index: mod/quiz/report/grading/report.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/report/grading/report.php,v retrieving revision 1.25.2.13 diff -u -r1.25.2.13 report.php --- mod/quiz/report/grading/report.php 12 Aug 2008 06:07:13 -0000 1.25.2.13 +++ mod/quiz/report/grading/report.php 27 Nov 2008 03:08:22 -0000 @@ -68,8 +68,9 @@ } $gradeableqs = quiz_report_load_questions($quiz); - foreach ($gradeableqs as $qid => $questionformenu){ - if (!$QTYPES[$questionformenu->qtype]->is_manual_graded()){ + $questionsinuse = implode(',', array_keys($gradeableqs)); + foreach ($gradeableqs as $qid => $question){ + if (!$QTYPES[$question->qtype]->is_question_manual_graded($question, $questionsinuse)){ unset($gradeableqs[$qid]); } } Index: lang/en_utf8/qtype_random.php =================================================================== RCS file: lang/en_utf8/qtype_random.php diff -N lang/en_utf8/qtype_random.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/en_utf8/qtype_random.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,4 @@ +