quiz: MDL-6085 when editing a question from various places like a preview attempt or review screen, don't use a popup, instead take advantage of the fact that question.php now takes a returnurl. Merged from MOODLE_19_STABLE.

And MDL-17568 minor niggles with new queston navigation:
* The bit that scrolls down to the question you just submitted in adaptive mode was not working with random questions.
* Teachers reviewing an open attempt were shown the qusetions as editable, not read only!
This commit is contained in:
tjhunt
2008-12-10 06:26:47 +00:00
parent f94824dbbe
commit aafdb447bf
9 changed files with 92 additions and 46 deletions
+1 -1
View File
@@ -138,7 +138,7 @@
/// Print all the questions
foreach ($attemptobj->get_question_ids($page) as $id) {
$attemptobj->print_question($id);
$attemptobj->print_question($id, false, $attemptobj->attempt_url($id, $page));
}
/// Print a link to the next page.
+19 -3
View File
@@ -470,7 +470,7 @@ class quiz_attempt extends quiz {
return $this->attempt->userid;
}
/** @return boolean whether this attemp has been finished (true) or is still in progress (false). */
/** @return boolean whether this attempt has been finished (true) or is still in progress (false). */
public function is_finished() {
return $this->attempt->timefinish != 0;
}
@@ -641,6 +641,10 @@ class quiz_attempt extends quiz {
$this->page_and_question_fragment($questionid, $page, $showall);
}
public function set_this_page_url($url) {
$this->quiz->thispageurl = $url;
}
// Bits of content =====================================================================
public function get_html_head_contributions($page = 'all') {
return get_html_head_contributions($this->get_question_ids($page),
@@ -660,12 +664,24 @@ class quiz_attempt extends quiz {
echo '</div>';
}
public function print_question($id) {
if ($this->is_finished()) {
/**
* Wrapper round print_question from lib/questionlib.php.
*
* @param integer $id the id of a question in this quiz attempt.
* @param boolean $reviewing is the being printed on an attempt or a review page.
* @param string $thispageurl the URL of the page this question is being printed on.
*/
public function print_question($id, $reviewing, $thispageurl = '') {
if ($reviewing) {
$options = $this->get_review_options();
} else {
$options = $this->get_render_options($this->states[$id]);
}
if ($thispageurl) {
$this->quiz->thispageurl = $thispageurl;
} else {
unset($thispageurl);
}
print_question($this->questions[$id], $this->states[$id], $this->questions[$id]->_number,
$this->quiz, $options);
}
+1
View File
@@ -408,6 +408,7 @@ class quiz_grading_report extends quiz_default_report {
// Print the question, without showing any previous comment.
$copy = $state->manualcomment;
$state->manualcomment = '';
$options->noeditlink = true;
print_question($question, $state, '', $quiz, $options);
// The print the comment and grade fields, putting back the previous comment.
+1 -1
View File
@@ -224,7 +224,7 @@
$lastpage = $attemptobj->is_last_page($page);
}
foreach ($attemptobj->get_question_ids($thispage) as $id) {
$attemptobj->print_question($id);
$attemptobj->print_question($id, true, $attemptobj->review_url($id, $page, $showall));
}
/// Close form if we opened it.
+9 -4
View File
@@ -50,6 +50,10 @@
$attemptobj->load_specific_question_state($questionid, $stateid);
}
/// Work out the base URL of this page.
$baseurl = $CFG->wwwroot . '/mod/quiz/reviewquestion.php?attempt=' .
$attemptobj->get_attemptid() . '&amp;question=' . $questionid;
/// Log this review.
add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'reviewquestion.php?attempt=' .
$attemptobj->get_attemptid() . '&question=' . $questionid .
@@ -86,9 +90,7 @@
/// Other attempts at the quiz.
if ($attemptobj->has_capability('mod/quiz:viewreports')) {
$attemptlist = $attemptobj->links_to_other_attempts(
'reviewquestion.php?attempt=' . $attemptobj->get_attemptid() .
'&amp;question=' . $questionid);
$attemptlist = $attemptobj->links_to_other_attempts($baseurl);
if ($attemptlist) {
$rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') .
'</th><td class="cell">' . $attemptlist . '</td></tr>';
@@ -110,7 +112,10 @@
}
/// Print the question in the requested state.
$attemptobj->print_question($questionid);
if ($stateid) {
$baseurl .= '&amp;state=' . $stateid;
}
$attemptobj->print_question($questionid, true, $baseurl);
/// Finish the page
print_footer();
+1
View File
@@ -189,6 +189,7 @@
// TODO: should not use quiz-specific function here
$options = quiz_get_renderoptions($quiz, $attempt, $context, $curstate);
$options->noeditlink = true;
// Fill in the correct responses (unless the question is in readonly mode)
if ($fillcorrect && !$options->readonly) {
+1 -17
View File
@@ -45,24 +45,8 @@ class description_qtype extends default_questiontype {
global $CFG;
$isfinished = question_state_is_graded($state->last_graded) || $state->event == QUESTION_EVENTCLOSE;
if (!empty($cmoptions->id)) {
$cm = get_coursemodule_from_instance('quiz', $cmoptions->id);
$cmorcourseid = '&amp;cmid='.$cm->id;
} else if (!empty($cmoptions->course)) {
$cmorcourseid = '&amp;courseid='.$cmoptions->course;
} else {
print_error('missingcourseorcmid', 'question');
}
// For editing teachers print a link to an editing popup window
$editlink = '';
if (question_has_capability_on($question, 'edit')) {
$stredit = get_string('edit');
$linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" />';
$editlink = link_to_popup_window('/question/question.php?inpopup=1&amp;id=' .
$question->id . $cmorcourseid, 'editquestion',
$linktext, false, false, $stredit, '', true);
}
$editlink = $this->get_question_edit_link($question, $cmoptions, $options);
$questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);
$image = get_question_image($question);
+1 -1
View File
@@ -3,7 +3,7 @@
* print_question() method.
*/
?>
<div id="q<?php echo $question->id; ?>" class="que <?php echo $question->qtype; ?> clearfix">
<div id="q<?php echo $actualquestionid; ?>" class="que <?php echo $question->qtype; ?> clearfix">
<div class="info">
<h2 class="no"><span class="accesshide">Question </span><?php echo $number;
if ($editlink) { ?>
+58 -19
View File
@@ -892,28 +892,23 @@ class default_questiontype {
global $CFG;
$isgraded = question_state_is_graded($state->last_graded);
// get the context so we can determine whether some extra links
// should be shown.
// Get the context we should use to check permissions.
if (!empty($cmoptions->id)) {
$cm = get_coursemodule_from_instance('quiz', $cmoptions->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$cmorcourseid = '&amp;cmid='.$cm->id;
$context = get_context_instance(CONTEXT_MODULE, $cmoptions->id);
} else if (!empty($cmoptions->course)) {
$context = get_context_instance(CONTEXT_COURSE, $cmoptions->course);
$cmorcourseid = '&amp;courseid='.$cmoptions->course;
} else {
print_error('missingcourseorcmid', 'question');
$context = null;
}
if (isset($question->randomquestionid)) {
$actualquestionid = $question->randomquestionid;
} else {
$actualquestionid = $question->id;
}
// For editing teachers print a link to an editing popup window
$editlink = '';
if (question_has_capability_on($question, 'edit')) {
$stredit = get_string('edit');
$linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" />';
$editlink = link_to_popup_window('/question/question.php?inpopup=1&amp;id=' .
$question->id . $cmorcourseid, 'editquestion',
$linktext, false, false, $stredit, '', true);
}
$editlink = $this->get_question_edit_link($question, $cmoptions, $options);
$generalfeedback = '';
if ($isgraded && $options->generalfeedback) {
@@ -936,11 +931,12 @@ class default_questiontype {
$comment = $state->manualcomment;
$commentlink = '';
if (isset($options->questioncommentlink) && $context && has_capability('mod/quiz:grade', $context)) {
if (!empty($options->questioncommentlink)) {
$strcomment = get_string('commentorgrade', 'quiz');
$question_to_comment = isset($question->randomquestionid) ? $question->randomquestionid : $question->id;
$commentlink = '<div class="commentlink">'.link_to_popup_window ($options->questioncommentlink.'?attempt='.$state->attempt.'&amp;question='.$question_to_comment,
'commentquestion', $strcomment, 450, 650, $strcomment, 'none', true).'</div>';
$commentlink = link_to_popup_window($options->questioncommentlink .
'?attempt=' . $state->attempt . '&amp;question=' . $actualquestionid,
'commentquestion', $strcomment, 450, 650, $strcomment, 'none', true);
$commentlink = '<div class="commentlink">'. $commentlink .'</div>';
}
$history = $this->history($question, $state, $number, $cmoptions, $options);
@@ -1009,6 +1005,49 @@ class default_questiontype {
'" alt="' . get_string('flagthisquestion', 'question') . '" />';
}
/**
* Get a link to an edit icon for this question, if the current user is allowed
* to edit it.
*
* @param object $question the question object.
* @param object $cmoptions the options from the module. If $cmoptions->thispageurl is set
* then the link will be to edit the question in this browser window, then return to
* $cmoptions->thispageurl. Otherwise the link will be to edit in a popup.
* @return string the HTML of the link, or nothing it the currenty user is not allowed to edit.
*/
function get_question_edit_link($question, $cmoptions, $options) {
global $CFG;
/// Is this user allowed to edit this question?
if (!empty($options->noeditlink) || !question_has_capability_on($question, 'edit')) {
return '';
}
/// Work out the right URL.
$linkurl = '/question/question.php?id=' . $question->id;
if (!empty($cmoptions->id)) {
$linkurl .= '&amp;cmid=' . $cmoptions->id;
} else if (!empty($cmoptions->course)) {
$linkurl .= '&amp;courseid=' . $cmoptions->course;
} else {
error('Need to provide courseid or cmid to get_question_edit_link.');
}
/// Work out the contents of the link.
$stredit = get_string('edit');
$linktext = '<img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . $stredit . '" />';
if (!empty($cmoptions->thispageurl)) {
/// The module allow editing in the same window, print an ordinary link.
return '<a href="' . $CFG->wwwroot . $linkurl . '&amp;returnurl=' . urlencode($cmoptions->thispageurl) .
'" title="' . $stredit . '">' . $linktext . '</a>';
} else {
/// We have to edit in a pop-up.
return link_to_popup_window($linkurl . '&amp;inpopup=1', 'editquestion',
$linktext, false, false, $stredit, '', true);
}
}
/**
* Print history of responses
*