mirror of
https://github.com/moodle/moodle.git
synced 2025-03-17 22:20:00 +01:00
MDL-16529 "Only include closed attempts in manual grade counts"
This commit is contained in:
parent
92b2bd00f8
commit
8b92c1e3f6
@ -37,9 +37,14 @@ define('QUESTION_EVENTMANUALGRADE', '9'); // Grade was entered by teacher
|
||||
define('QUESTION_EVENTS_GRADED', QUESTION_EVENTGRADE.','.
|
||||
QUESTION_EVENTCLOSEANDGRADE.','.
|
||||
QUESTION_EVENTMANUALGRADE);
|
||||
global $QUESTION_EVENTS_GRADED;
|
||||
$QUESTION_EVENTS_GRADED = array(QUESTION_EVENTGRADE, QUESTION_EVENTCLOSEANDGRADE,
|
||||
QUESTION_EVENTMANUALGRADE);
|
||||
|
||||
|
||||
define('QUESTION_EVENTS_CLOSED', QUESTION_EVENTCLOSE.','.
|
||||
QUESTION_EVENTCLOSEANDGRADE.','.
|
||||
QUESTION_EVENTMANUALGRADE);
|
||||
|
||||
define('QUESTION_EVENTS_CLOSED_OR_GRADED', QUESTION_EVENTGRADE.','.
|
||||
QUESTION_EVENTS_CLOSED);
|
||||
|
||||
/**#@-*/
|
||||
|
||||
@ -1082,7 +1087,7 @@ function get_question_states(&$questions, $cmoptions, $attempt, $lastattemptid =
|
||||
* @return object the requested state. False on error.
|
||||
*/
|
||||
function question_load_specific_state($question, $cmoptions, $attempt, $stateid) {
|
||||
global $DB, $QUESTION_EVENTS_GRADED;
|
||||
global $DB;
|
||||
// Load specified states for the question.
|
||||
// sess.sumpenalty is probably wrong here shoul really be a sum of penalties from before the one we are asking for.
|
||||
$sql = 'SELECT st.*, sess.sumpenalty, sess.manualcomment, sess.flagged, sess.id as questionsessionid
|
||||
@ -1099,7 +1104,6 @@ function question_load_specific_state($question, $cmoptions, $attempt, $stateid)
|
||||
restore_question_state($question, $state);
|
||||
|
||||
// Load the most recent graded states for the questions before the specified one.
|
||||
list($eventinsql, $params) = $DB->get_in_or_equal($QUESTION_EVENTS_GRADED);
|
||||
$sql = 'SELECT st.*, sess.sumpenalty, sess.manualcomment, sess.flagged, sess.id as questionsessionid
|
||||
FROM {question_states} st, {question_sessions} sess
|
||||
WHERE st.seq_number <= ?
|
||||
@ -1107,10 +1111,9 @@ function question_load_specific_state($question, $cmoptions, $attempt, $stateid)
|
||||
AND sess.attemptid = st.attempt
|
||||
AND st.question = ?
|
||||
AND sess.questionid = st.question
|
||||
AND st.event ' . $eventinsql .
|
||||
AND st.event IN ('.QUESTION_EVENTS_GRADED.') '.
|
||||
'ORDER BY st.seq_number DESC';
|
||||
$gradedstates = $DB->get_records_sql($sql, array_merge(
|
||||
array($state->seq_number, $attempt->id, $question->id), $params), 0, 1);
|
||||
$gradedstates = $DB->get_records_sql($sql, array($state->seq_number, $attempt->id, $question->id), 0, 1);
|
||||
if (empty($gradedstates)) {
|
||||
$state->last_graded = clone($state);
|
||||
} else {
|
||||
@ -1240,8 +1243,11 @@ function save_question_session($question, $state) {
|
||||
* @param object $state
|
||||
*/
|
||||
function question_state_is_graded($state) {
|
||||
$gradedevents = explode(',', QUESTION_EVENTS_GRADED);
|
||||
return (in_array($state->event, $gradedevents));
|
||||
static $question_events_graded = array();
|
||||
if (!$question_events_graded){
|
||||
$question_events_graded = explode(',', QUESTION_EVENTS_GRADED);
|
||||
}
|
||||
return (in_array($state->event, $question_events_graded));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1251,9 +1257,11 @@ function question_state_is_graded($state) {
|
||||
* @param object $state
|
||||
*/
|
||||
function question_state_is_closed($state) {
|
||||
return ($state->event == QUESTION_EVENTCLOSE
|
||||
or $state->event == QUESTION_EVENTCLOSEANDGRADE
|
||||
or $state->event == QUESTION_EVENTMANUALGRADE);
|
||||
static $question_events_closed = array();
|
||||
if (!$question_events_closed){
|
||||
$question_events_closed = explode(',', QUESTION_EVENTS_CLOSED);
|
||||
}
|
||||
return (in_array($state->event, $question_events_closed));
|
||||
}
|
||||
|
||||
|
||||
|
117
lib/simpletest/testquestionlib.php
Normal file
117
lib/simpletest/testquestionlib.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program 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 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program 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: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Unit tests for (some of) ../questionlib.php.
|
||||
*
|
||||
* @copyright © 2006 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package question
|
||||
*/
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||
}
|
||||
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
|
||||
class questionlib_test extends MoodleUnitTestCase {
|
||||
|
||||
|
||||
function setUp() {
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
}
|
||||
|
||||
function test_question_state_is_closed() {
|
||||
$state = new object();
|
||||
$state->event = QUESTION_EVENTOPEN;
|
||||
$this->assertFalse(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTNAVIGATE;
|
||||
$this->assertFalse(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTSAVE;
|
||||
$this->assertFalse(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTGRADE;
|
||||
$this->assertFalse(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTDUPLICATE;
|
||||
$this->assertFalse(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTVALIDATE;
|
||||
$this->assertFalse(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTSUBMIT;
|
||||
$this->assertFalse(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTCLOSEANDGRADE;
|
||||
$this->assertTrue(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTCLOSE;
|
||||
$this->assertTrue(question_state_is_closed($state));
|
||||
|
||||
$state->event = QUESTION_EVENTMANUALGRADE;
|
||||
$this->assertTrue(question_state_is_closed($state));
|
||||
|
||||
}
|
||||
function test_question_state_is_graded() {
|
||||
$state = new object();
|
||||
$state->event = QUESTION_EVENTOPEN;
|
||||
$this->assertFalse(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTNAVIGATE;
|
||||
$this->assertFalse(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTSAVE;
|
||||
$this->assertFalse(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTDUPLICATE;
|
||||
$this->assertFalse(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTVALIDATE;
|
||||
$this->assertFalse(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTSUBMIT;
|
||||
$this->assertFalse(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTCLOSE;
|
||||
$this->assertFalse(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTCLOSEANDGRADE;
|
||||
$this->assertTrue(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTMANUALGRADE;
|
||||
$this->assertTrue(question_state_is_graded($state));
|
||||
|
||||
$state->event = QUESTION_EVENTGRADE;
|
||||
$this->assertTrue(question_state_is_graded($state));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -160,8 +160,6 @@ class quiz_grading_report extends quiz_default_report {
|
||||
groups_print_activity_menu($this->cm, $this->viewurl->out(false, array('userid'=>0, 'attemptid'=>0)));
|
||||
}
|
||||
|
||||
echo '<div class="quizattemptcounts">' . quiz_num_attempt_summary($quiz, $cm, true, $currentgroup) . '</div>';
|
||||
|
||||
if(empty($this->users)) {
|
||||
if ($currentgroup){
|
||||
notify(get_string('nostudentsingroup'));
|
||||
@ -438,17 +436,16 @@ class quiz_grading_report extends quiz_default_report {
|
||||
'{quiz_attempts} qa ';
|
||||
$params = array();
|
||||
|
||||
if (($wantstateevent|| $gradenextungraded || $gradeungraded) && $questionid){
|
||||
$from .= "LEFT JOIN {question_sessions} qns " .
|
||||
"ON (qns.attemptid = qa.uniqueid AND qns.questionid = ?) ";
|
||||
$params[] = $questionid;
|
||||
$from .= "LEFT JOIN {question_states} qs " .
|
||||
"ON (qs.id = qns.newgraded AND qs.question = ?) ";
|
||||
$params[] = $questionid;
|
||||
}
|
||||
$from .= "LEFT JOIN {question_sessions} qns " .
|
||||
"ON (qns.attemptid = qa.uniqueid AND qns.questionid = ?) ";
|
||||
$params[] = $questionid;
|
||||
$from .= "LEFT JOIN {question_states} qs " .
|
||||
"ON (qs.id = qns.newest AND qs.question = ?) ";
|
||||
$params[] = $questionid;
|
||||
|
||||
list($usql, $u_params) = $DB->get_in_or_equal(array_keys($this->users));
|
||||
if ($gradenextungraded || $gradeungraded) { // get ungraded attempts
|
||||
$where = "WHERE u.id $usql AND qs.event NOT IN (".QUESTION_EVENTS_GRADED.') ';
|
||||
$where = "WHERE u.id $usql AND qs.event IN (".QUESTION_EVENTS_GRADED.")";
|
||||
$params = array_merge($params, $u_params);
|
||||
} else if ($userid) { // get all the attempts for a specific user
|
||||
$where = 'WHERE u.id=?';
|
||||
@ -460,6 +457,8 @@ class quiz_grading_report extends quiz_default_report {
|
||||
$where = "WHERE u.id $usql ";
|
||||
$params = array_merge($params, $u_params);
|
||||
}
|
||||
|
||||
$where .= ' AND qs.event IN ('.QUESTION_EVENTS_CLOSED_OR_GRADED.')';
|
||||
|
||||
$where .= ' AND u.id = qa.userid AND qa.quiz = ?';
|
||||
$params[] = $quizid;
|
||||
|
@ -26,7 +26,7 @@ function quiz_get_newgraded_states($attemptidssql, $idxattemptq = true, $fields=
|
||||
"{question_sessions} qns, " .
|
||||
"{question_states} qs " .
|
||||
"WHERE qns.attemptid $usql AND " .
|
||||
"qns.newgraded = qs.id";
|
||||
"qns.newest = qs.id";
|
||||
$gradedstates = $DB->get_records_sql($gradedstatesql, $params);
|
||||
} else if ($attemptidssql && is_object($attemptidssql)){
|
||||
$gradedstatesql = "SELECT $fields FROM " .
|
||||
@ -35,7 +35,7 @@ function quiz_get_newgraded_states($attemptidssql, $idxattemptq = true, $fields=
|
||||
"{question_states} qs " .
|
||||
"WHERE qns.attemptid = qa.uniqueid AND " .
|
||||
$attemptidssql->where." AND ".
|
||||
"qns.newgraded = qs.id";
|
||||
"qns.newest = qs.id";
|
||||
$gradedstates = $DB->get_records_sql($gradedstatesql, $attemptidssql->params);
|
||||
} else {
|
||||
return array();
|
||||
@ -135,10 +135,10 @@ function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){
|
||||
$params = array($quiz->id);
|
||||
list($u_sql, $u_params) = $DB->get_in_or_equal($userids);
|
||||
list($q_sql, $q_params) = $DB->get_in_or_equal($questionids);
|
||||
|
||||
|
||||
$params = array_merge($params, $u_params, $q_params);
|
||||
$sql = "SELECT qs.question, COUNT(1) AS totalattempts,
|
||||
SUM(CASE WHEN (qs.event IN (".QUESTION_EVENTS_GRADED.")) THEN 1 ELSE 0 END) AS gradedattempts
|
||||
SUM(CASE WHEN (qs.event IN(".QUESTION_EVENTS_GRADED.")) THEN 1 ELSE 0 END) AS gradedattempts
|
||||
FROM
|
||||
{quiz_attempts} qa,
|
||||
{question_sessions} qns,
|
||||
@ -147,7 +147,8 @@ function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){
|
||||
qa.quiz = ? AND
|
||||
qa.userid $u_sql AND
|
||||
qns.attemptid = qa.uniqueid AND
|
||||
qns.newgraded = qs.id AND
|
||||
qns.newest = qs.id AND
|
||||
qs.event IN (".QUESTION_EVENTS_CLOSED_OR_GRADED.") AND
|
||||
qs.question $q_sql
|
||||
GROUP BY qs.question";
|
||||
return $DB->get_records_sql($sql, $params);
|
||||
|
Loading…
x
Reference in New Issue
Block a user