From 2e7551866789f73290669b9be8996f3b20fe9f3b Mon Sep 17 00:00:00 2001
From: michaelpenne
Date: Mon, 1 Nov 2004 20:41:55 +0000
Subject: [PATCH] added a link to report, changed conditions for displaying
essay link, modified the essay functions to reflect the new view of an essay
question, and updated view.php to work with modattempts option
---
mod/lesson/view.php | 645 +++++++++++++++++++++++++++-----------------
1 file changed, 402 insertions(+), 243 deletions(-)
diff --git a/mod/lesson/view.php b/mod/lesson/view.php
index 4675f073ee..c250552d1c 100644
--- a/mod/lesson/view.php
+++ b/mod/lesson/view.php
@@ -103,7 +103,7 @@
} else {
$pixpath = $path .'/../theme/'. $CFG->theme .'/pix';
}
-
+
/************** navigation **************************************/
if ($action == 'navigation') {
//CDC Chris Berri added this echo call for left menu. must match that in lesson.php for styles
@@ -131,7 +131,7 @@
}
/// CDC-FLAG /// password protected lesson code
- if ($lesson->usepassword) {
+ if ($lesson->usepassword && !isteacher($course->id)) {
$correctpass = false;
if (isset($_POST['userpassword'])) {
if ($lesson->password == md5(trim($_POST['userpassword']))) {
@@ -208,8 +208,13 @@
$retries = 0;
}
if ($retries) {
- print_heading(get_string('attempt', 'lesson', $retries + 1));
+ print_heading(get_string('attempt', 'lesson', $retries + 1));
}
+
+ if (isset($USER->modattempts[$lesson->id])) {
+ unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing
+ }
+
// if there are any questions have been answered correctly in this attempt
if ($attempts = get_records_select('lesson_attempts',
"lessonid = $lesson->id AND userid = $USER->id AND retry = $retries AND
@@ -248,7 +253,8 @@
print_simple_box('
'. get_string('leftduringtimed', 'lesson') .'
', 'center');
echo '\n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes'
- echo '' . "\n"; echo '';///CDC Chris Berri added close div tag
+ echo '' . "\n";
+ echo '';///CDC Chris Berri added close div tag
} else {
print_simple_box_start('center');
echo '
';
@@ -271,9 +277,10 @@
echo "\n"; echo "
";///CDC Chris Berri added close div tag
}
print_footer($course);
- exit();
+ exit();
}
}
+
if ($grades) {
foreach ($grades as $grade) {
$bestgrade = $grade->grade;
@@ -296,9 +303,9 @@
}
}
// start at the first page
- if (!$pageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) {
- error('Navigation: first page not found');
- }
+ if (!$pageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) {
+ error('Navigation: first page not found');
+ }
/// CDC-FLAG /// -- This is the code for starting a timed test
if($lesson->timed && !isset($USER->startlesson[$lesson->id])) {
unset($startlesson);
@@ -382,7 +389,10 @@
}
if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) {
// code for the clock
- echo "
';
}
unset($newtime);
@@ -413,10 +425,9 @@
'prevpageid', 0)) {
error('Navigation: first page not found');
}
- if ($pageid == $firstpageid) {
+ if ($pageid == $firstpageid && !isset($USER->modattempts[$lesson->id])) {
print_simple_box(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center');
}
-
}
}
/// CDC-FLAG ///
@@ -425,15 +436,15 @@
if (!$page = get_record('lesson_pages', 'id', $pageid)) {
error('Navigation: the page record not found');
}
- /// CDC-FLAG 6/21/04 /// - this only gets called when a user starts up a new lesson and the first page is a cluster page
- if ($page->qtype == LESSON_CLUSTER) {
+ /// CDC-FLAG 6/21/04 ///
+ if ($page->qtype == LESSON_CLUSTER) { //this only gets called when a user starts up a new lesson and the first page is a cluster page
if (!isteacher($course->id)) {
- // get new id
- $pageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid);
- // get new page info
- if (!$page = get_record('lesson_pages', 'id', $pageid)) {
- error('Navigation: the page record not found');
- }
+ // get new id
+ $pageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid);
+ // get new page info
+ if (!$page = get_record('lesson_pages', 'id', $pageid)) {
+ error('Navigation: the page record not found');
+ }
} else {
// get the next page
$pageid = $page->nextpageid;
@@ -489,7 +500,11 @@
if (isteacher($course->id)) {
echo "
".get_string('teacherongoingwarning', 'lesson').'
';
} else {
- lesson_calculate_ongoing_score($lesson, $USER);
+ $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
+ if (isset($USER->modattempts[$lesson->id])) {
+ $ntries--;
+ }
+ lesson_calculate_ongoing_score($lesson, $USER->id, $ntries);
}
}
/// CDC-FLAG ///
@@ -552,6 +567,18 @@
}
/// CDC-FLAG ///
echo " \n";
+
+ // this is for modattempts option. Find the users previous answer to this page,
+ // and then display it below in answer processing
+ if (isset($USER->modattempts[$lesson->id])) {
+ $retries = count_records('lesson_grades', "lessonid", $lesson->id, "userid", $USER->id);
+ $retries--;
+ if (! $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND pageid = $page->id AND retry = $retries", "timeseen")) {
+ error("Previous attempt record could not be found!");
+ }
+ $attempt = end($attempts);
+ }
+
// get the answers in a set order, the id order
if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
echo "";
+ echo "
\n";
break;
case LESSON_BRANCHTABLE :
- $nextprevious = array();
- $otherjumps = array();
- // seperate out next and previous jumps from the other jumps
- foreach ($answers as $answer) {
- if($answer->jumpto == LESSON_NEXTPAGE || $answer->jumpto == LESSON_PREVIOUSPAGE) {
- $nextprevious[] = $answer;
- } else {
- $otherjumps[] = $answer;
- }
- }
- if ($page->layout) {
- echo "
";
- // next 3 foreach loops print out the links in correct order
- foreach ($nextprevious as $jump) {
- if ($jump->jumpto == LESSON_PREVIOUSPAGE) {
- echo "
";
- } else {
- // next 3 foreach loops print out the links in correct order
- foreach ($nextprevious as $jump) {
- if ($jump->jumpto == LESSON_NEXTPAGE) {
- echo "
";
- }
- }
- }
+ if (!empty($answers)) {
+ $nextprevious = array();
+ $otherjumps = array();
+ // seperate out next and previous jumps from the other jumps
+ foreach ($answers as $answer) {
+ if($answer->jumpto == LESSON_NEXTPAGE || $answer->jumpto == LESSON_PREVIOUSPAGE) {
+ $nextprevious[] = $answer;
+ } else {
+ $otherjumps[] = $answer;
+ }
+ }
+ if ($page->layout) {
+ echo "
";
+ // next 3 foreach loops print out the links in correct order
+ foreach ($nextprevious as $jump) {
+ if ($jump->jumpto == LESSON_PREVIOUSPAGE) {
+ echo "
";
+ } else {
+ // next 3 foreach loops print out the links in correct order
+ foreach ($nextprevious as $jump) {
+ if ($jump->jumpto == LESSON_NEXTPAGE) {
+ echo "
";
- }
+ /// CDC-FLAG /// link to grade essay questions and to report
+ if ($testattempts = get_records("lesson_attempts", "lessonid", $lesson->id)) { // just check to see if anyone has answered any questions.
+ echo "
";
+ }
+ if ($essaypages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { // get pages that are essay
+ // get only the attempts that are in response to essay questions
+ $essaypageids = implode(",", array_keys($essaypages)); // all the pageids in comma seperated list
+ if ($essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($essaypageids)")) {
+ echo "
";
+ }
+ }
/// CDC-FLAG /// tree code - in final release, will use lang file for all text output.
// NoticeFix next two lines and bowth viewAlls
$branch = false;
@@ -1223,9 +1338,7 @@
break;
case LESSON_MATCHING :
echo $LESSON_QUESTION_TYPE[$page->qtype];
- if (!lesson_iscorrect($page->id, $answer->jumpto)) {
- echo " - ".get_string("firstanswershould", "lesson");
- }
+ echo get_string("firstanswershould", "lesson");
break;
case LESSON_TRUEFALSE :
case LESSON_NUMERICAL :
@@ -1462,109 +1575,148 @@
/*******************essay view **************************************/ // 6/29/04
elseif ($action == 'essayview') {
print_heading_with_help($lesson->name, "overview", "lesson");
- if (!$essays = get_records_select("lesson_essay", "lessonid = $lesson->id", "timesubmitted")) {
- error("No one has answered essay questions yet...");
- }
- if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
+
+ // get lesson pages that are essay
+ if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) {
error("Error: could not find lesson pages");
}
- if (!$users = lesson_get_participants($lesson->id)) {
+
+ // get all the users who have taken this lesson, order by their last name
+ if (!$users = get_records_sql("SELECT DISTINCT u.*
+ FROM {$CFG->prefix}user u,
+ {$CFG->prefix}lesson_attempts a
+ WHERE a.lessonid = '$lesson->id' and
+ u.id = a.userid
+ ORDER BY u.lastname")) {
error("Error: could not find users");
}
-
- echo "
";
-
- foreach ($essays as $essay) {
- $studentname = $users[$essay->userid]->lastname.", ".$users[$essay->userid]->firstname;
- $essay->studentname = $studentname;
- $temp[$studentname][] = $essay;
+
+ // get only the attempts that are in response to essay questions
+ $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list
+ if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)")) {
+ error ("No one has answered essay questions yet...");
+ }
+ // group all the essays by userid
+ foreach ($essayattempts as $essay) {
+ // not very nice :) but basically
+ // this organizes the essays so I know how many times a student answered an essay per try and per page
+ $studentessays[$essay->userid][$essay->pageid][$essay->retry][] = $essay;
}
- ksort($temp);
- echo "
";
- echo "
cellheading2\">
$course->students
".get_string("essays", "lesson")."
".get_string("email", "lesson")."
";
- foreach ($temp as $student) {
- echo "
".$student[0]->studentname."
";
- $end = end($student);
- foreach ($student as $essay) {
- if (!$essay->graded) {
- $style = "style='color:#DF041E;text-decoration:underline;'";
- } elseif (!$essay->sent) {
- $style = "style='color:#006600;text-decoration:underline;'";
- } else {
- $style = "style='color:#999999;'";
- }
- $output = "id&action=essaygrade&essayid=$essay->id\">".$pages[$essay->pageid]->title."";
- if ($essay->id != $end->id) {
- $output .= ", ";
- }
- echo $output;
+ print_heading("id\">".get_string("gobacktolesson", "lesson")."");
+
+ $table->head = array($course->students, get_string("essays", "lesson"), get_string("email", "lesson"));
+ $table->align = array("left", "left", "left");
+ $table->wrap = array("nowrap", "wrap", "nowrap");
+ $table->width = "90%";
+ $table->size = array("*", "70%", "*");
+
+ // get the student ids of the students who have answered the essay question
+ $studentids = array_keys($studentessays);
+
+ // cycle through all the ids
+ foreach ($studentids as $id) {
+ $studentname = $users[$id]->lastname.", ".$users[$id]->firstname;
+ unset($essaylinks);
+ // go through each essay
+ foreach ($studentessays[$id] as $page => $tries) {
+ // go through each essay per page
+ foreach($tries as $try) {
+ // make sure they didn't answer it more than the max number of attmepts
+ if (count($try) > $lesson->maxattempts) {
+ $essay = $try[$lesson->maxattempts-1];
+ } else {
+ $essay = end($try);
+ }
+ $essayinfo = unserialize($essay->useranswer);
+ // different colors for all the states of an essay (graded, if sent, not graded)
+ if (!$essayinfo->graded) {
+ $style = "style='color:#DF041E;text-decoration:underline;'";
+ } elseif (!$essayinfo->sent) {
+ $style = "style='color:#006600;text-decoration:underline;'";
+ } else {
+ $style = "style='color:#999999;'";
+ }
+ // link for each essay
+ $essaylinks[] = "id&action=essaygrade&attemptid=$essay->id\">".$pages[$essay->pageid]->title."";
+ }
}
- echo "