Index: mod/quiz/tabs.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/tabs.php,v
retrieving revision 1.33
diff -u -r1.33 tabs.php
--- mod/quiz/tabs.php 20 Nov 2008 06:59:12 -0000 1.33
+++ mod/quiz/tabs.php 24 Nov 2008 13:15:49 -0000
@@ -49,44 +49,25 @@
if ($currenttab == 'info' && count($row) == 1) {
// Don't show only an info tab (e.g. to students).
} else {
+ //$reports is passed in from report.php
$tabs[] = $row;
}
if ($currenttab == 'reports' and isset($mode)) {
$activated[] = 'reports';
- // Standard reports we want to show first.
- $reportrs = $DB->get_recordset('quiz_report', null, 'displayorder DESC', 'id, name');
- // Reports that are restricted by capability.
- $reportrestrictions = array(
- 'regrade' => 'mod/quiz:grade',
- 'grading' => 'mod/quiz:grade'
- );
- $reportdirs = get_list_of_plugins("mod/quiz/report");
- //order the reports tab in descending order of displayorder
- $reportlist = array();
- foreach ($reportrs as $key => $rs) {
- if (in_array($rs->name, $reportdirs)) {
- $reportlist[]=$rs->name;
- }
- }
- //add any other reports on the end
- foreach ($reportdirs as $report) {
- if (!in_array($report, $reportlist)) {
- $reportlist[]=$report;
- }
- }
$row = array();
$currenttab = '';
+
+ $reportlist = quiz_report_list($context);
+
foreach ($reportlist as $report) {
- if (!isset($reportrestrictions[$report]) || has_capability($reportrestrictions[$report], $context)) {
- $row[] = new tabobject($report, "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id&mode=$report",
- get_string($report, 'quiz_'.$report));
- if ($report == $mode) {
- $currenttab = $report;
- }
+ $row[] = new tabobject($report, "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id&mode=$report",
+ get_string($report, 'quiz_'.$report));
+ if ($report == $mode) {
+ $currenttab = $report;
}
}
$tabs[] = $row;
Index: mod/quiz/review.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/review.php,v
retrieving revision 1.83
diff -u -r1.83 review.php
--- mod/quiz/review.php 26 Sep 2008 10:49:31 -0000 1.83
+++ mod/quiz/review.php 24 Nov 2008 13:15:49 -0000
@@ -9,6 +9,7 @@
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
+ require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
$attemptid = required_param('attempt', PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
Index: mod/quiz/version.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/version.php,v
retrieving revision 1.137
diff -u -r1.137 version.php
--- mod/quiz/version.php 26 Aug 2008 01:09:23 -0000 1.137
+++ mod/quiz/version.php 24 Nov 2008 13:15:49 -0000
@@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2008082600; // The (date) version of this module
+$module->version = 2008112101; // The (date) version of this module
$module->requires = 2008072401; // Requires this Moodle version
$module->cron = 0; // How often should cron check this module (seconds)?
Index: mod/quiz/report.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report.php,v
retrieving revision 1.50
diff -u -r1.50 report.php
--- mod/quiz/report.php 24 Jun 2008 08:59:29 -0000 1.50
+++ mod/quiz/report.php 24 Nov 2008 13:15:49 -0000
@@ -9,7 +9,7 @@
$id = optional_param('id',0,PARAM_INT); // Course Module ID, or
$q = optional_param('q',0,PARAM_INT); // quiz ID
- $mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode
+ $mode = optional_param('mode', '', PARAM_ALPHA); // Report mode
if ($id) {
if (! $cm = get_coursemodule_from_id('quiz', $id)) {
@@ -36,10 +36,20 @@
}
}
+
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
- require_capability('mod/quiz:viewreports', $context);
-
+
+ $reportlist = quiz_report_list($context);
+ if (count($reportlist)==0){
+ print_error('erroraccessingreport', 'quiz');
+ }
+ if ($mode == ''){
+ $mode = reset($reportlist);//first element in array
+ } elseif (!in_array($mode, $reportlist)){
+ print_error('erroraccessingreport', 'quiz');
+ }
+
// if no questions have been set up yet redirect to edit.php
if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
redirect('edit.php?cmid='.$cm->id);
Index: mod/quiz/report/statistics/db/install.xml
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/statistics/db/install.xml,v
retrieving revision 1.6
diff -u -r1.6 install.xml
--- mod/quiz/report/statistics/db/install.xml 10 Nov 2008 11:56:37 -0000 1.6
+++ mod/quiz/report/statistics/db/install.xml 24 Nov 2008 13:15:57 -0000
@@ -1,5 +1,5 @@
-
@@ -64,4 +64,11 @@
+
+
+
+
+
+
+
\ No newline at end of file
Index: mod/quiz/report/statistics/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/statistics/db/upgrade.php,v
retrieving revision 1.7
diff -u -r1.7 upgrade.php
--- mod/quiz/report/statistics/db/upgrade.php 10 Nov 2008 11:56:37 -0000 1.7
+++ mod/quiz/report/statistics/db/upgrade.php 24 Nov 2008 13:15:57 -0000
@@ -134,6 +134,11 @@
}
}
}
+
+
+ if ($result && $oldversion < 2008112100) {
+ $result = $result && $DB->set_field('quiz_report', 'capability', 'quizreport/statistics:view', array('name'=>'statistics'));
+ }
return $result;
}
Index: mod/quiz/report/reportlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/reportlib.php,v
retrieving revision 1.36
diff -u -r1.36 reportlib.php
--- mod/quiz/report/reportlib.php 21 Oct 2008 05:45:39 -0000 1.36
+++ mod/quiz/report/reportlib.php 24 Nov 2008 13:15:51 -0000
@@ -343,4 +343,45 @@
}
return $grade.'%';
}
+/**
+ * Returns an array of reports to which the current user has access to.
+ * Reports are ordered as they should be for display in tabs.
+ */
+function quiz_report_list($context){
+ global $DB;
+ static $reportlist = null;
+ if (!is_null($reportlist)){
+ return $reportlist;
+ }
+ $reports = $DB->get_records('quiz_report', null, 'displayorder DESC', 'name, capability');
+
+ $reportdirs = get_list_of_plugins("mod/quiz/report");
+ //order the reports tab in descending order of displayorder
+ $reportcaps = array();
+ if ($reports){
+ foreach ($reports as $key => $obj) {
+ if (in_array($obj->name, $reportdirs)) {
+ $reportcaps[$obj->name]=$obj->capability;
+ }
+ }
+ }
+
+ //add any other reports on the end
+ foreach ($reportdirs as $reportname) {
+ if (!in_array($reportname, $reportcaps)) {
+ $reportcaps[$reportname]= null;
+ }
+ }
+ $reportlist = array();
+ foreach ($reportcaps as $name => $capability){
+ if (empty($capability)){
+ $capability = 'mod/quiz:viewreports';
+ }
+ if (has_capability($capability, $context)){
+ $reportlist[] = $name;
+ }
+ }
+ return $reportlist;
+}
+
?>
Index: lang/en_utf8/quiz_statistics.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/quiz_statistics.php,v
retrieving revision 1.17
diff -u -r1.17 quiz_statistics.php
--- lang/en_utf8/quiz_statistics.php 10 Nov 2008 11:56:37 -0000 1.17
+++ lang/en_utf8/quiz_statistics.php 24 Nov 2008 13:15:41 -0000
@@ -3,6 +3,8 @@
$string['statistics'] = 'Statistics';
+$string['statistics:view'] = 'View statistics report';
+$string['statistics:componentname'] = 'Quiz statistics report';
$string['statisticsreport'] = 'Statistics report';
$string['calculatefrom'] = 'Calculate statistics from';
Index: lang/en_utf8/quiz.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/quiz.php,v
retrieving revision 1.117
diff -u -r1.117 quiz.php
--- lang/en_utf8/quiz.php 23 Nov 2008 11:09:28 -0000 1.117
+++ lang/en_utf8/quiz.php 24 Nov 2008 13:15:41 -0000
@@ -253,6 +253,7 @@
$string['emailnotifysubject'] = '$a->studentname has completed quiz $a->quizname';
$string['empty'] = 'Empty';
$string['endtest'] = 'End test ...';
+$string['erroraccessingreport'] = 'You cannot access this report';
$string['errorinquestion'] = 'Error in question';
$string['errormissingquestion'] = 'Error: The system is missing the question with id $a';
$string['errornotnumbers'] = 'Error - answers must be numeric';
@@ -518,6 +519,7 @@
$string['quiz:ignoretimelimits'] = 'Ignores time limit on quizzes';
$string['quiz:manage'] = 'Manage quizzes';
$string['quiz:preview'] = 'Preview quizzes';
+$string['quiz:regrade'] = 'Regrade quiz attempts';
$string['quiz:view'] = 'View quiz information';
$string['quiz:viewreports'] = 'View quiz reports';
$string['quizavailable'] = 'The quiz is available until: $a';
Index: mod/quiz/db/access.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/db/access.php,v
retrieving revision 1.10
diff -u -r1.10 access.php
--- mod/quiz/db/access.php 13 Aug 2008 07:05:42 -0000 1.10
+++ mod/quiz/db/access.php 24 Nov 2008 13:15:49 -0000
@@ -51,7 +51,7 @@
)
),
- // Manually grade and comment on student attempts at a question, and regrade quizzes.
+ // Manually grade and comment on student attempts at a question.
'mod/quiz:grade' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
@@ -63,6 +63,19 @@
)
),
+ // Regrade quizzes.
+ 'mod/quiz:regrade' => array(
+ 'riskbitmask' => RISK_SPAM | RISK_XSS,
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'admin' => CAP_ALLOW
+ ),
+ 'clonepermissionsfrom' => 'mod/quiz:grade'
+ ),
+
// View the quiz reports.
'mod/quiz:viewreports' => array(
'riskbitmask' => RISK_PERSONAL,
Index: mod/quiz/db/install.xml
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/db/install.xml,v
retrieving revision 1.16
diff -u -r1.16 install.xml
--- mod/quiz/db/install.xml 15 Aug 2008 11:15:08 -0000 1.16
+++ mod/quiz/db/install.xml 24 Nov 2008 13:15:51 -0000
@@ -1,5 +1,5 @@
-
@@ -112,7 +112,8 @@
-
+
+
@@ -140,7 +141,6 @@
-
Index: mod/quiz/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/db/upgrade.php,v
retrieving revision 1.27
diff -u -r1.27 upgrade.php
--- mod/quiz/db/upgrade.php 17 Sep 2008 05:24:30 -0000 1.27
+++ mod/quiz/db/upgrade.php 24 Nov 2008 13:15:51 -0000
@@ -196,6 +196,21 @@
// question type, this is now a no-op.
upgrade_mod_savepoint($result, 2008082600, 'quiz');
}
+
+ if ($result && $oldversion < 2008112101) {
+
+ /// Define field lastcron to be added to quiz_report
+ $table = new xmldb_table('quiz_report');
+ $field = new xmldb_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'cron');
+
+ /// Conditionally launch add field lastcron
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ /// quiz savepoint reached
+ upgrade_mod_savepoint($result, 2008112101, 'quiz');
+ }
return $result;
}
Index: mod/quiz/report/statistics/statistics_graph.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/statistics/statistics_graph.php,v
retrieving revision 1.3
diff -u -r1.3 statistics_graph.php
--- mod/quiz/report/statistics/statistics_graph.php 15 Sep 2008 09:16:57 -0000 1.3
+++ mod/quiz/report/statistics/statistics_graph.php 24 Nov 2008 13:15:57 -0000
@@ -32,7 +32,7 @@
}
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-require_capability('mod/quiz:viewreports', $modcontext);
+require_capability('quizreport/statistics:view', $modcontext);
$line = new graph(800,600);
$line->parameter['title'] = '';
Index: mod/quiz/report/statistics/version.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/statistics/version.php,v
retrieving revision 1.7
diff -u -r1.7 version.php
--- mod/quiz/report/statistics/version.php 10 Nov 2008 11:56:37 -0000 1.7
+++ mod/quiz/report/statistics/version.php 24 Nov 2008 13:15:57 -0000
@@ -1,4 +1,4 @@
version = 2008111000; // The (date) version of this module
+$plugin->version = 2008112100; // The (date) version of this module
?>
\ No newline at end of file
Index: mod/quiz/report/overview/report.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/overview/report.php,v
retrieving revision 1.161
diff -u -r1.161 report.php
--- mod/quiz/report/overview/report.php 13 Nov 2008 08:41:01 -0000 1.161
+++ mod/quiz/report/overview/report.php 24 Nov 2008 13:15:57 -0000
@@ -278,7 +278,7 @@
$headers = array();
if (!$table->is_downloading()) { //do not print notices when downloading
//regrade buttons
- if (has_capability('mod/quiz:grade', $this->context)){
+ if (has_capability('mod/quiz:regrade', $this->context)){
$countregradeneeded = $this->count_regrade_all_needed($quiz, $groupstudents);
if ($currentgroup){
$a= new object();
@@ -359,7 +359,7 @@
$headers[] = $header;
}
}
- if (!$table->is_downloading() && has_capability('mod/quiz:grade', $this->context) && $regradedattempts){
+ if (!$table->is_downloading() && has_capability('mod/quiz:regrade', $this->context) && $regradedattempts){
$columns[] = 'regraded';
$headers[] = get_string('regrade', 'quiz_overview');
}
@@ -424,7 +424,7 @@
*/
function regrade_all($dry, $quiz, $groupstudents){
global $DB;
- if (!has_capability('mod/quiz:grade', $this->context)) {
+ if (!has_capability('mod/quiz:regrade', $this->context)) {
notify(get_string('regradenotallowed', 'quiz'));
return true;
}
@@ -507,7 +507,7 @@
}
function regrade_all_needed($quiz, $groupstudents){
global $DB;
- if (!has_capability('mod/quiz:grade', $this->context)) {
+ if (!has_capability('mod/quiz:regrade', $this->context)) {
notify(get_string('regradenotallowed', 'quiz'));
return;
}
@@ -636,7 +636,7 @@
}
function regrade_selected_attempts($quiz, $attemptids, $groupstudents){
global $DB;
- require_capability('mod/quiz:grade', $this->context);
+ require_capability('mod/quiz:regrade', $this->context);
if ($groupstudents){
list($usql, $params) = $DB->get_in_or_equal($groupstudents);
$where = "qa.userid $usql AND ";
Index: mod/quiz/report/overview/overview_table.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/overview/overview_table.php,v
retrieving revision 1.15
diff -u -r1.15 overview_table.php
--- mod/quiz/report/overview/overview_table.php 24 Sep 2008 10:22:57 -0000 1.15
+++ mod/quiz/report/overview/overview_table.php 24 Nov 2008 13:15:54 -0000
@@ -94,7 +94,7 @@
echo ''.
get_string('selectnone', 'quiz').' ';
echo ' ';
- if (has_capability('mod/quiz:grade', $this->context)){
+ if (has_capability('mod/quiz:regrade', $this->context)){
echo '';
}
echo '';
@@ -317,12 +317,12 @@
}
}
$this->gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt');
- if (has_capability('mod/quiz:grade', $this->context)){
+ if (has_capability('mod/quiz:regrade', $this->context)){
$this->regradedqs = quiz_get_regraded_qs($attemptids);
}
} else {
$this->gradedstatesbyattempt = quiz_get_newgraded_states($this->sql, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt');
- if (has_capability('mod/quiz:grade', $this->context)){
+ if (has_capability('mod/quiz:regrade', $this->context)){
$this->regradedqs = quiz_get_regraded_qs($this->sql);
}
}
Index: mod/quiz/report/overview/overviewsettings_form.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/overview/overviewsettings_form.php,v
retrieving revision 1.10
diff -u -r1.10 overviewsettings_form.php
--- mod/quiz/report/overview/overviewsettings_form.php 13 Nov 2008 08:41:01 -0000 1.10
+++ mod/quiz/report/overview/overviewsettings_form.php 24 Nov 2008 13:15:54 -0000
@@ -37,7 +37,7 @@
$gm = ''.quiz_get_grading_option_name($this->_customdata['quiz']->grademethod).'';
$showattemptsgrp[] =& $mform->createElement('advcheckbox', 'qmfilter', get_string('showattempts', 'quiz_overview'), get_string('optonlygradedattempts', 'quiz_overview', $gm), null, array(0,1));
}
- if (has_capability('mod/quiz:grade', $this->_customdata['context'])){
+ if (has_capability('mod/quiz:regrade', $this->_customdata['context'])){
$showattemptsgrp[] =& $mform->createElement('advcheckbox', 'regradefilter', get_string('showattempts', 'quiz_overview'), get_string('optonlyregradedattempts', 'quiz_overview'), null, array(0,1));
}
if ($showattemptsgrp){
Index: lib/accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.546
diff -u -r1.546 accesslib.php
--- lib/accesslib.php 24 Nov 2008 07:27:11 -0000 1.546
+++ lib/accesslib.php 24 Nov 2008 13:15:49 -0000
@@ -3053,6 +3053,10 @@
$defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/access.php';
$varprefix = $compparts[0].'_'.$compparts[1];
+ } else if ($compparts[0] == 'quizreport') {
+ $defpath = $CFG->dirroot.'/mod/quiz/report/'.$compparts[1].'/db/access.php';
+ $varprefix = $compparts[0].'_'.$compparts[1];
+
} else {
$defpath = $CFG->dirroot.'/'.$component.'/db/access.php';
$varprefix = str_replace('/', '_', $component);
@@ -3888,6 +3892,10 @@
$string = get_string($stringname, 'gradereport_'.$componentname);
break;
+ case 'quizreport':
+ $string = get_string($stringname, 'quiz_'.$componentname);
+ break;
+
default:
$string = get_string($stringname);
break;
@@ -3944,7 +3952,12 @@
break;
case CONTEXT_MODULE:
- $string = get_string('modulename', basename($component));
+ if (preg_match('|^quizreport/([a-z_]*)|', $component, $matches)){
+ $langname = 'quiz_'.$matches[1];
+ $string = get_string($matches[1].':componentname', $langname);
+ } else {
+ $string = get_string('modulename', basename($component));
+ }
break;
case CONTEXT_BLOCK:
Index: mod/quiz/report/statistics/db/access.php
===================================================================
RCS file: mod/quiz/report/statistics/db/access.php
diff -N mod/quiz/report/statistics/db/access.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ mod/quiz/report/statistics/db/access.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,20 @@
+ array(
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'admin' => CAP_ALLOW
+ ),
+ 'clonepermissionsfrom' => 'mod/quiz:viewreports'
+ )
+);
+?>
+