// Find existing random questions in this category that are
// not used by any quiz.
if ($existingquestions = $DB->get_records_sql(
- "SELECT * FROM {question} q
+ "SELECT q.id,q.qtype FROM {question} q
WHERE qtype = '" . RANDOM . "'
AND category = ?
AND " . $DB->sql_compare_text('questiontext') . " = ?
AND NOT EXISTS (SELECT * FROM {quiz_question_instances} WHERE question = q.id)
ORDER BY id", array($category->id, $recurse))) {
- // Take as many of these as needed.
+ // Take as many of these as needed.
while (($existingquestion = array_shift($existingquestions))
and $randomcount > 0) {
quiz_add_quiz_question($existingquestion->id, $quiz, $addonpage);
}
// update question grades
- $questionrecord = $DB->get_record('question', array('id' => $id));
- $quiz->grades[$id]
- = $questionrecord->defaultgrade;
+ $quiz->grades[$id] = $DB->get_field('question', 'defaultgrade', array('id' => $id));
quiz_update_question_instance($quiz->grades[$id], $id, $quiz->instance);
return true;
$categorylist_array = explode(',', $categorylist);
list($usql, $params) = $DB->get_in_or_equal($categorylist_array);
- if (!$questions = $DB->get_records_select('question',
- "category $usql AND parent = '0' $showhidden",
- $params, $sortorderdecoded, '*', 0, $numbertoshow)) {
- // There are no questions on the requested page.
- $page = 0;
- if (!$questions = $DB->get_records_select('question',
- "category $usql AND parent = '0' $showhidden",
- $params, $sortorderdecoded, '*', 0, $numbertoshow)) {
- // There are no questions at all
- return;
- }
+ if (!$questions = $DB->get_records_select('question', "category $usql AND parent = '0' $showhidden",
+ $params, $sortorderdecoded, 'qtype,name,questiontext,questiontextformat', 0, $numbertoshow)) {
}
foreach ($questions as $question) {
echo "<li>";