diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index ff753664095..9c29e313006 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -608,7 +608,7 @@ class quiz_attempt { public function get_display_options($reviewing) { if ($reviewing) { if (is_null($this->reviewoptions)) { - $this->reviewoptions = quiz_get_reviewoptions($this->get_quiz(), + $this->reviewoptions = quiz_get_review_options($this->get_quiz(), $this->attempt, $this->quizobj->get_context()); } return $this->reviewoptions; diff --git a/mod/quiz/comment.php b/mod/quiz/comment.php index ea8da3a8454..e92633dbe5c 100644 --- a/mod/quiz/comment.php +++ b/mod/quiz/comment.php @@ -1,4 +1,20 @@ . + /** * 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. @@ -6,65 +22,59 @@ * @package mod * @subpackage quiz * @copyright gustav delius 2006 - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - require_once('../../config.php'); - require_once('locallib.php'); +require_once('../../config.php'); +require_once('locallib.php'); - $attemptid = required_param('attempt', PARAM_INT); // attempt id - $questionid = required_param('question', PARAM_INT); // question id +$attemptid = required_param('attempt', PARAM_INT); // attempt id +$slot = required_param('slot', PARAM_INT); // question number in attempt - $PAGE->set_url('/mod/quiz/comment.php', array('attempt'=>$attemptid, 'question'=>$questionid)); +$PAGE->set_url('/mod/quiz/comment.php', array('attempt' => $attemptid, 'slot' => $slot)); - $attemptobj = quiz_attempt::create($attemptid); +$attemptobj = quiz_attempt::create($attemptid); -/// Can only grade finished attempts. - if (!$attemptobj->is_finished()) { - print_error('attemptclosed', 'quiz'); +// Can only grade finished attempts. +if (!$attemptobj->is_finished()) { + print_error('attemptclosed', 'quiz'); +} + +// Check login and permissions. +require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm()); +$attemptobj->require_capability('mod/quiz:grade'); + +// Log this action. +add_to_log($attemptobj->get_courseid(), 'quiz', 'manualgrade', 'comment.php?attempt=' . + $attemptobj->get_attemptid() . '&slot=' . $slot, + $attemptobj->get_quizid(), $attemptobj->get_cmid()); + +// Print the page header +$PAGE->set_pagelayout('popup'); +echo $OUTPUT->header(); +echo $OUTPUT->heading(format_string($attemptobj->get_question_name($slot))); + +// Process any data that was submitted. +if (data_submitted() && confirm_sesskey()) { + if (optional_param('submit', false, PARAM_BOOL)) { + // TODO better error handling. + $transaction = $DB->start_delegated_transaction(); + $attemptobj->process_all_actions(time()); + $transaction->allow_commit(); + echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); + close_window(2, true); + die; } +} -/// Check login and permissions. - require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm()); - $attemptobj->require_capability('mod/quiz:grade'); - -/// Load the questions and states. - $questionids = array($questionid); - $attemptobj->load_questions($questionids); - $attemptobj->load_question_states($questionids); - -/// Log this action. - add_to_log($attemptobj->get_courseid(), 'quiz', 'manualgrade', 'comment.php?attempt=' . - $attemptobj->get_attemptid() . '&question=' . $questionid, - $attemptobj->get_quizid(), $attemptobj->get_cmid()); - -/// Print the page header - $PAGE->set_pagelayout('popup'); - echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($attemptobj->get_question($questionid)->name)); - -/// Process any data that was submitted. - if ($data = data_submitted() and confirm_sesskey()) { - $error = $attemptobj->process_comment($questionid, - $data->response['comment'], FORMAT_HTML, $data->response['grade']); - - /// If success, notify and print a close button. - if (!is_string($error)) { - echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); - close_window(2, true); - } - - /// Otherwise, display the error and fall throug to re-display the form. - echo $OUTPUT->notification($error); - } - -/// Print the comment form. - echo '
'; -/// End of the page. - echo $OUTPUT->footer(); -?> +// End of the page. +echo $OUTPUT->footer(); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 1b632e26411..5e2be4629d9 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -800,7 +800,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, } } - $options = quiz_get_reviewoptions($quiz, $attempt, $context); + $options = quiz_get_review_options($quiz, $attempt, $context); $tmpactivity = new stdClass; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index f2d44b69c14..a7be9779320 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1041,18 +1041,20 @@ function quiz_attempt_state($quiz, $attempt) { * * @return mod_quiz_display_options */ -function quiz_get_reviewoptions($quiz, $attempt, $context) { +function quiz_get_review_options($quiz, $attempt, $context) { $options = mod_quiz_display_options::make_from_quiz($quiz, quiz_attempt_state($quiz, $attempt)); $options->readonly = true; $options->flags = quiz_get_flag_option($attempt, $context); - $options->questionreviewlink = '/mod/quiz/reviewquestion.php?attempt=' . $attempt->id; + $options->questionreviewlink = new moodle_url('/mod/quiz/reviewquestion.php', + array('attempt' => $attempt->id)); // Show a link to the comment box only for closed attempts if ($attempt->timefinish && !$attempt->preview && !is_null($context) && has_capability('mod/quiz:grade', $context)) { $options->manualcomment = question_display_options::VISIBLE; - $options->manualcommentlink = '/mod/quiz/comment.php?attempt=' . $attempt->id; + $options->manualcommentlink = new moodle_url('/mod/quiz/comment.php', + array('attempt' => $attempt->id)); } if (!is_null($context) && !$attempt->preview && has_capability('mod/quiz:viewreports', $context) && diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index 4cf45499e32..1b91b5494c3 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -381,7 +381,7 @@ class quiz_grading_report extends quiz_default_report { // with only one question there is only one entry in this array $state = &$states[$question->id]; - $options = quiz_get_reviewoptions($quiz, $attempt, $context); + $options = quiz_get_review_options($quiz, $attempt, $context); unset($options->questioncommentlink); $options->readonly = 1; diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index b6c7ffbccef..8d7dd43efde 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -27,7 +27,7 @@ class quiz_overview_report extends quiz_default_report { $fakeattempt->preview = false; $fakeattempt->timefinish = $quiz->timeopen; $fakeattempt->userid = 0; - $reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $this->context); + $reviewoptions = quiz_get_review_options($quiz, $fakeattempt, $this->context); $showgrades = quiz_has_grades($quiz) && $reviewoptions->scores; $download = optional_param('download', '', PARAM_ALPHA); diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index b73ccfd7517..57c38e355ed 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -27,7 +27,7 @@ class quiz_responses_report extends quiz_default_report { $fakeattempt->preview = false; $fakeattempt->timefinish = $quiz->timeopen; $fakeattempt->userid = 0; - $reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $context); + $reviewoptions = quiz_get_review_options($quiz, $fakeattempt, $context); $showgrades = quiz_has_grades($quiz) && $reviewoptions->scores; $download = optional_param('download', '', PARAM_ALPHA); diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 465280430b4..8164a5fb87f 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -218,7 +218,7 @@ if ($attempts) { // One row for each attempt foreach ($attempts as $attempt) { - $attemptoptions = quiz_get_reviewoptions($quiz, $attempt, $context); + $attemptoptions = quiz_get_review_options($quiz, $attempt, $context); $row = array(); // Add the attempt number, making it a link, if appropriate. diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index 630db9f265c..b4c80ce28d0 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -71,7 +71,7 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { $commentfield = $qa->get_behaviour_field_name('comment'); - list($commenttext, $commentformat) = $this->qa->get_manual_comment(); + list($commenttext, $commentformat) = $qa->get_manual_comment(); $comment = print_textarea(can_use_html_editor(), 10, 80, null, null, $commentfield, $commenttext, 0, true); $comment = html_writer::tag('div', html_writer::tag('div', html_writer::tag('label', get_string('comment', 'question'), array('for' => $commentfield)), @@ -136,10 +136,9 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { $output .= get_string('commentx', 'question', $qa->get_behaviour()->format_comment()); } if ($options->manualcommentlink) { - $strcomment = get_string('commentormark', 'question'); - $link = link_to_popup_window($options->manualcommentlink . - '&slot=' . $qa->get_slot(), - 'commentquestion', $strcomment, 600, 800, $strcomment, 'none', true); + $url = new moodle_url($options->manualcommentlink, array('slot' => $qa->get_slot())); + $link = $this->output->action_link($url, get_string('commentormark', 'question'), + new popup_action('click', $url, 'commentquestion', array('width' => 600, 'height' => 800))); $output .= html_writer::tag('div', $link, array('class' => 'commentlink')); } return $output; diff --git a/question/todo/diffstat.txt b/question/todo/diffstat.txt index 5c23e9ddbed..c6a9d394e97 100644 --- a/question/todo/diffstat.txt +++ b/question/todo/diffstat.txt @@ -70,8 +70,8 @@ DONE mod/quiz/attempt.php | 742 ++---- DONE mod/quiz/attempt_close_js.php | 27 - DONE mod/quiz/attemptlib.php | 1219 +++++++++ mod/quiz/backuplib.php | 16 +- - mod/quiz/comment.php | 171 +- - mod/quiz/config.html | 304 ++- +DONE mod/quiz/comment.php | 171 +- +DONE mod/quiz/config.html | 304 ++- DONE mod/quiz/db/access.php | 19 +- DONE mod/quiz/db/install.xml | 191 +- DONE mod/quiz/db/mysql.php | 1163 --------