Merge branch 'MDL-26098' of git://github.com/timhunt/moodle

This commit is contained in:
Petr Skoda 2011-01-31 19:25:41 +01:00
commit b6f3e4f8f0
7 changed files with 36 additions and 18 deletions

View File

@ -1058,7 +1058,7 @@ function close_window(e) {
} else {
e.returnValue = false;
}
self.close();
window.close();
}
/**
@ -1067,7 +1067,7 @@ function close_window(e) {
function close_window_reloading_opener() {
if (window.opener) {
window.opener.location.reload(1);
close_window();
close_window({});
// Intentionally, only try to close the window if there is some evidence we are in a popup.
}
}

View File

@ -1225,12 +1225,13 @@ function get_question_states(&$questions, $cmoptions, $attempt, $lastattemptid =
* @global object
* @param array $question The question to load the state for.
* @param object $cmoptions Options from the specifica activity module, e.g. $quiz.
* @param object $attempt The attempt for which the question sessions are to be loaded.
* @param integer $attemptid The question_attempts this is part of.
* @param integer $stateid The id of a specific state of this question.
* @return object the requested state. False on error.
*/
function question_load_specific_state($question, $cmoptions, $attempt, $stateid) {
function question_load_specific_state($question, $cmoptions, $attemptid, $stateid) {
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.manualcommentformat,
@ -1241,7 +1242,7 @@ function question_load_specific_state($question, $cmoptions, $attempt, $stateid)
AND sess.attemptid = st.attempt
AND st.question = ?
AND sess.questionid = st.question';
$state = $DB->get_record_sql($sql, array($stateid, $attempt->id, $question->id));
$state = $DB->get_record_sql($sql, array($stateid, $attemptid, $question->id));
if (!$state) {
return false;
}
@ -1258,7 +1259,7 @@ function question_load_specific_state($question, $cmoptions, $attempt, $stateid)
AND sess.questionid = st.question
AND st.event IN ('.QUESTION_EVENTS_GRADED.') '.
'ORDER BY st.seq_number DESC';
$gradedstates = $DB->get_records_sql($sql, array($state->seq_number, $attempt->id, $question->id), 0, 1);
$gradedstates = $DB->get_records_sql($sql, array($state->seq_number, $attemptid, $question->id), 0, 1);
if (empty($gradedstates)) {
$state->last_graded = clone($state);
} else {
@ -1534,7 +1535,7 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
$attempt->sumgrades -= $states[count($states)-1]->grade;
// Initialise the replaystate
$replaystate = question_load_specific_state($question, $cmoptions, $attempt, $states[0]->id);
$replaystate = question_load_specific_state($question, $cmoptions, $attempt->uniqueid, $states[0]->id);
$replaystate->sumpenalty = 0;
$replaystate->last_graded->sumpenalty = 0;

View File

@ -536,7 +536,7 @@ class quiz_attempt extends quiz {
public function load_specific_question_state($questionid, $stateid) {
global $DB;
$state = question_load_specific_state($this->questions[$questionid],
$this->quiz, $this->attempt, $stateid);
$this->quiz, $this->attempt->uniqueid, $stateid);
if ($state === false) {
throw new moodle_quiz_exception($this, 'invalidstateid');
}

View File

@ -2,9 +2,11 @@
/**
* This page allows the teacher to enter a manual grade for a particular question.
* This page is expected to only be used in a popup window.
* *
*
* @package mod
* @subpackage quiz
* @copyright gustav delius 2006
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
*/
require_once('../../config.php');
@ -61,7 +63,7 @@
$attemptobj->question_print_comment_fields($questionid, 'response');
?>
<div>
<input type="hidden" name="attempt" value="<?php echo $attemptobj->get_uniqueid(); ?>" />
<input type="hidden" name="attempt" value="<?php echo $attemptobj->get_attemptid(); ?>" />
<input type="hidden" name="question" value="<?php echo $questionid; ?>" />
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
</div>

View File

@ -917,7 +917,7 @@ function quiz_get_reviewoptions($quiz, $attempt, $context) {
// Show a link to the comment box only for closed attempts
if ($attempt->timefinish && has_capability('mod/quiz:grade', $context)) {
$options->questioncommentlink = '/mod/quiz/comment.php';
$options->questioncommentlink = new moodle_url('/mod/quiz/comment.php', array('attempt' => $attempt->id));
}
// Whether to display a response history.

View File

@ -20,6 +20,7 @@
$url->param('state', $stateid);
}
$PAGE->set_url($url);
$PAGE->set_pagelayout('popup');
$attemptobj = quiz_attempt::create($attemptid);
@ -27,23 +28,37 @@
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
$attemptobj->check_review_capability();
/// Create an object to manage all the other (non-roles) access rules.
$accessmanager = $attemptobj->get_access_manager(time());
$options = $attemptobj->get_review_options();
/// Permissions checks for normal users who do not have quiz:viewreports capability.
if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
/// Can't review during the attempt - send them back to the attempt page.
if (!$attemptobj->is_finished()) {
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('cannotreviewopen', 'quiz'));
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
die;
}
/// Can't review other users' attempts.
if (!$attemptobj->is_own_attempt()) {
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('notyourattempt', 'quiz'));
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
die;
}
/// Can't review unless Students may review -> Responses option is turned on.
if (!$options->responses) {
$accessmanager = $attemptobj->get_access_manager(time());
echo $OUTPUT->header();
echo $OUTPUT->notification($accessmanager->cannot_review_message($attemptobj->get_review_options()));
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
die;
}
}

View File

@ -957,7 +957,7 @@ class default_questiontype {
if (!empty($options->questioncommentlink)) {
$strcomment = get_string('commentorgrade', 'quiz');
$link = new moodle_url("$options->questioncommentlink?attempt=$state->attempt&question=$actualquestionid");
$link = new moodle_url($options->questioncommentlink, array('question' => $actualquestionid));
$action = new popup_action('click', $link, 'commentquestion', array('height' => 480, 'width' => 750));
$commentlink = $OUTPUT->container($OUTPUT->action_link($link, $strcomment, $action), 'commentlink');
}
@ -1087,12 +1087,11 @@ class default_questiontype {
return '';
}
$params = array('aid' => $state->attempt);
if (isset($question->randomquestionid)) {
$params['qid'] = $question->randomquestionid;
$actualquestionid = $question->randomquestionid;
$randomprefix = 'random' . $question->id . '-';
} else {
$params['qid'] = $question->id;
$actualquestionid = $question->id;
$randomprefix = '';
}
if ($options->history == 'all') {
@ -1101,7 +1100,8 @@ class default_questiontype {
$eventtest = 'event IN (' . QUESTION_EVENTS_GRADED . ')';
}
$states = $DB->get_records_select('question_states',
'attempt = :aid AND question = :qid AND ' . $eventtest, $params, 'seq_number ASC');
'attempt = :aid AND question = :qid AND ' . $eventtest,
array('aid' => $state->attempt, 'qid' => $actualquestionid), 'seq_number,id');
if (count($states) <= 1) {
return '';
}
@ -1131,7 +1131,7 @@ class default_questiontype {
$link = '<b>' . $st->seq_number . '</b>';
} else if (isset($options->questionreviewlink)) {
$reviewlink = new moodle_url($options->questionreviewlink);
$reviewlink->params(array('state'=>$st->id,'question'=>$question->id));
$reviewlink->params(array('state' => $st->id,'question' => $actualquestionid));
$link = new moodle_url($reviewlink);
$action = new popup_action('click', $link, 'reviewquestion', array('height' => 450, 'width' => 650));
$link = $OUTPUT->action_link($link, $st->seq_number, $action, array('title'=>$strreviewquestion));