Skip to content

Commit

Permalink
MDL-27161: fixed optional setting for 'require grading' to prevent pa…
Browse files Browse the repository at this point in the history
…ge lock out
  • Loading branch information
Rossiani Wijaya committed May 13, 2011
1 parent 39d106e commit f4dc83e
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions mod/lesson/essay.php
Expand Up @@ -46,41 +46,59 @@
}
$PAGE->set_url($url);

$attempt = new stdClass();
$user = new stdClass();
$attemptid = optional_param('attemptid', 0, PARAM_INT);

if ($attemptid > 0) {
$attempt = $DB->get_record('lesson_attempts', array('id' => $attemptid));
$answer = $DB->get_record('lesson_answers', array('lessonid' => $lesson->id, 'pageid' => $attempt->pageid));
$user = $DB->get_record('user', array('id' => $attempt->userid));
$scoreoptions = array();
if ($lesson->custom) {
$i = $answer->score;
while ($i >= 0) {
$scoreoptions[$i] = (string)$i;
$i--;
}
} else {
$scoreoptions[0] = get_string('nocredit', 'lesson');
$scoreoptions[1] = get_string('credit', 'lesson');
}
}

/// Handle any preprocessing before header is printed - based on $mode
switch ($mode) {
case 'grade':
// Grading form - get the necessary data
require_sesskey();

$attemptid = required_param('attemptid', PARAM_INT);

if (!$attempt = $DB->get_record('lesson_attempts', array('id' => $attemptid))) {
if (empty($attempt)) {
print_error('cannotfindattempt', 'lesson');
}
$page = $lesson->load_page($attempt->pageid);
if (!$user = $DB->get_record('user', array('id' => $attempt->userid))) {
if (empty($user)) {
print_error('cannotfinduser', 'lesson');
}
if (!$answer = $DB->get_record('lesson_answers', array('lessonid' => $lesson->id, 'pageid' => $page->id))) {
if (empty($answer)) {
print_error('cannotfindanswer', 'lesson');
}
break;

case 'update':
require_sesskey();
$mform = new essay_grading_form();
if ($form = $mform->get_data()) {

if (optional_param('cancel', false, PARAM_RAW)) {
redirect("$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id");
}

$attemptid = required_param('attemptid', PARAM_INT);
$score = optional_param('score', 0, PARAM_INT);
if (empty($attempt)) {
print_error('cannotfindattempt', 'lesson');
}
if (empty($user)) {
print_error('cannotfinduser', 'lesson');
}

if (!$attempt = $DB->get_record('lesson_attempts', array('id' => $attemptid))) {
print_error('cannotfindattempt', 'lesson');
}
$mform = new essay_grading_form(null, array('scoreoptions'=>$scoreoptions, 'user'=>$user));
if ($mform->is_cancelled()) {
redirect("$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id");
}
if ($form = $mform->get_data()) {
if (!$grades = $DB->get_records('lesson_grades', array("lessonid"=>$lesson->id, "userid"=>$attempt->userid), 'completed', '*', $attempt->retry, 1)) {
print_error('cannotfindgrade', 'lesson');
}
Expand All @@ -89,7 +107,7 @@
$essayinfo = unserialize($attempt->useranswer);

$essayinfo->graded = 1;
$essayinfo->score = $score;
$essayinfo->score = $form->score;
$essayinfo->response = clean_param($form->response, PARAM_RAW);
$essayinfo->sent = 0;
if (!$lesson->custom && $essayinfo->score == 1) {
Expand Down Expand Up @@ -368,22 +386,9 @@
case 'grade':
// Grading form
// Expects the following to be set: $attemptid, $answer, $user, $page, $attempt


$essayinfo = unserialize($attempt->useranswer);
$options = array();
if ($lesson->custom) {
$i = $answer->score;
while ($i >= 0) {
$options[$i] = (string)$i;
$i--;
}
} else {
$options[0] = get_string('nocredit', 'lesson');
$options[1] = get_string('credit', 'lesson');
}
$mform = new essay_grading_form(null, array('scoreoptions'=>$options, 'user'=>$user));

$mform = new essay_grading_form(null, array('scoreoptions'=>$scoreoptions, 'user'=>$user));
$data = new stdClass;
$data->id = $cm->id;
$data->attemptid = $attemptid;
Expand Down

0 comments on commit f4dc83e

Please sign in to comment.