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);
/**#@-*/
* @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
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 <= ?
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 {
* @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));
}
/**
* @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));
}
--- /dev/null
+<?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));
+
+ }
+}
+
+?>
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'));
'{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=?';
$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;
"{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 " .
"{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();
$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,
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);