Index: mod/quiz/report/reportlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/reportlib.php,v
retrieving revision 1.32
diff -u -r1.32 reportlib.php
--- mod/quiz/report/reportlib.php 11 Sep 2008 12:48:09 -0000 1.32
+++ mod/quiz/report/reportlib.php 22 Sep 2008 08:43:52 -0000
@@ -26,7 +26,7 @@
"{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 @@
"{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,15 @@
$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);
+
+ $closedorgradedevents = array_unique(array_merge(
+ explode(',', QUESTION_EVENTS_GRADED),
+ explode(',', QUESTION_EVENTS_CLOSED)));
+ list($closedorgraded_sql, $closedorgraded_params) = $DB->get_in_or_equal($closedorgradedevents);
- $params = array_merge($params, $u_params, $q_params);
+ $params = array_merge($params, $u_params, $closedorgraded_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 +152,8 @@
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 $closedorgraded_sql AND
qs.question $q_sql
GROUP BY qs.question";
return $DB->get_records_sql($sql, $params);
Index: mod/quiz/report/grading/report.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/report/grading/report.php,v
retrieving revision 1.46
diff -u -r1.46 report.php
--- mod/quiz/report/grading/report.php 18 Sep 2008 07:39:10 -0000 1.46
+++ mod/quiz/report/grading/report.php 22 Sep 2008 08:43:53 -0000
@@ -160,8 +160,6 @@
groups_print_activity_menu($this->cm, $this->viewurl->out(false, array('userid'=>0, 'attemptid'=>0)));
}
- echo '
' . quiz_num_attempt_summary($quiz, $cm, true, $currentgroup) . '
';
-
if(empty($this->users)) {
if ($currentgroup){
notify(get_string('nostudentsingroup'));
@@ -438,17 +436,16 @@
'{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,14 @@
$where = "WHERE u.id $usql ";
$params = array_merge($params, $u_params);
}
+
+ $closedorgradedevents = array_unique(array_merge(
+ explode(',', QUESTION_EVENTS_GRADED),
+ explode(',', QUESTION_EVENTS_CLOSED)));
+ list($closedorgraded_sql, $closedorgraded_params) = $DB->get_in_or_equal($closedorgradedevents);
+ $params = array_merge($params, $closedorgraded_params);
+ $where .= ' AND qs.event '.$closedorgraded_sql;
+
$where .= ' AND u.id = qa.userid AND qa.quiz = ?';
$params[] = $quizid;
Index: lib/questionlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/questionlib.php,v
retrieving revision 1.169
diff -u -r1.169 questionlib.php
--- lib/questionlib.php 18 Sep 2008 07:39:10 -0000 1.169
+++ lib/questionlib.php 22 Sep 2008 08:43:52 -0000
@@ -37,9 +37,11 @@
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);
/**#@-*/
@@ -1082,7 +1084,7 @@
* @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 +1101,6 @@
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 +1108,9 @@
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 +1240,11 @@
* @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 +1254,11 @@
* @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));
}
Index: lib/simpletest/testquestionlib.php
===================================================================
RCS file: lib/simpletest/testquestionlib.php
diff -N lib/simpletest/testquestionlib.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/simpletest/testquestionlib.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,117 @@
+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));
+
+ }
+}
+
+?>