From: tjhunt Date: Tue, 9 Sep 2008 10:16:17 +0000 (+0000) Subject: MDL-16409 Make a new admin report to list all questions of a particular type, by... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3041a0dfed4df43975afcf4cdfe0b850ff60ae16;p=moodle.git MDL-16409 Make a new admin report to list all questions of a particular type, by context Partially done. This has the settings form, and queries the database for the right data, but does not format it correctly yet. --- diff --git a/admin/qtypes.php b/admin/qtypes.php index 5d1ae13c61..95060de8b6 100644 --- a/admin/qtypes.php +++ b/admin/qtypes.php @@ -10,6 +10,7 @@ require_login(); $systemcontext = get_context_instance(CONTEXT_SYSTEM); require_capability('moodle/question:config', $systemcontext); + $canviewreports = has_capability('moodle/site:viewreports', $systemcontext); admin_externalpage_setup('manageqtypes'); @@ -179,8 +180,12 @@ } else { $strcount = $counts[$qtypename]->numquestions; } - $row[] = '' . $strcount . ''; + if ($canviewreports) { + $row[] = '' . $strcount . ''; + } else { + $strcount; + } } else { $row[] = 0; } diff --git a/admin/report/questioninstances/index.php b/admin/report/questioninstances/index.php new file mode 100644 index 0000000000..56e65e03e9 --- /dev/null +++ b/admin/report/questioninstances/index.php @@ -0,0 +1,83 @@ +libdir.'/adminlib.php'); +require_once($CFG->libdir.'/questionlib.php'); + +// Check permissions. +require_login(); +$systemcontext = get_context_instance(CONTEXT_SYSTEM); +require_capability('moodle/site:viewreports', $systemcontext); + +// Get URL parameters. +$requestedqtype = optional_param('qtype', '', PARAM_SAFEDIR); + +// Log. +add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype); + +// Print the header. +admin_externalpage_setup('reportquestioninstances'); +admin_externalpage_print_header(); + +// Prepare the list of capabilites to choose from +$qtypechoices = array(); +foreach ($QTYPES as $qtype) { + $qtypechoices[$qtype->name()] = $qtype->local_name(); +} + +// Print the settings form. +print_box_start('generalbox boxwidthwide boxaligncenter centerpara'); +echo '
'; +print_heading(get_string('reportsettings', 'report_questioninstances')); +echo '

', get_string('intro', 'report_questioninstances') , '

'; +echo '

'; +choose_from_menu($qtypechoices, 'qtype', $requestedqtype); +echo '

'; +echo '

'; +echo '
'; +print_box_end(); + +// If we have a qtype to report on, generate the report. +if ($requestedqtype) { + + // Work out the bits needed for the SQL WHERE clauses. + if ($requestedqtype == 'missingtype') { + $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); + } else { + $sqlqtypetest = '= ?'; + $params = array($requestedqtype); + } + + // Get all the role_capabilities rows for this capability - that is, all + // role definitions, and all role overrides. + $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 + GROUP BY contextid, con.id, con.contextlevel, con.instanceid, con.path, con.depth + ORDER BY numquestions DESC, numhidden ASC", $params); + + // Print the report heading. + print_heading(get_string('reportforqtype', 'report_questioninstances', $QTYPES[$requestedqtype]->local_name())); + + // Now, print the table of results. + // TODO + print_object($counts); +} + +// Footer. +admin_externalpage_print_footer(); +?> diff --git a/lang/en_utf8/report_questioninstances.php b/lang/en_utf8/report_questioninstances.php new file mode 100644 index 0000000000..009bbb3c5c --- /dev/null +++ b/lang/en_utf8/report_questioninstances.php @@ -0,0 +1,8 @@ + diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 05adbb003b..9a424714bf 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -965,6 +965,12 @@ body#admin-modules table.generaltable td.c0 #admin-report-capability-index h3 { margin-bottom: 0; } +#admin-report-questioninstances-index #settingsform h2 { + margin-top: 0; +} +#admin-report-questioninstances-index #settingsform p { + margin-bottom: 0; +} #admin-roles-allowassign .buttons, #admin-roles-allowoverride .buttons,