Permalink
Browse files

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

  • Loading branch information...
Sam Hemelryk
Sam Hemelryk committed Jun 8, 2011
2 parents f6bd0b9 + e84dacf commit 0b8dea80dcddbf6de2148846da382d8e799ee788
View
@@ -210,56 +210,16 @@ function question_context_has_any_questions($context) {
/**
* Returns list of 'allowed' grades for grade selection
* formatted suitably for dropdown box function
+ *
+ * @deprecated since 2.1. Use {@link question_bank::fraction_options()} or
+ * {@link question_bank::fraction_options_full()} instead.
+ *
* @return object ->gradeoptionsfull full array ->gradeoptions +ve only
*/
function get_grade_options() {
- // define basic array of grades. This list comprises all fractions of the form:
- // a. p/q for q <= 6, 0 <= p <= q
- // b. p/10 for 0 <= p <= 10
- // c. 1/q for 1 <= q <= 10
- // d. 1/20
- $grades = array(
- 1.0000000,
- 0.9000000,
- 0.8333333,
- 0.8000000,
- 0.7500000,
- 0.7000000,
- 0.6666667,
- 0.6000000,
- 0.5000000,
- 0.4000000,
- 0.3333333,
- 0.3000000,
- 0.2500000,
- 0.2000000,
- 0.1666667,
- 0.1428571,
- 0.1250000,
- 0.1111111,
- 0.1000000,
- 0.0500000,
- 0.0000000);
-
- // iterate through grades generating full range of options
- $gradeoptionsfull = array();
- $gradeoptions = array();
- foreach ($grades as $grade) {
- $percentage = 100 * $grade;
- $gradeoptions["$grade"] = $percentage . '%';
- $gradeoptionsfull["$grade"] = $percentage . '%';
- $gradeoptionsfull['' . (-$grade)] = (-$percentage) . '%';
- }
- $gradeoptionsfull['0'] = $gradeoptions['0'] = get_string('none');
-
- // sort lists
- arsort($gradeoptions, SORT_NUMERIC);
- arsort($gradeoptionsfull, SORT_NUMERIC);
-
- // construct return object
$grades = new stdClass();
- $grades->gradeoptions = $gradeoptions;
- $grades->gradeoptionsfull = $gradeoptionsfull;
+ $grades->gradeoptions = question_bank::fraction_options();
+ $grades->gradeoptionsfull = question_bank::fraction_options_full();
return $grades;
}
View
@@ -756,6 +756,20 @@ public function get_question_status($slot, $showcorrectness) {
return $this->quba->get_question_state_string($slot, $showcorrectness);
}
+ /**
+ * Return the grade obtained on a particular question, if the user is permitted
+ * to see it. You must previously have called load_question_states to load the
+ * state data about this question.
+ *
+ * @param int $slot the number used to identify this question within this attempt.
+ * @param bool $showcorrectness Whether right/partial/wrong states should
+ * be distinguised.
+ * @return string class name for this state.
+ */
+ public function get_question_state_class($slot, $showcorrectness) {
+ return $this->quba->get_question_state_class($slot, $showcorrectness);
+ }
+
/**
* Return the grade obtained on a particular question.
* You must previously have called load_question_states to load the state
@@ -1167,7 +1181,7 @@ public function get_question_buttons() {
$button = new quiz_nav_question_button();
$button->id = 'quiznavbutton' . $slot;
$button->number = $qa->get_question()->_number;
- $button->stateclass = $qa->get_state()->get_state_class($showcorrectness);
+ $button->stateclass = $qa->get_state_class($showcorrectness);
if (!$showcorrectness && $button->stateclass == 'notanswered') {
$button->stateclass = 'complete';
}
@@ -1226,7 +1240,7 @@ public function render_before_button_bits(mod_quiz_renderer $output) {
public function render_end_bits(mod_quiz_renderer $output) {
return html_writer::link($this->attemptobj->summary_url(),
- get_string('endtest', 'quiz'), array('id' => 'endtestlink')) .
+ get_string('endtest', 'quiz'), array('class' => 'endtestlink')) .
$output->countdown_timer() .
$this->render_restart_preview_link($output);
}
View
@@ -481,43 +481,38 @@ function quiz_set_grade($newgrade, $quiz) {
// Use a transaction, so that on those databases that support it, this is safer.
$transaction = $DB->start_delegated_transaction();
- try {
- // Update the quiz table.
- $DB->set_field('quiz', 'grade', $newgrade, array('id' => $quiz->instance));
-
- // Rescaling the other data is only possible if the old grade was non-zero.
- if ($quiz->grade > 1e-7) {
- global $CFG;
-
- $factor = $newgrade/$quiz->grade;
- $quiz->grade = $newgrade;
-
- // Update the quiz_grades table.
- $timemodified = time();
- $DB->execute("
- UPDATE {quiz_grades}
- SET grade = ? * grade, timemodified = ?
- WHERE quiz = ?
- ", array($factor, $timemodified, $quiz->id));
-
- // Update the quiz_feedback table.
- $DB->execute("
- UPDATE {quiz_feedback}
- SET mingrade = ? * mingrade, maxgrade = ? * maxgrade
- WHERE quizid = ?
- ", array($factor, $factor, $quiz->id));
- }
-
- // update grade item and send all grades to gradebook
- quiz_grade_item_update($quiz);
- quiz_update_grades($quiz);
+ // Update the quiz table.
+ $DB->set_field('quiz', 'grade', $newgrade, array('id' => $quiz->instance));
+
+ // Rescaling the other data is only possible if the old grade was non-zero.
+ if ($quiz->grade > 1e-7) {
+ global $CFG;
+
+ $factor = $newgrade/$quiz->grade;
+ $quiz->grade = $newgrade;
+
+ // Update the quiz_grades table.
+ $timemodified = time();
+ $DB->execute("
+ UPDATE {quiz_grades}
+ SET grade = ? * grade, timemodified = ?
+ WHERE quiz = ?
+ ", array($factor, $timemodified, $quiz->id));
+
+ // Update the quiz_feedback table.
+ $DB->execute("
+ UPDATE {quiz_feedback}
+ SET mingrade = ? * mingrade, maxgrade = ? * maxgrade
+ WHERE quizid = ?
+ ", array($factor, $factor, $quiz->id));
+ }
- $transaction->allow_commit();
- return true;
+ // update grade item and send all grades to gradebook
+ quiz_grade_item_update($quiz);
+ quiz_update_grades($quiz);
- } catch (Exception $e) {
- $transaction->rollback($e);
- }
+ $transaction->allow_commit();
+ return true;
}
/**
@@ -869,6 +864,9 @@ function quiz_question_edit_button($cmid, $question, $returnurl, $contentafteric
// Build the icon.
if ($action) {
+ if ($returnurl instanceof moodle_url) {
+ $returnurl = str_replace($CFG->wwwroot, '', $returnurl->out(false));
+ }
$questionparams = array('returnurl' => $returnurl, 'cmid' => $cmid, 'id' => $question->id);
$questionurl = new moodle_url("$CFG->wwwroot/question/question.php", $questionparams);
return '<a title="' . $action . '" href="' . $questionurl->out() . '"><img src="' .
View
@@ -352,7 +352,7 @@ public function quiz_notices($messages) {
return '';
}
return $this->box($this->heading(get_string('accessnoticesheader', 'quiz'), 3) .
- $this->access_messages($messages), 'quizaccessnotices');
+ $this->access_messages($messages), 'quizaccessnotices');
}
/**
@@ -484,6 +484,8 @@ public function summary_table($attemptobj, $displayoptions) {
$row[] = $attemptobj->get_question_mark($slot);
}
$table->data[] = $row;
+ $table->rowclasses[] = $attemptobj->get_question_state_class(
+ $slot, $displayoptions->correctness);
}
// Print the summary table.
@@ -536,17 +538,22 @@ public function summary_page_controls($attemptobj) {
* @param array $quiz Array conting quiz data
* @param int $cm Course Module ID
* @param int $context The page context ID
- * @param array $messages Array contining any maeeages
+ * @param array $infomessages information about this quiz
* @param mod_quiz_view_object $viewobj
- * @param string $buttontext
+ * @param string $buttontext text for the start/continue attempt button, if
+ * it should be shown.
+ * @param array $infomessages further information about why the student cannot
+ * attempt this quiz now, if appicable this quiz
*/
- public function view_page($course, $quiz, $cm, $context, $messages, $viewobj, $buttontext) {
+ public function view_page($course, $quiz, $cm, $context, $infomessages, $viewobj,
+ $buttontext, $preventmessages) {
$output = '';
- $output .= $this->view_information($course, $quiz, $cm, $context, $messages);
+ $output .= $this->view_information($course, $quiz, $cm, $context, $infomessages);
$output .= $this->view_table($quiz, $context, $viewobj);
$output .= $this->view_best_score($viewobj);
$output .= $this->view_result_info($quiz, $context, $cm, $viewobj);
- $output .= $this->view_attempt_button($course, $quiz, $cm, $context, $viewobj, $buttontext);
+ $output .= $this->view_attempt_button($course, $quiz, $cm, $context, $viewobj,
+ $buttontext, $preventmessages);
return $output;
}
@@ -608,9 +615,7 @@ public function view_information($course, $quiz, $cm, $context, $messages) {
'intro');
}
- $output .= $this->box_start('quizinfo');
- $this->access_messages($messages);
- $output .= $this->box_end();
+ $output .= $this->box($this->access_messages($messages), 'quizinfo');
// Show number of attempts summary to those who can view reports.
if (has_capability('mod/quiz:viewreports', $context)) {
@@ -853,7 +858,8 @@ public function view_result_info($quiz, $context, $cm, $viewobj) {
* @param mod_quiz_view_object $viewobj
* @param string $buttontext
*/
- public function view_attempt_button($course, $quiz, $cm, $context, $viewobj, $buttontext) {
+ public function view_attempt_button($course, $quiz, $cm, $context, $viewobj,
+ $buttontext, $preventmessages) {
$output = '';
// Determine if we should be showing a start/continue attempt button,
// or a button to go back to the course page.
@@ -864,6 +870,10 @@ public function view_attempt_button($course, $quiz, $cm, $context, $viewobj, $bu
$output .= quiz_no_questions_message($quiz, $cm, $context);
}
+ if ($preventmessages) {
+ $output .= $this->access_messages($preventmessages);
+ }
+
if ($buttontext) {
$output .= $viewobj->accessmanager->print_start_attempt_button($viewobj->canpreview,
$buttontext, $viewobj->unfinished);
View
@@ -175,14 +175,14 @@
);
$summarydata['timetaken'] = array(
'title' => get_string('timetaken', 'quiz'),
- 'content' => userdate($timetaken),
+ 'content' => format_time($timetaken),
);
}
if (!empty($overtime)) {
$summarydata['overdue'] = array(
'title' => get_string('overdue', 'quiz'),
- 'content' => userdate($overtime),
+ 'content' => format_time($overtime),
);
}
View
@@ -162,14 +162,15 @@
$viewobj->lastfinishedattempt = $lastfinishedattempt;
// Display information about this quiz.
-$messages = $viewobj->accessmanager->describe_rules();
+$infomessages = $viewobj->accessmanager->describe_rules();
if ($quiz->attempts != 1) {
- $messages[] = get_string('gradingmethod', 'quiz',
+ $infomessages[] = get_string('gradingmethod', 'quiz',
quiz_get_grading_option_name($quiz->grademethod));
}
// This will be set something if as start/continue attempt button should appear.
$buttontext = '';
+$preventmessages = array();
if (!quiz_clean_layout($quiz->questions, true)) {
$buttontext = '';
@@ -183,10 +184,10 @@
} else {
if ($viewobj->canattempt) {
- $messages = $viewobj->accessmanager->prevent_new_attempt($viewobj->numattempts,
+ $preventmessages = $viewobj->accessmanager->prevent_new_attempt($viewobj->numattempts,
$viewobj->lastfinishedattempt);
- if ($messages) {
- $this->access_messages($messages);
+ if ($preventmessages) {
+ $buttontext = '';
} else if ($viewobj->numattempts == 0) {
$buttontext = get_string('attemptquiznow', 'quiz');
} else {
@@ -204,8 +205,7 @@
if (!$viewobj->moreattempts) {
$buttontext = '';
} else if ($viewobj->canattempt
- && $messages = $viewobj->accessmanager->prevent_access()) {
- $this->access_messages($messages);
+ && $preventmessages = $viewobj->accessmanager->prevent_access()) {
$buttontext = '';
}
}
@@ -215,13 +215,14 @@
// Guests can't do a quiz, so offer them a choice of logging in or going back.
if (isguestuser()) {
- echo $output->view_page_guest($course, $quiz, $cm, $context, $messages, $viewobj);
+ echo $output->view_page_guest($course, $quiz, $cm, $context, $infomessages, $viewobj);
} else if (!isguestuser() && !($viewobj->canattempt || $viewobj->canpreview
|| $viewobj->canreviewmine)) {
// If they are not enrolled in this course in a good enough role, tell them to enrol.
- echo $output->view_page_notenrolled($course, $quiz, $cm, $context, $messages, $viewobj);
+ echo $output->view_page_notenrolled($course, $quiz, $cm, $context, $infomessages, $viewobj);
} else {
- echo $output->view_page($course, $quiz, $cm, $context, $messages, $viewobj, $buttontext);
+ echo $output->view_page($course, $quiz, $cm, $context, $infomessages, $viewobj,
+ $buttontext, $preventmessages);
}
echo $OUTPUT->footer();
Oops, something went wrong.

0 comments on commit 0b8dea8

Please sign in to comment.