Skip to content
Browse files

javascript MDL-26098 make the review this question in a previous stat…

…e popup work.
  • Loading branch information...
1 parent 1db6b9b commit 3708abd0f23d41cc472e6f6f8579ddbba51d758f @timhunt timhunt committed Jan 29, 2011
Showing with 27 additions and 11 deletions.
  1. +6 −5 lib/questionlib.php
  2. +1 −1 mod/quiz/attemptlib.php
  3. +15 −0 mod/quiz/reviewquestion.php
  4. +5 −5 question/type/questiontype.php
View
11 lib/questionlib.php
@@ -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
2 mod/quiz/attemptlib.php
@@ -536,7 +536,7 @@ public function preload_question_states() {
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
15 mod/quiz/reviewquestion.php
@@ -20,30 +20,45 @@
$url->param('state', $stateid);
}
$PAGE->set_url($url);
+ $PAGE->set_pagelayout('popup');
$attemptobj = quiz_attempt::create($attemptid);
/// Check login.
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
10 question/type/questiontype.php
@@ -1087,12 +1087,11 @@ function history($question, $state, $number, $cmoptions, $options) {
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 @@ function history($question, $state, $number, $cmoptions, $options) {
$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 @@ function history($question, $state, $number, $cmoptions, $options) {
$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));

0 comments on commit 3708abd

Please sign in to comment.
Something went wrong with that request. Please try again.