print_heading(get_string('reportsettings', 'report_questioninstances'));
echo '<p id="intro">', get_string('intro', 'report_questioninstances') , '</p>';
echo '<p><label for="menuqtype"> ' . get_string('questiontype', 'admin') . '</label> ';
-choose_from_menu($qtypechoices, 'qtype', $requestedqtype);
+choose_from_menu($qtypechoices, 'qtype', $requestedqtype, get_string('all'), '', '_all_');
echo '</p>';
echo '<p><input type="submit" id="settingssubmit" value="' .
get_string('getreport', 'report_questioninstances') . '" /></p>';
$othertypes = array_keys($QTYPES);
$key = array_search('missingtype', $othertypes);
unset($othertypes[$key]);
- list($sqlqtypetest, $params) = $DB->get_in_or_equals($othertypes, SQL_PARAMS_QM, '', false);
+ list($sqlqtypetest, $params) = $DB->get_in_or_equal($othertypes, SQL_PARAMS_QM, '', false);
+ $sqlqtypetest = 'WHERE qtype ' . $sqlqtypetest;
+ $title = get_string('reportformissingqtypes', 'report_questioninstances');
+ } else if ($requestedqtype == '_all_') {
+ $sqlqtypetest = '';
+ $params = array();
+ $title = get_string('reportforallqtypes', 'report_questioninstances');
} else {
- $sqlqtypetest = '= ?';
+ $sqlqtypetest = 'WHERE qtype = ?';
$params = array($requestedqtype);
+ $title = get_string('reportforqtype', 'report_questioninstances', $QTYPES[$requestedqtype]->local_name());
}
- // Get all the role_capabilities rows for this capability - that is, all
- // role definitions, and all role overrides.
+ // Get the question counts, and all the context information, for each
+ // context. That is, rows of these results can be used as $context objects.
$counts = $DB->get_records_sql("
SELECT qc.contextid, count(1) as numquestions, sum(hidden) as numhidden, con.id, con.contextlevel, con.instanceid, con.path, con.depth
FROM {question} q
JOIN {question_categories} qc ON q.category = qc.id
JOIN {context} con ON con.id = qc.contextid
- WHERE qtype $sqlqtypetest
+ $sqlqtypetest
GROUP BY contextid, con.id, con.contextlevel, con.instanceid, con.path, con.depth
- ORDER BY numquestions DESC, numhidden ASC", $params);
+ ORDER BY numquestions DESC, numhidden ASC, con.contextlevel ASC, con.id ASC", $params);
// Print the report heading.
- print_heading(get_string('reportforqtype', 'report_questioninstances', $QTYPES[$requestedqtype]->local_name()));
+ print_heading($title);
- // Now, print the table of results.
- // TODO
- print_object($counts);
+ // Initialise the table.
+ $table = new stdClass;
+ $table->head = array(
+ get_string('context', 'role'),
+ get_string('totalquestions', 'report_questioninstances'),
+ get_string('visiblequestions', 'report_questioninstances'),
+ get_string('hiddenquestions', 'report_questioninstances'));
+ $table->data = array();
+ $table->class = '';
+ $table->id = '';
+
+ // Add the data for each row.
+ $totalquestions = 0;
+ $totalvisible = 0;
+ $totalhidden = 0;
+ foreach ($counts as $count) {
+ // Work out a link for editing questions in this context.
+ $contextname = print_context_name($count);
+ $url = question_edit_url($count);
+ if ($url) {
+ $contextname = '<a href="' . $url . '" title="' .
+ get_string('editquestionshere', 'report_questioninstances') .
+ '">' . $contextname . '</a>';
+ }
+
+ // Put the scores in the table.
+ $numvisible = $count->numquestions - $count->numhidden;
+ $table->data[] = array(
+ $contextname,
+ $count->numquestions,
+ $numvisible,
+ $count->numhidden);
+
+ // Update the totals.
+ $totalquestions += $count->numquestions;
+ $totalvisible += $numvisible;
+ $totalhidden += $count->numhidden;
+ }
+
+ // Add a totals row.
+ $table->data[] = array(
+ '<b>' . get_string('total') . '</b>',
+ $totalquestions,
+ $totalvisible,
+ $totalhidden);
+
+ // Print it.
+ print_table($table);
}
// Footer.