From 9e93d4d03f8c88f9d0a3e9bc203163dd85459aff Mon Sep 17 00:00:00 2001 From: rkingdon Date: Sat, 27 Mar 2004 04:15:29 +0000 Subject: [PATCH] Version 3 update --- lang/en/lesson.php | 25 ++- mod/lesson/backuplib.php | 4 +- mod/lesson/db/mysql.php | 7 +- mod/lesson/db/mysql.sql | 2 + mod/lesson/import.php | 1 - mod/lesson/index.php | 19 +- mod/lesson/lesson.php | 357 +++++++++++++++++++++++++++++++------- mod/lesson/lib.php | 19 +- mod/lesson/mod.html | 35 +++- mod/lesson/restorelib.php | 4 +- mod/lesson/version.php | 2 +- mod/lesson/view.php | 271 +++++++++++++++++++---------- 12 files changed, 576 insertions(+), 170 deletions(-) diff --git a/lang/en/lesson.php b/lang/en/lesson.php index 938a6eb0b4..afbd3dd314 100644 --- a/lang/en/lesson.php +++ b/lang/en/lesson.php @@ -3,31 +3,40 @@ $string['actionaftercorrectanswer'] = "Action after Correct Answer"; -$string['addanewpage'] = "Add a new page"; -$string['addpagehere'] = "Add page Here"; +$string['addabranchtable'] = "Add a Branch Table"; +$string['addanendofbranch'] = "Add an End of Branch"; +$string['addaquestionpage'] = "Add a Question Page"; $string['answer'] = "Answer"; $string['answersfornumerical'] = "Answers for Numerical questions should be matched pairs of Minimum and Maximum values"; $string['attempt'] = "Attempt: \$a"; $string['attempts'] = "Attempts"; $string['available'] = "Available from"; -$string['canretake'] = "\$a can re-take"; +$string['branchtable'] = "Branch Table"; +$string['canretake'] = "\$a can Re-take"; $string['casesensitive'] = "Case Sensitive"; $string['checknavigation'] = "Check navigation"; +$string['checkbranchtable'] = "Check Branch Table"; $string['checkquestion'] = "Check Question"; $string['confirmdeletionofthispage'] = "Confirm deletion of this page"; $string['congratulations'] = "Congratulations - end of lesson reached"; $string['continue'] = "Continue"; $string['deadline'] = "Deadline"; +$string['deleting'] = "Deleting"; $string['deletingpage'] = "Deleting page: \$a"; +$string['description'] = "Description"; $string['displayofgrade'] = "Display of grade (for students only)"; +$string['endofbranch'] = "End of Branch"; $string['endoflesson'] = "End of lesson"; $string['fileformat'] = "File Format"; $string['firstanswershould'] = "First Answer should Jump to the "Correct" Page"; $string['gradeis'] = "Grade is \$a"; +$string['handlingofretakes'] = "Handling of Re-takes"; +$string['here'] = "here"; $string['importquestions'] = "Import Questions"; $string['jumpto'] = "Jump to"; -$string['maximumnumberofanswers'] = "Maximum number of answers"; +$string['maximumnumberofanswersbranches'] = "Maximum number of answers/branches"; $string['maximumnumberofattempts'] = "Maximum number of Attempts"; +$string['minimumnumberofquestions'] = "Minimum number of Questions"; $string['modulename'] = "Lesson"; $string['modulenameplural'] = "Lessons"; $string['multianswer'] = "Multianswer"; @@ -39,6 +48,8 @@ $string['nextpage'] = "Next page"; $string['noanswer'] = "No answer given"; $string['noattemptrecordsfound'] = "No Attempt Records Found: No Grade given"; $string['normal'] = "Normal - follow Lesson Path"; +$string['notdefined'] = "Not Defined"; +$string['notitle'] = "No Title"; $string['numberofcorrectanswers'] = "Number of correct answers: \$a"; $string['numberofcorrectmatches'] = "Number of Correct Matches: \$a"; $string['numberofpagesviewed'] = "Number of pages viewed: \$a"; @@ -48,6 +59,7 @@ $string['outof'] = "Out of \$a"; $string['questiontype'] = "Question Type"; $string['questionoption'] = "Question Option"; $string['page'] = "Page: \$a"; +$string['pages'] = "Pages"; $string['pagecontents'] = "Page contents"; $string['pagetitle'] = "Page title"; $string['pleasecheckoneanswer'] = "Please check one Answer"; @@ -62,8 +74,13 @@ $string['showanunseenpage'] = "Show an Unseen Page"; $string['showanunansweredpage'] = "Show an unanswered Page"; $string['thatsthecorrectanswer'] = "That's the Correct Answer"; $string['thatsthewronganswer'] = "That's the Wrong Answer"; +$string['thefollowingpagesjumptothispage'] = "The following Pages jump to this Page"; $string['thispage'] = "This page"; +$string['usemaximum'] = "Use Maximum"; +$string['usemean'] = "Use Mean"; $string['youhaveseen'] = "You have seen more than one page of this lesson already.
Do you want to start at the last page you saw?"; $string['youranswer'] = "Your Answer"; +$string['yourcurrentgradeis'] = "Your current Grade is \$a"; +$string['youshouldview'] = "You should view at least: \$a"; ?> diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index a9000ea745..e44928285e 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -49,9 +49,11 @@ fwrite ($bf,full_tag("MODTYPE",4,false,"lesson")); fwrite ($bf,full_tag("NAME",4,false,$lesson->name)); fwrite ($bf,full_tag("GRADE",4,false,$lesson->grade)); + fwrite ($bf,full_tag("USEMAXGRADE",4,false,$lesson->usemaxgrade)); fwrite ($bf,full_tag("MAXANSWERS",4,false,$lesson->maxanswers)); fwrite ($bf,full_tag("MAXATTEMPTS",4,false,$lesson->maxattempts)); fwrite ($bf,full_tag("NEXTPAGEDEFAULT",4,false,$lesson->nextpagedefault)); + fwrite ($bf,full_tag("MINQUESTIONS",4,false,$lesson->minquestions)); fwrite ($bf,full_tag("MAXPAGES",4,false,$lesson->maxpages)); fwrite ($bf,full_tag("RETAKE",4,false,$lesson->retake)); fwrite ($bf,full_tag("AVAILABLE",4,false,$lesson->available)); @@ -171,9 +173,9 @@ $status =fwrite ($bf,start_tag("ATTEMPT",5,true)); //Print attempt contents fwrite ($bf,full_tag("USERID",6,false,$attempt->userid)); + fwrite ($bf,full_tag("RETRY",6,false,$attempt->retry)); fwrite ($bf,full_tag("CORRECT",6,false,$attempt->correct)); fwrite ($bf,full_tag("TIMESEEN",6,false,$attempt->timeseen)); - fwrite ($bf,full_tag("RETRY",6,false,$attempt->retry)); //End attempt $status =fwrite ($bf,end_tag("ATTEMPT",5,true)); } diff --git a/mod/lesson/db/mysql.php b/mod/lesson/db/mysql.php index 3fbf630d38..b8f7893a00 100644 --- a/mod/lesson/db/mysql.php +++ b/mod/lesson/db/mysql.php @@ -30,7 +30,12 @@ function lesson_upgrade($oldversion) { if ($oldversion < 2004032000) { // Upgrade some old beta lessons execute_sql(" UPDATE `{$CFG->prefix}lesson_pages` SET qtype = 3 WHERE qtype = 0"); } - + + if ($oldversion < 2004032400) { + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usegrademax` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `minquestions` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); + } + return true; } diff --git a/mod/lesson/db/mysql.sql b/mod/lesson/db/mysql.sql index 30391b4164..aa19296c33 100644 --- a/mod/lesson/db/mysql.sql +++ b/mod/lesson/db/mysql.sql @@ -9,9 +9,11 @@ CREATE TABLE `prefix_lesson` ( `course` int(10) unsigned NOT NULL default '0', `name` varchar(255) NOT NULL default '', `grade` tinyint(3) NOT NULL default '0', + `usemaxgrade` tinyint(3) NOT NULL default '0', `maxanswers` int(3) unsigned NOT NULL default '4', `maxattempts` int(3) unsigned NOT NULL default '5', `nextpagedefault` int(3) unsigned NOT NULL default '0', + `minquestions` int(3) unsigned NOT NULL default '0', `maxpages` int(3) unsigned NOT NULL default '0', `retake` int(3) unsigned NOT NULL default '1', `available` int(10) unsigned NOT NULL default '0', diff --git a/mod/lesson/import.php b/mod/lesson/import.php index 6fd516e34b..85883a3ef0 100644 --- a/mod/lesson/import.php +++ b/mod/lesson/import.php @@ -106,7 +106,6 @@ print_string("fileformat", "lesson"); echo ":"; choose_from_menu($fileformatnames, "format", "gift", ""); - helpbutton("import", $strimportquestions, "lesson"); echo ""; echo ""; diff --git a/mod/lesson/index.php b/mod/lesson/index.php index 8e7e41d464..7faafa8058 100644 --- a/mod/lesson/index.php +++ b/mod/lesson/index.php @@ -76,14 +76,17 @@ if (isteacher($course->id)) { $grade_value = $lesson->grade; } else { - // it's a student, show their maximum grade - if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND - userid = $USER->id", "grade DESC")) { - foreach ($grades as $grade) { - // grades are stored as percentages - $grade_value = number_format($grade->grade * $lesson->grade / 100, 1); - break; // only the first (largest) grade needed - } + // it's a student, show their mean or maximum grade + if ($lesson->usemaxgrade) { + $grade = get_record_sql("SELECT MAX(grade) as grade FROM {$CFG->prefix}lesson_grades + WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid"); + } else { + $grade = get_record_sql("SELECT AVG(grade) as grade FROM {$CFG->prefix}lesson_grades + WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid"); + } + if ($grade) { + // grades are stored as percentages + $grade_value = number_format($grade->grade * $lesson->grade / 100, 1); } else { $grade_value = 0; } diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index c3702d6641..4e29e94d26 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -3,7 +3,9 @@ /************************************************* ACTIONS handled are: - addpage + addbranchtable + addendofbranch + addpage confirmdelete continue delete @@ -57,8 +59,145 @@ require_variable($action); + /************** add branch table ************************************/ + if ($action == 'addbranchtable' ) { + + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + // first get the preceeding page + $pageid = $_GET['pageid']; + + // set of jump array + $jump[0] = get_string("thispage", "lesson"); + $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); + $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); + if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + error("Add page: first page not found"); + } + while (true) { + if ($apageid) { + $title = get_field("lesson_pages", "title", "id", $apageid); + $jump[$apageid] = $title; + $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + } else { + // last page reached + break; + } + } + + // give teacher a blank proforma + print_heading_with_help(get_string("addabranchtable", "lesson"), "overview", "lesson"); + ?> +
+ + + + +
+ + + \n"; + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + } + use_html_editor(); + // close table and form + ?> +
+
:
+
"; + echo get_string("pagecontents", "lesson").":
\n"; + print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); + echo "
".get_string("description", "lesson")." $iplus1:
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]"); + echo "
".get_string("jumpto", "lesson").": \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); + echo "

+ "> + "> +
+
+ id)) { + error("Only teachers can look at this page"); + } + + // first get the preceeding page + $pageid = $_GET['pageid']; + + $timenow = time(); + + // the new page is not the first page (end of branch always comes after an existing page) + if (!$page = get_record("lesson_pages", "id", $pageid)) { + error("Add end of branch: page record not found"); + } + // chain back up to find the (nearest branch table) + $btpageid = $pageid; + if (!$btpage = get_record("lesson_pages", "id", $btpageid)) { + error("Add end of branch: btpage record not found"); + } + while (($btpage->qtype != LESSON_BRANCHTABLE) AND ($btpage->prevpageid > 0)) { + $btpageid = $btpage->prevpageid; + if (!$btpage = get_record("lesson_pages", "id", $btpageid)) { + error("Add end of branch: btpage record not found"); + } + } + if ($btpage->qtype == LESSON_BRANCHTABLE) { + $newpage->lessonid = $lesson->id; + $newpage->prevpageid = $pageid; + $newpage->nextpageid = $page->nextpageid; + $newpage->qtype = LESSON_ENDOFBRANCH; + $newpage->timecreated = $timenow; + $newpage->title = get_string("endofbranch", "lesson"); + $newpage->contents = get_string("endofbranch", "lesson"); + if (!$newpageid = insert_record("lesson_pages", $newpage)) { + error("Insert page: new page not inserted"); + } + // update the linked list... + if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + error("Add end of branch: unable to update link"); + } + if ($page->nextpageid) { + // the new page is not the last page + if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + error("Insert page: unable to update previous link"); + } + } + // ..and the single "answer" + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswer->jumpto = $btpageid; + if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + error("Add end of branch: answer record not inserted"); + } + redirect("view.php?id=$cm->id", get_string("ok")); + } else { + notice(get_string("nobranchtablefound", "lesson"), "view.php?id=$cm->id"); + } + } + + /************** add page ************************************/ - if ($action == 'addpage' ) { + elseif ($action == 'addpage' ) { if (!isteacher($course->id)) { error("Only teachers can look at this page"); @@ -86,7 +225,7 @@ } // give teacher a blank proforma - print_heading_with_help(get_string("addanewpage", "lesson"), "overview", "lesson"); + print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson"); ?>
@@ -132,7 +271,7 @@ // close table and form ?>
- "> + "> ">
@@ -419,6 +558,25 @@ } } break; + + case LESSON_BRANCHTABLE: + $noanswer = false; + $newpageid = $_POST['jumpto']; + // convert jumpto page into a proper page id + if ($newpageid == 0) { + $newpageid = $pageid; + } elseif ($newpageid == LESSON_NEXTPAGE) { + if (!$newpageid = $page->nextpageid) { + // no nextpage go to end of lesson + $newpageid = LESSON_EOL; + } + } + // no need to record anything in lesson_attempts + redirect("view.php?id=$cm->id&action=navigation&pageid=$newpageid"); + print_footer($course); + exit(); + break; + } if ($noanswer) { $newpageid = $pageid; // display same page again @@ -595,9 +753,16 @@ } while (true) { if ($apageid) { - $title = get_field("lesson_pages", "title", "id", $apageid); - $jump[$apageid] = $title; - $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + if (!$apage = get_record("lesson_pages", "id", $apageid)) { + error("Edit page: apage record not found"); + } + if ($apage->qtype != LESSON_ENDOFBRANCH) { + // don't include EOB's in the list... + if (trim($page->title)) { // ...nor nuffin pages + $jump[$apageid] = $apage->title; + } + } + $apageid = $apage->nextpageid; } else { // last page reached break; @@ -622,10 +787,10 @@ print_textarea($usehtmleditor, 25, 70, 630, 400, "contents", $page->contents); echo "\n"; $n = 0; - echo "".get_string("questiontype", "lesson").": \n"; - choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); switch ($page->qtype) { case LESSON_SHORTANSWER : + echo "".get_string("questiontype", "lesson").": \n"; + choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); echo "  "; if ($page->qoption) { echo ""; @@ -633,8 +798,11 @@ echo ""; } echo " ".get_string("casesensitive", "lesson")."\n"; + helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); break; case LESSON_MULTICHOICE : + echo "".get_string("questiontype", "lesson").": \n"; + choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); echo "  "; if ($page->qoption) { echo ""; @@ -642,20 +810,48 @@ echo ""; } echo " ".get_string("multianswer", "lesson")."\n"; + helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); + break; + case LESSON_TRUEFALSE : + case LESSON_MATCHING : + case LESSON_NUMERICAL : + echo "".get_string("questiontype", "lesson").": \n"; + choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); + helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); + break; + case LESSON_BRANCHTABLE : + echo "qtype\">\n"; + echo "".get_string("branchtable", "lesson")." \n"; break; + case LESSON_ENDOFBRANCH : + echo "qtype\">\n"; + echo "".get_string("endofbranch", "lesson")." \n"; + break; } - helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); echo "\n"; if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { foreach ($answers as $answer) { $nplus1 = $n + 1; echo "id\">\n"; - echo "".get_string("answer", "lesson")." $nplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); - echo "\n"; - echo "".get_string("response", "lesson")." $nplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); - echo "\n"; + switch ($page->qtype) { + case LESSON_MULTICHOICE: + case LESSON_TRUEFALSE: + case LESSON_SHORTANSWER: + case LESSON_NUMERICAL: + case LESSON_MATCHING: + echo "".get_string("answer", "lesson")." $nplus1:
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + echo "\n"; + echo "".get_string("response", "lesson")." $nplus1:
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); + echo "\n"; + break; + case LESSON_BRANCHTABLE: + echo "".get_string("description", "lesson")." $nplus1:
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + echo "\n"; + break; + } echo "".get_string("jumpto", "lesson").": \n"; lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); @@ -663,19 +859,34 @@ $n++; } } - for ($i = $n; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]"); - echo "\n"; - echo "".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$i]"); - echo "\n"; - echo "".get_string("jumpto", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); - echo "\n"; + if ($page->qtype != LESSON_ENDOFBRANCH) { + for ($i = $n; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + switch ($page->qtype) { + case LESSON_MULTICHOICE: + case LESSON_TRUEFALSE: + case LESSON_SHORTANSWER: + case LESSON_NUMERICAL: + case LESSON_MATCHING: + echo "".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]"); + echo "\n"; + echo "".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$i]"); + echo "\n"; + break; + case LESSON_BRANCHTABLE: + echo "".get_string("description", "lesson")." $iplus1:
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]"); + echo "\n"; + break; + } + echo "".get_string("jumpto", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); + echo "\n"; + } } use_html_editor(); // close table and form @@ -722,7 +933,13 @@ } // update the linked list if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $form->pageid)) { - error("Insert page: unable to update link"); + error("Insert page: unable to update next link"); + } + if ($page->nextpageid) { + // new page is not the last page + if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + error("Insert page: unable to update previous link"); + } } } else { // new page is the first page @@ -776,7 +993,9 @@ $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; $newanswer->answer = trim($form->answer[$i]); - $newanswer->response = trim($form->response[$i]); + if (isset($form->response[$i])) { + $newanswer->response = trim($form->response[$i]); + } if (isset($form->jumpto[$i])) { $newanswer->jumpto = $form->jumpto[$i]; } @@ -812,7 +1031,10 @@ get_string("movepagehere", "lesson")."\n"; while (true) { if ($page->id != $pageid) { - echo "cellheading2\">$page->title\n"; + if (!$title = trim($page->title)) { + $title = "<< ".get_string("notitle", "lesson")." >>"; + } + echo "cellheading2\">$title\n"; echo "id&action=moveit&pageid=$pageid&after={$page->id}\">". get_string("movepagehere", "lesson")."\n"; } @@ -953,36 +1175,51 @@ if (!update_record("lesson_pages", $page)) { error("Update page: page not updated"); } - for ($i = 0; $i < $lesson->maxanswers; $i++) { - if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML gives


... - if ($form->answerid[$i]) { - $oldanswer->id = $form->answerid[$i]; - $oldanswer->timemodified = $timenow; - $oldanswer->answer = trim($form->answer[$i]); - $oldanswer->response = trim($form->response[$i]); - $oldanswer->jumpto = $form->jumpto[$i]; - if (!update_record("lesson_answers", $oldanswer)) { - error("Update page: answer $i not updated"); + if ($page->qtype == LESSON_ENDOFBRANCH) { + // there's just a single answer with a jump + $oldanswer->id = $form->answerid[0]; + $oldanswer->timemodified = $timenow; + $oldanswer->jumpto = $form->jumpto[0]; + if (!update_record("lesson_answers", $oldanswer)) { + error("Update page: EOB not updated"); + } + } else { + // it's an "ordinary" page + for ($i = 0; $i < $lesson->maxanswers; $i++) { + if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML gives


... + if ($form->answerid[$i]) { + $oldanswer->id = $form->answerid[$i]; + $oldanswer->timemodified = $timenow; + $oldanswer->answer = trim($form->answer[$i]); + if (isset($form->response[$i])) { + $oldanswer->response = trim($form->response[$i]); + } + $oldanswer->jumpto = $form->jumpto[$i]; + if (!update_record("lesson_answers", $oldanswer)) { + error("Update page: answer $i not updated"); + } + } else { + // it's a new answer + unset($newanswer); // need to clear id if more than one new answer is ben added + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $page->id; + $newanswer->timecreated = $timenow; + $newanswer->answer = trim($form->answer[$i]); + if (isset($form->response[$i])) { + $newanswer->response = trim($form->response[$i]); + } + $newanswer->jumpto = $form->jumpto[$i]; + $newanswerid = insert_record("lesson_answers", $newanswer); + if (!$newanswerid) { + error("Update page: answer record not inserted"); + } } } else { - // it's a new answer - unset($newanswer); // need to clear id if more than one new answer is ben added - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $page->id; - $newanswer->timecreated = $timenow; - $newanswer->answer = trim($form->answer[$i]); - $newanswer->response = trim($form->response[$i]); - $newanswer->jumpto = $form->jumpto[$i]; - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Update page: answer record not inserted"); - } - } - } else { - if ($form->answerid[$i]) { - // need to delete blanked out answer - if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { - error("Update page: unable to delete answer record"); + if ($form->answerid[$i]) { + // need to delete blanked out answer + if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { + error("Update page: unable to delete answer record"); + } } } } diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index f0ff0dea1d..8fe287e8ff 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -53,15 +53,21 @@ if (!defined("LESSON_NUMERICAL")) { if (!defined("LESSON_MULTIANSWER")) { define("LESSON_MULTIANSWER", "9"); } -$LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", "quiz"), +if (!defined("LESSON_BRANCHTABLE")) { + define("LESSON_BRANCHTABLE", "20"); +} +if (!defined("LESSON_ENDOFBRANCH")) { + define("LESSON_ENDOFBRANCH", "21"); +} +$LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", "quiz"), LESSON_TRUEFALSE => get_string("truefalse", "quiz"), LESSON_SHORTANSWER => get_string("shortanswer", "quiz"), LESSON_NUMERICAL => get_string("numerical", "quiz"), - LESSON_MATCHING => get_string("match", "quiz") + LESSON_MATCHING => get_string("match", "quiz") // LESSON_DESCRIPTION => get_string("description", "quiz"), // LESSON_RANDOM => get_string("random", "quiz"), // LESSON_RANDOMSAMATCH => get_string("randomsamatch", "quiz"), -// LESSON_MULTIANSWER => get_string("multianswer", "quiz") +// LESSON_MULTIANSWER => get_string("multianswer", "quiz"), ); @@ -308,8 +314,13 @@ function lesson_grades($lessonid) { if (!$lesson = get_record("lesson", "id", $lessonid)) { error("Lesson record not found"); } - $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE + if ($lesson->usemaxgrade) { + $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE + lessonid = $lessonid GROUP BY userid"); + } else { + $grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid"); + } // convert grades from percentages and tidy the numbers if ($grades) { diff --git a/mod/lesson/mod.html b/mod/lesson/mod.html index b846fecede..224bfc6df5 100644 --- a/mod/lesson/mod.html +++ b/mod/lesson/mod.html @@ -11,6 +11,9 @@ require("$CFG->dirroot/mod/lesson/lib.php"); // for parameter array if (!isset($form->grade)) { $form->grade = 0; } + if (!isset($form->usemaxgrade)) { + $form->usemaxgrade = 0; + } if (!isset($form->maxanswers)) { $form->maxanswers = 4; } @@ -20,6 +23,9 @@ require("$CFG->dirroot/mod/lesson/lib.php"); // for parameter array if (!isset($form->nextpagedefault)) { $form->nextpagedefault = 0; } + if (!isset($form->minquestions)) { + $form->minquestions = 0; + } if (!isset($form->maxpages)) { $form->maxpages = 0; } @@ -58,14 +64,14 @@ require("$CFG->dirroot/mod/lesson/lib.php"); // for parameter array -

:

+

:

1; $i--) { $numbers[$i] = $i; } choose_from_menu($numbers, "maxanswers", "$form->maxanswers", ""); - helpbutton("maxanswers", get_string("maximumnumberofanswers", "lesson"), "lesson"); + helpbutton("maxanswers", get_string("maximumnumberofanswersbranches", "lesson"), "lesson"); ?> @@ -94,6 +100,20 @@ require("$CFG->dirroot/mod/lesson/lib.php"); // for parameter array + +

:

+ + =0; $i--) { + $numbers[$i] = $i; + } + choose_from_menu($numbers, "minquestions", "$form->minquestions", ""); + helpbutton("minquestions", get_string("minimumnumberofquestions", "lesson"), "lesson"); + ?> + + +

:

@@ -119,6 +139,17 @@ require("$CFG->dirroot/mod/lesson/lib.php"); // for parameter array + +

:

+ + usemaxgrade, ""); + helpbutton("handlingofretakes", get_string("handlingofretakes", "lesson"), "lesson"); + ?> + + +

: course = $restore->course_id; $lesson->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $lesson->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']); + $lesson->usemaxgrade = backup_todb($info['MOD']['#']['USEMAXGRADE']['0']['#']); $lesson->maxanswers = backup_todb($info['MOD']['#']['MAXANSWERS']['0']['#']); $lesson->maxattempts = backup_todb($info['MOD']['#']['MAXATTEMPTS']['0']['#']); $lesson->nextpagedefault = backup_todb($info['MOD']['#']['NEXTPAGEDEFAULT']['0']['#']); + $lesson->minquestions = backup_todb($info['MOD']['#']['MINQUESTIONS']['0']['#']); $lesson->maxpages = backup_todb($info['MOD']['#']['MAXPAGES']['0']['#']); $lesson->retake = backup_todb($info['MOD']['#']['RETAKE']['0']['#']); $lesson->available = backup_todb($info['MOD']['#']['AVAILABLE']['0']['#']); @@ -254,9 +256,9 @@ $attempt->pageid = $pageid; $attempt->answerid = $answerid; $attempt->userid = backup_todb($attempt_info['#']['USERID']['0']['#']); + $attempt->retry = backup_todb($attempt_info['#']['RETRY']['0']['#']); $attempt->correct = backup_todb($attempt_info['#']['CORRECT']['0']['#']); $attempt->timeseen = backup_todb($attempt_info['#']['TIMESEEN']['0']['#']); - $attempt->retry = backup_todb($attempt_info['#']['RETRY']['0']['#']); //We have to recode the userid field $user = backup_getid($restore->backup_unique_code,"user",$olduserid); diff --git a/mod/lesson/version.php b/mod/lesson/version.php index fea9b63d61..a263869380 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2004032000; // The current module version (Date: YYYYMMDDXX) +$module->version = 2004032400; // The current module version (Date: YYYYMMDDXX) $module->requires = 2004013101; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 5972977cc0..fb2f7baf01 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -60,7 +60,7 @@ // display individual pages and their sets of answers // if pageid is EOL then the end of the lesson has been reached print_heading($lesson->name); - if (empty($pageid)) { + if (empty($pageid)) { add_to_log($course->id, "lesson", "start", "view.php?id=$cm->id", "$lesson->id", $cm->id); // if no pageid given see if the lesson has been started if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", @@ -135,7 +135,55 @@ if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Navigation: the page record not found"); } + // before we output everything check to see if the page is a EOB, if so jump directly + // to it's associated branch table + if ($page->qtype == LESSON_ENDOFBRANCH) { + if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { + // print_heading(get_string("endofbranch", "lesson")); + foreach ($answers as $answer) { + // just need the first answer + redirect("view.php?id=$cm->id&action=navigation&pageid=$answer->jumpto", + get_string("endofbranch", "lesson")); + break; + } + print_footer($course); + exit(); + } else { + error("Navigation: No answers on EOB"); + } + } + // it's not a EOB process it... echo "
\n"; + if ($page->qtype == LESSON_BRANCHTABLE) { + if ($lesson->minquestions and isstudent($course->id)) { + // tell student how many questions they have seen, how many are required and their grade + $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + $nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", + $USER->id, "retry", $ntries); + if ($nviewed) { + echo "

".get_string("numberofpagesviewed", "lesson", $nviewed). + "; (".get_string("youshouldview", "lesson", $lesson->minquestions).")
"; + // count the number of distinct correct pages + if ($correctpages = get_records_select("lesson_attempts", "lessonid = $lesson->id + AND userid = $USER->id AND retry = $ntries AND correct = 1")) { + foreach ($correctpages as $correctpage) { + $temp[$correctpage->pageid] = 1; + } + $ncorrect = count($temp); + } else { + $nccorrect = 0; + } + if ($nviewed < $lesson->minquestions) { + $nviewed = $lesson->minquestions; + } + echo get_string("numberofcorrectanswers", "lesson", $ncorrect)."
\n"; + $thegrade = intval(100 * $ncorrect / $nviewed); + echo get_string("yourcurrentgradeis", "lesson", + number_format($thegrade * $lesson->grade / 100, 1)). + " (".get_string("outof", "lesson", $lesson->grade).")

\n"; + } + } + } print_heading($page->title); print_simple_box(format_text($page->contents), 'center'); echo "
\n"; @@ -224,6 +272,21 @@ echo "

\n"; break; + + case LESSON_BRANCHTABLE : + echo "
"; + echo ""; + // don't suffle answers + foreach ($answers as $answer) { + echo ""; + } + echo '
"; + echo "answer\""; + echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\">"; + echo "
'; + print_simple_box_end(); + break; + } echo "\n"; } else { @@ -248,74 +311,44 @@ print_simple_box_start("center"); $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (isstudent($course->id)) { - // do a sanity check on the user's path through a normal lesson (not a Flash Card lesson) - if ($attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND - userid = $USER->id AND retry = $ntries", "timeseen ASC")) { - $check = true; - if ($lesson->nextpagedefault == 0) { - if (!$thispageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, - "prevpageid", 0)) { - error("Navigation Check: first page not found"); - } - foreach ($attempts as $attempt) { - // skip any page without answers - while (!$answers = get_records("lesson_answers", "pageid", $thispageid)) { - if (!$thispageid = get_field("lesson_pages", "nextpageid", "id", $thispageid)) { - error("Navigation Check: nextpageid not found"); - } - } - if ($attempt->pageid != $thispageid) { - // something odd - // echo "

\$thispageid: $thispageid; \$attempt->pageid: $attempt->pageid

\n"; - $check = false; - break; - } - if (!$answer = get_record("lesson_answers", "id", $attempt->answerid)) { - error("Navigation Check: answer not found"); - } - if ($answer->jumpto) { - if ($answer->jumpto == LESSON_NEXTPAGE) { - if (!$thispageid = get_field("lesson_pages", "nextpageid", "id", - $thispageid)) { - $thispageid = LESSON_EOL; // end of foreach loop should have been reached - } - } else { - $thispageid = $answer->jumpto; - } - } + if ($nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", + $USER->id, "retry", $ntries)) { + // count the number of distinct correct pages + if ($correctpages = get_records_select("lesson_attempts", "lessonid = $lesson->id AND + userid = $USER->id AND retry = $ntries AND correct = 1")) { + foreach ($correctpages as $correctpage) { + $temp[$correctpage->pageid] = 1; } + $ncorrect = count($temp); + } else { + $ncorrect = 0; } - if ($check) { - $ncorrect = count_records_select("lesson_attempts", "lessonid = $lesson->id AND - userid = $USER->id AND retry = $ntries AND correct = 1"); - $nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", - $USER->id, "retry", $ntries); - if ($nviewed) { - $thegrade = intval(100 * $ncorrect / $nviewed); - } else { - $thegrade = 0; - } - echo "

".get_string("numberofpagesviewed", "lesson", $nviewed). - "

\n"; - echo "

".get_string("numberofcorrectanswers", "lesson", $ncorrect). - "

\n"; - echo "

".get_string("gradeis", "lesson", - number_format($thegrade * $lesson->grade / 100, 1)). - " (".get_string("outof", "lesson", $lesson->grade).")

\n"; - $grade->lessonid = $lesson->id; - $grade->userid = $USER->id; - $grade->grade = $thegrade; - $grade->completed = time(); - if (!$newgradeid = insert_record("lesson_grades", $grade)) { - error("Navigation: grade not inserted"); + echo "

".get_string("numberofpagesviewed", "lesson", $nviewed). + "

\n"; + if ($lesson->minquestions) { + if ($nviewed < $lesson->minquestions) { + // print a warning and set nviewed to minquestions + echo "

".get_string("youshouldview", "lesson", + $lesson->minquestions)." ".get_string("pages", "lesson")."

\n"; + $nviewed = $lesson->minquestions; } - } else { - print_string("sanitycheckfailed", "lesson"); - delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, - "retry", $ntries); + } + echo "

".get_string("numberofcorrectanswers", "lesson", $ncorrect). + "

\n"; + $thegrade = intval(100 * $ncorrect / $nviewed); + echo "

".get_string("gradeis", "lesson", + number_format($thegrade * $lesson->grade / 100, 1)). + " (".get_string("outof", "lesson", $lesson->grade).")

\n"; + $grade->lessonid = $lesson->id; + $grade->userid = $USER->id; + $grade->grade = $thegrade; + $grade->completed = time(); + if (!$newgradeid = insert_record("lesson_grades", $grade)) { + error("Navigation: grade not inserted"); } } else { print_string("noattemptrecordsfound", "lesson"); + $thegrade = 0; } } else { // display for teacher @@ -409,8 +442,11 @@ if (isteacheredit($course->id)) { echo "id&pageid=0\">". get_string("importquestions", "lesson")." | ". - "id&action=addpage&pageid=0\">". - get_string("addpagehere", "lesson")."\n"; + "id&action=addbranchtable&pageid=0\">". + get_string("addabranchtable", "lesson")." | ". + "id&action=addendofbranch&pageid=0\">". + get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). + "\n"; } echo "\n"; while (true) { @@ -434,42 +470,69 @@ foreach ($answers as $answer) { echo "cellheading2\" colspan=\"2\" align=\"center\">\n"; if ($i == 1) { - echo $LESSON_QUESTION_TYPE[$page->qtype]; switch ($page->qtype) { case LESSON_SHORTANSWER : + echo $LESSON_QUESTION_TYPE[$page->qtype]; if ($page->qoption) { echo " - ".get_string("casesensitive", "lesson"); } break; case LESSON_MULTICHOICE : + echo $LESSON_QUESTION_TYPE[$page->qtype]; if ($page->qoption) { echo " - ".get_string("multianswer", "lesson"); } break; case LESSON_MATCHING : + echo $LESSON_QUESTION_TYPE[$page->qtype]; if (!lesson_iscorrect($page->id, $answer->jumpto)) { echo " - ".get_string("firstanswershould", "lesson"); } break; + case LESSON_TRUEFALSE : + case LESSON_NUMERICAL : + echo $LESSON_QUESTION_TYPE[$page->qtype]; + break; + case LESSON_BRANCHTABLE : + echo get_string("branchtable", "lesson"); + break; + case LESSON_ENDOFBRANCH : + echo get_string("endofbranch", "lesson"); + break; } } else { echo " "; } echo "\n"; - echo "\n"; - if (lesson_iscorrect($page->id, $answer->jumpto)) { - // underline correct answers - echo "".get_string("answer", "lesson")." $i: \n"; - } else { - echo "".get_string("answer", "lesson")." $i: \n"; + switch ($page->qtype) { + case LESSON_MULTICHOICE: + case LESSON_TRUEFALSE: + case LESSON_SHORTANSWER: + case LESSON_NUMERICAL: + case LESSON_MATCHING: + echo "\n"; + if (lesson_iscorrect($page->id, $answer->jumpto)) { + // underline correct answers + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + echo "\n"; + echo format_text($answer->answer); + echo "\n"; + echo "".get_string("response", "lesson")." $i: \n"; + echo "\n"; + echo format_text($answer->response); + echo "\n"; + break; + case LESSON_BRANCHTABLE: + echo "\n"; + echo "".get_string("description", "lesson")." $i: \n"; + echo "\n"; + echo format_text($answer->answer); + echo "\n"; + break; } - echo "\n"; - echo format_text($answer->answer); - echo "\n"; - echo "".get_string("response", "lesson")." $i: \n"; - echo "\n"; - echo format_text($answer->response); - echo "\n"; if ($answer->jumpto == 0) { $jumptitle = get_string("thispage", "lesson"); } elseif ($answer->jumpto == LESSON_NEXTPAGE) { @@ -481,25 +544,59 @@ $jumptitle = "".get_string("notdefined", "lesson").""; } } - echo "".get_string("jumpto", "lesson").": \n"; - echo "\n"; + echo "".get_string("jumpto", "lesson").": "; + echo "\n"; echo "$jumptitle\n"; $i++; } // print_simple_box_end(); - echo "cellheading2\" colspan=\"2\" align=\"center\">". - "id;". - "document.lessonpages.submit();\">\n"; + echo "cellheading2\" colspan=\"2\" align=\"center\">"; + if ($page->qtype != LESSON_ENDOFBRANCH) { + echo "qtype == LESSON_BRANCHTABLE) { + echo get_string("checkbranchtable", "lesson"); + } else { + echo get_string("checkquestion", "lesson"); + } + echo "\" onclick=\"document.lessonpages.pageid.value=$page->id;". + "document.lessonpages.submit();\">"; + } + echo " \n"; } echo "\n"; if (isteacheredit($course->id)) { echo "id&pageid=$page->id\">". get_string("importquestions", "lesson")." | ". - "id&action=addpage&pageid=$page->id\">". - get_string("addpagehere", "lesson")."\n"; + "id&action=addbranchtable&pageid=$page->id\">". + get_string("addabranchtable", "lesson")." | "; + // the current page or the next page is an end of branch don't show EOB link + $nextqtype = 0; // set to anything else EOB + if ($page->nextpageid) { + $nextqtype = get_field("lesson_pages", "qtype", "id", $page->nextpageid); + } + if (($page->qtype != LESSON_ENDOFBRANCH) and ($nextqtype != LESSON_ENDOFBRANCH)) { + echo "id&action=addendofbranch&pageid=$page->id\">". + get_string("addanendofbranch", "lesson")." | "; + } + echo "id&action=addpage&pageid=$page->id\">". + get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). + "\n"; } echo "\n"; + // check the prev links - fix (silently) if necessary - there was a bug in + // versions 1 and 2 when add new pages. Not serious then as the backwards + // links were not used in those versions + if (isset($prevpageid)) { + if ($page->prevpageid != $prevpageid) { + // fix it + set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id); + if ($CFG->debug) { + echo "

***prevpageid of page $page->id set to $prevpageid***"; + } + } + } + $prevpageid = $page->id; + // move to next page if ($page->nextpageid) { if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { error("Teacher view: Next page not found!"); -- 2.39.5