Merge branch 'MDL-44492' of git://github.com/timhunt/moodle
This commit is contained in:
@@ -709,6 +709,7 @@ $string['reportregrade'] = 'Regrade attempts';
|
||||
$string['reportresponses'] = 'Detailed responses';
|
||||
$string['reports'] = 'Reports';
|
||||
$string['reportshowonly'] = 'Show only attempts';
|
||||
$string['reportshowonlyfinished'] = 'Show at most one finished attempt per user ({$a})';
|
||||
$string['reportsimplestat'] = 'Simple statistics';
|
||||
$string['reportusersall'] = 'all users who have attempted the quiz';
|
||||
$string['reportuserswith'] = 'enrolled users who have attempted the quiz';
|
||||
|
||||
@@ -972,6 +972,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
|
||||
// Highlight the highest grade if appropriate.
|
||||
if ($viewobj->overallstats && !$attemptobj->is_preview()
|
||||
&& $viewobj->numattempts > 1 && !is_null($viewobj->mygrade)
|
||||
&& $attemptobj->get_state() == quiz_attempt::FINISHED
|
||||
&& $attemptgrade == $viewobj->mygrade
|
||||
&& $quiz->grademethod == QUIZ_GRADEHIGHEST) {
|
||||
$table->rowclasses[$attemptobj->get_attempt_number()] = 'bestrow';
|
||||
|
||||
@@ -89,8 +89,8 @@ abstract class mod_quiz_attempts_report_form extends moodleform {
|
||||
$gm = html_writer::tag('span',
|
||||
quiz_get_grading_option_name($this->_customdata['quiz']->grademethod),
|
||||
array('class' => 'highlight'));
|
||||
$mform->addElement('advcheckbox', 'onlygraded', get_string('reportshowonly', 'quiz'),
|
||||
get_string('optonlygradedattempts', 'quiz_overview', $gm));
|
||||
$mform->addElement('advcheckbox', 'onlygraded', '',
|
||||
get_string('reportshowonlyfinished', 'quiz', $gm));
|
||||
$mform->disabledIf('onlygraded', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
|
||||
$mform->disabledIf('onlygraded', 'statefinished', 'notchecked');
|
||||
}
|
||||
|
||||
@@ -272,12 +272,20 @@ class mod_quiz_attempts_report_options {
|
||||
$this->onlygraded = false;
|
||||
}
|
||||
|
||||
if ($this->onlygraded) {
|
||||
$this->states = array(quiz_attempt::FINISHED);
|
||||
if (!$this->is_showing_finished_attempts()) {
|
||||
$this->onlygraded = false;
|
||||
}
|
||||
|
||||
if ($this->pagesize < 1) {
|
||||
$this->pagesize = quiz_attempts_report::DEFAULT_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the options are such that finished attempts are being shown.
|
||||
* @return boolean
|
||||
*/
|
||||
protected function is_showing_finished_attempts() {
|
||||
return $this->states === null || in_array(quiz_attempt::FINISHED, $this->states);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +425,8 @@ abstract class quiz_attempts_report_table extends table_sql {
|
||||
$params = array('quizid' => $this->quiz->id);
|
||||
|
||||
if ($this->qmsubselect && $this->options->onlygraded) {
|
||||
$from .= " AND $this->qmsubselect";
|
||||
$from .= " AND (quiza.state <> :finishedstate OR $this->qmsubselect)";
|
||||
$params['finishedstate'] = quiz_attempt::FINISHED;
|
||||
}
|
||||
|
||||
switch ($this->options->attempts) {
|
||||
|
||||
@@ -41,7 +41,6 @@ $string['optallattempts'] = 'all attempts';
|
||||
$string['optallstudents'] = 'all {$a} who have or have not attempted the quiz';
|
||||
$string['optattemptsonly'] = '{$a} who have attempted the quiz';
|
||||
$string['optnoattemptsonly'] = '{$a} who have not attempted the quiz';
|
||||
$string['optonlygradedattempts'] = 'that are graded for each user ({$a})';
|
||||
$string['optonlyregradedattempts'] = 'that have been regraded / are marked as needing regrading';
|
||||
$string['overview'] = 'Grades';
|
||||
$string['overviewdownload'] = 'Overview download';
|
||||
|
||||
@@ -38,7 +38,7 @@ class quiz_overview_settings_form extends mod_quiz_attempts_report_form {
|
||||
|
||||
protected function other_attempt_fields(MoodleQuickForm $mform) {
|
||||
if (has_capability('mod/quiz:regrade', $this->_customdata['context'])) {
|
||||
$mform->addElement('advcheckbox', 'onlyregraded', '',
|
||||
$mform->addElement('advcheckbox', 'onlyregraded', get_string('reportshowonly', 'quiz'),
|
||||
get_string('optonlyregradedattempts', 'quiz_overview'));
|
||||
$mform->disabledIf('onlyregraded', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,10 @@ class quiz_overview_options extends mod_quiz_attempts_report_options {
|
||||
public function resolve_dependencies() {
|
||||
parent::resolve_dependencies();
|
||||
|
||||
if ($this->attempts == quiz_attempts_report::ENROLLED_WITHOUT) {
|
||||
$this->onlyregraded = false;
|
||||
}
|
||||
|
||||
if (!$this->usercanseegrades) {
|
||||
$this->slotmarks = false;
|
||||
}
|
||||
|
||||
@@ -121,13 +121,6 @@ class quiz_overview_report extends quiz_attempts_report {
|
||||
// Construct the SQL.
|
||||
$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') .
|
||||
' AS uniqueid, ';
|
||||
if ($this->qmsubselect) {
|
||||
$fields .=
|
||||
"(CASE " .
|
||||
" WHEN {$this->qmsubselect} THEN 1" .
|
||||
" ELSE 0 " .
|
||||
"END) AS gradedattempt, ";
|
||||
}
|
||||
|
||||
list($fields, $from, $where, $params) = $table->base_sql($allowed);
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for the quiz overview report.
|
||||
*
|
||||
* @package quiz_overview
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
|
||||
require_once($CFG->dirroot . '/mod/quiz/report/default.php');
|
||||
require_once($CFG->dirroot . '/mod/quiz/report/overview/report.php');
|
||||
|
||||
|
||||
/**
|
||||
* Tests for the quiz overview report.
|
||||
*
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quiz_overview_report_testcase extends advanced_testcase {
|
||||
|
||||
public function test_report_sql() {
|
||||
global $DB, $SITE;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$quizgenerator = $generator->get_plugin_generator('mod_quiz');
|
||||
$quiz = $quizgenerator->create_instance(array('course' => $SITE->id,
|
||||
'grademethod' => QUIZ_GRADEHIGHEST, 'grade' => 100.0, 'sumgrades' => 10.0,
|
||||
'attempts' => 10));
|
||||
|
||||
$student1 = $generator->create_user();
|
||||
$student2 = $generator->create_user();
|
||||
$student3 = $generator->create_user();
|
||||
|
||||
$quizid = 123;
|
||||
$timestamp = 1234567890;
|
||||
|
||||
// The test data.
|
||||
$fields = array('quiz', 'userid', 'attempt', 'sumgrades', 'state');
|
||||
$attempts = array(
|
||||
array($quiz->id, $student1->id, 1, 0.0, quiz_attempt::FINISHED),
|
||||
array($quiz->id, $student1->id, 2, 5.0, quiz_attempt::FINISHED),
|
||||
array($quiz->id, $student1->id, 3, 8.0, quiz_attempt::FINISHED),
|
||||
array($quiz->id, $student1->id, 4, null, quiz_attempt::ABANDONED),
|
||||
array($quiz->id, $student1->id, 5, null, quiz_attempt::IN_PROGRESS),
|
||||
array($quiz->id, $student2->id, 1, null, quiz_attempt::ABANDONED),
|
||||
array($quiz->id, $student2->id, 2, null, quiz_attempt::ABANDONED),
|
||||
array($quiz->id, $student2->id, 3, 7.0, quiz_attempt::FINISHED),
|
||||
array($quiz->id, $student2->id, 4, null, quiz_attempt::ABANDONED),
|
||||
array($quiz->id, $student2->id, 5, null, quiz_attempt::ABANDONED),
|
||||
);
|
||||
|
||||
// Load it in to quiz attempts table.
|
||||
$uniqueid = 1;
|
||||
foreach ($attempts as $attempt) {
|
||||
$data = array_combine($fields, $attempt);
|
||||
$data['timestart'] = $timestamp + 3600 * $data['attempt'];
|
||||
$data['timemodifed'] = $data['timestart'];
|
||||
if ($data['state'] == quiz_attempt::FINISHED) {
|
||||
$data['timefinish'] = $data['timestart'] + 600;
|
||||
$data['timemodifed'] = $data['timefinish'];
|
||||
}
|
||||
$data['layout'] = ''; // Not used, but cannot be null.
|
||||
$data['uniqueid'] = $uniqueid++;
|
||||
$data['preview'] = 0;
|
||||
$DB->insert_record('quiz_attempts', $data);
|
||||
}
|
||||
|
||||
// Actually getting the SQL to run is quit hard. Do a minimal set up of
|
||||
// some objects.
|
||||
$context = context_module::instance($quiz->cmid);
|
||||
$cm = get_coursemodule_from_id('quiz', $quiz->cmid);
|
||||
$qmsubselect = quiz_report_qm_filter_select($quiz);
|
||||
$reportstudents = array($student1->id, $student2->id, $student3->id);
|
||||
|
||||
// Set the options.
|
||||
$reportoptions = new quiz_overview_options('overview', $quiz, $cm, null);
|
||||
$reportoptions->attempts = quiz_attempts_report::ENROLLED_ALL;
|
||||
$reportoptions->onlygraded = true;
|
||||
$reportoptions->states = array(quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, quiz_attempt::FINISHED);
|
||||
|
||||
// Now do a minimal set-up of the table class.
|
||||
$table = new quiz_overview_table($quiz, $context, $qmsubselect, $reportoptions,
|
||||
array(), $reportstudents, array(1), null);
|
||||
$table->define_columns(array('attempt'));
|
||||
$table->sortable(true, 'uniqueid');
|
||||
$table->define_baseurl(new moodle_url('/mod/quiz/report.php'));
|
||||
$table->setup();
|
||||
|
||||
// Run the query.
|
||||
list($fields, $from, $where, $params) = $table->base_sql($reportstudents);
|
||||
$table->set_sql($fields, $from, $where, $params);
|
||||
$table->query_db(30, false);
|
||||
|
||||
// Verify what was returned: Student 1's best and in progress attempts.
|
||||
// Stuent 2's finshed attempt, and Student 3 with no attempt.
|
||||
// The array key is {student id}#{attempt number}.
|
||||
$this->assertEquals(4, count($table->rawdata));
|
||||
$this->assertArrayHasKey($student1->id . '#3', $table->rawdata);
|
||||
$this->assertEquals(1, $table->rawdata[$student1->id . '#3']->gradedattempt);
|
||||
$this->assertArrayHasKey($student1->id . '#3', $table->rawdata);
|
||||
$this->assertEquals(0, $table->rawdata[$student1->id . '#5']->gradedattempt);
|
||||
$this->assertArrayHasKey($student2->id . '#3', $table->rawdata);
|
||||
$this->assertEquals(1, $table->rawdata[$student2->id . '#3']->gradedattempt);
|
||||
$this->assertArrayHasKey($student3->id . '#0', $table->rawdata);
|
||||
$this->assertEquals(0, $table->rawdata[$student3->id . '#0']->gradedattempt);
|
||||
}
|
||||
}
|
||||
@@ -156,27 +156,33 @@ function quiz_report_qm_filter_select($quiz, $quizattemptsalias = 'quiza') {
|
||||
function quiz_report_grade_method_sql($grademethod, $quizattemptsalias = 'quiza') {
|
||||
switch ($grademethod) {
|
||||
case QUIZ_GRADEHIGHEST :
|
||||
return "NOT EXISTS (SELECT 1 FROM {quiz_attempts} qa2
|
||||
return "($quizattemptsalias.state = 'finished' AND NOT EXISTS (
|
||||
SELECT 1 FROM {quiz_attempts} qa2
|
||||
WHERE qa2.quiz = $quizattemptsalias.quiz AND
|
||||
qa2.userid = $quizattemptsalias.userid AND (
|
||||
qa2.userid = $quizattemptsalias.userid AND
|
||||
qa2.state = 'finished' AND (
|
||||
COALESCE(qa2.sumgrades, 0) > COALESCE($quizattemptsalias.sumgrades, 0) OR
|
||||
(COALESCE(qa2.sumgrades, 0) = COALESCE($quizattemptsalias.sumgrades, 0) AND qa2.attempt < $quizattemptsalias.attempt)
|
||||
))";
|
||||
)))";
|
||||
|
||||
case QUIZ_GRADEAVERAGE :
|
||||
return '';
|
||||
|
||||
case QUIZ_ATTEMPTFIRST :
|
||||
return "NOT EXISTS (SELECT 1 FROM {quiz_attempts} qa2
|
||||
return "($quizattemptsalias.state = 'finished' AND NOT EXISTS (
|
||||
SELECT 1 FROM {quiz_attempts} qa2
|
||||
WHERE qa2.quiz = $quizattemptsalias.quiz AND
|
||||
qa2.userid = $quizattemptsalias.userid AND
|
||||
qa2.attempt < $quizattemptsalias.attempt)";
|
||||
qa2.state = 'finished' AND
|
||||
qa2.attempt < $quizattemptsalias.attempt))";
|
||||
|
||||
case QUIZ_ATTEMPTLAST :
|
||||
return "NOT EXISTS (SELECT 1 FROM {quiz_attempts} qa2
|
||||
return "($quizattemptsalias.state = 'finished' AND NOT EXISTS (
|
||||
SELECT 1 FROM {quiz_attempts} qa2
|
||||
WHERE qa2.quiz = $quizattemptsalias.quiz AND
|
||||
qa2.userid = $quizattemptsalias.userid AND
|
||||
qa2.attempt > $quizattemptsalias.attempt)";
|
||||
qa2.state = 'finished' AND
|
||||
qa2.attempt > $quizattemptsalias.attempt))";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-12
@@ -311,8 +311,9 @@ div.editq div.question div.content .singlequestion a .questiontext {
|
||||
#page-mod-quiz-view #page .quizattemptsummary td p {
|
||||
margin-top: 0;
|
||||
}
|
||||
table.quizattemptsummary .bestrow td {
|
||||
background-color: #e8e8e8;
|
||||
#page-mod-quiz-view table.quizattemptsummary tr.bestrow td {
|
||||
border-color: #bce8f1;
|
||||
background-color: #d9edf7;
|
||||
}
|
||||
table.quizattemptsummary .noreviewmessage {
|
||||
color: gray;
|
||||
@@ -347,9 +348,10 @@ table.quizattemptsummary .noreviewmessage {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.mod-quiz .gradedattempt,
|
||||
.mod-quiz tr.gradedattempt td {
|
||||
background-color: #e8e8e8;
|
||||
body.path-mod-quiz .gradedattempt,
|
||||
body.path-mod-quiz table tbody tr.gradedattempt > td {
|
||||
border-color: #bce8f1;
|
||||
background-color: #d9edf7;
|
||||
}
|
||||
|
||||
.quizattemptcounts {
|
||||
@@ -431,8 +433,8 @@ table.quizreviewsummary td.cell {
|
||||
background-color: #fcc;
|
||||
}
|
||||
#page-mod-quiz-report .highlight {
|
||||
border : medium solid yellow;
|
||||
background-color: lightYellow;
|
||||
border: 1px solid #bce8f1;
|
||||
background-color: #d9edf7;
|
||||
}
|
||||
#page-mod-quiz-report .negcovar {
|
||||
border : medium solid pink;
|
||||
@@ -443,11 +445,8 @@ table.quizreviewsummary td.cell {
|
||||
#page-mod-quiz-report .gradetheselink {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
#page-mod-quiz-report .mform fieldset {
|
||||
margin: 0;
|
||||
}
|
||||
#page-mod-quiz-report fieldset.felement.fgroup {
|
||||
margin: 0;
|
||||
#page-mod-quiz-report .mform fieldset.fgroup span label {
|
||||
margin-right: 14px;
|
||||
}
|
||||
#page-mod-quiz-report table th {
|
||||
white-space: normal;
|
||||
|
||||
@@ -95,16 +95,17 @@ class mod_quiz_reportlib_testcase extends advanced_testcase {
|
||||
$fakeattempt->userid = 123;
|
||||
$fakeattempt->quiz = 456;
|
||||
$fakeattempt->layout = '1,2,0,3,4,0,5';
|
||||
$fakeattempt->state = quiz_attempt::FINISHED;
|
||||
|
||||
// We intentionally insert these in a funny order, to test the SQL better.
|
||||
// The test data is:
|
||||
// id | quizid | user | attempt | sumgrades
|
||||
// ----------------------------------------
|
||||
// 4 | 456 | 123 | 1 | 30
|
||||
// 2 | 456 | 123 | 2 | 50
|
||||
// 1 | 456 | 123 | 3 | 50
|
||||
// 3 | 456 | 123 | 4 | null
|
||||
// 5 | 456 | 1 | 1 | 100
|
||||
// id | quizid | user | attempt | sumgrades | state
|
||||
// ---------------------------------------------------
|
||||
// 4 | 456 | 123 | 1 | 30 | finished
|
||||
// 2 | 456 | 123 | 2 | 50 | finished
|
||||
// 1 | 456 | 123 | 3 | 50 | finished
|
||||
// 3 | 456 | 123 | 4 | null | inprogress
|
||||
// 5 | 456 | 1 | 1 | 100 | finished
|
||||
// layout is only given because it has a not-null constraint.
|
||||
// uniqueid values are meaningless, but that column has a unique constraint.
|
||||
|
||||
@@ -121,11 +122,13 @@ class mod_quiz_reportlib_testcase extends advanced_testcase {
|
||||
$fakeattempt->attempt = 4;
|
||||
$fakeattempt->sumgrades = null;
|
||||
$fakeattempt->uniqueid = 39;
|
||||
$fakeattempt->state = quiz_attempt::IN_PROGRESS;
|
||||
$DB->insert_record('quiz_attempts', $fakeattempt);
|
||||
|
||||
$fakeattempt->attempt = 1;
|
||||
$fakeattempt->sumgrades = 30;
|
||||
$fakeattempt->uniqueid = 52;
|
||||
$fakeattempt->state = quiz_attempt::FINISHED;
|
||||
$DB->insert_record('quiz_attempts', $fakeattempt);
|
||||
|
||||
$fakeattempt->attempt = 1;
|
||||
@@ -151,7 +154,7 @@ class mod_quiz_reportlib_testcase extends advanced_testcase {
|
||||
. quiz_report_qm_filter_select($quiz), array(123, 456));
|
||||
$this->assertEquals(1, count($lastattempt));
|
||||
$lastattempt = reset($lastattempt);
|
||||
$this->assertEquals(4, $lastattempt->attempt);
|
||||
$this->assertEquals(3, $lastattempt->attempt);
|
||||
|
||||
$quiz->attempts = 0;
|
||||
$quiz->grademethod = QUIZ_GRADEHIGHEST;
|
||||
|
||||
Reference in New Issue
Block a user