From acab90991a77ef8165b848cdb36f9de3aec0913d Mon Sep 17 00:00:00 2001 From: michaelpenne Date: Wed, 16 Nov 2005 22:35:46 +0000 Subject: [PATCH] BUG FIX: progress bar now does not break when student reviews the lesson. BUG FIX: matching question type upgrade script now supports quotes. CHANGED: Improved labels for form elements to improve accessibility. NEW: added a skip navigation link for left menu. --- mod/lesson/action/continue.php | 4 ++ mod/lesson/db/mysql.php | 2 +- mod/lesson/db/postgres7.php | 2 +- mod/lesson/locallib.php | 109 ++++++++++++++++--------------- mod/lesson/styles.php | 6 ++ mod/lesson/view.php | 114 ++++++++++++++++----------------- 6 files changed, 125 insertions(+), 112 deletions(-) diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index ae7ef5f8057..631ae7f8e47 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -12,6 +12,8 @@ if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { // print the pages echo '
'; + // skip navigation link + echo ''; echo '
'."\n"; echo ''."\n"; echo ''."\n"; @@ -27,6 +29,8 @@ echo ''."\n"; echo '
'."\n"; echo '
'; + // skip to anchor + echo ''; } } diff --git a/mod/lesson/db/mysql.php b/mod/lesson/db/mysql.php index 8b41b10a486..480e68f5b46 100644 --- a/mod/lesson/db/mysql.php +++ b/mod/lesson/db/mysql.php @@ -60,7 +60,7 @@ function lesson_upgrade($oldversion) { foreach ($answers as $answer) { $answer->timecreated = $time; $answer->timemodified = 0; - insert_record('lesson_answers', $answer); + insert_record('lesson_answers', (object) array_map('addslashes', (array)$answer)); } } } diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index 919856f4252..39a5248c8a9 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -60,7 +60,7 @@ function lesson_upgrade($oldversion) { foreach ($answers as $answer) { $answer->timecreated = $time; $answer->timemodified = 0; - insert_record('lesson_answers', $answer); + insert_record('lesson_answers', (object) array_map('addslashes', (array)$answer)); } } } diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 796a7c6b16f..7d2a3850fe3 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -1159,71 +1159,74 @@ function lesson_print_progress_bar($lesson, $course) { notify(get_string('progressbarteacherwarning', 'lesson', $course->teachers)); return false; } - - // all of the lesson pages - if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id)) { - return false; - } else { - foreach ($pages as $page) { - if ($page->prevpageid == 0) { - $pageid = $page->id; // find the first page id - break; + if (!isset($USER->modattempts[$lesson->id])) { + // all of the lesson pages + if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id)) { + return false; + } else { + foreach ($pages as $page) { + if ($page->prevpageid == 0) { + $pageid = $page->id; // find the first page id + break; + } } } - } - // current attempt number - if (!$ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id)) { - $ntries = 0; // may not be necessary - } + // current attempt number + if (!$ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id)) { + $ntries = 0; // may not be necessary + } - $viewedpageids = array(); + $viewedpageids = array(); - // collect all of the correctly answered questions - if ($viewedpages = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries AND correct = 1", 'timeseen DESC', 'pageid, id')) { - $viewedpageids = array_keys($viewedpages); - } - // collect all of the branch tables viewed - if ($viewedbranches = get_records_select("lesson_branch", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", 'timeseen DESC', 'pageid, id')) { - $viewedpageids = array_merge($viewedpageids, array_keys($viewedbranches)); - } + // collect all of the correctly answered questions + if ($viewedpages = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries AND correct = 1", 'timeseen DESC', 'pageid, id')) { + $viewedpageids = array_keys($viewedpages); + } + // collect all of the branch tables viewed + if ($viewedbranches = get_records_select("lesson_branch", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", 'timeseen DESC', 'pageid, id')) { + $viewedpageids = array_merge($viewedpageids, array_keys($viewedbranches)); + } - // Filter out the following pages: - // End of Cluster - // End of Branch - // Pages found inside of Clusters - // Do not filter out Cluster Page(s) because we count a cluster as one. - // By keeping the cluster page, we get our 1 - $validpages = array(); - while ($pageid != 0) { - if ($pages[$pageid]->qtype == LESSON_CLUSTER) { - $clusterpageid = $pageid; // copy it - $validpages[$clusterpageid] = 1; // add the cluster page as a valid page - $pageid = $pages[$pageid]->nextpageid; // get next page + // Filter out the following pages: + // End of Cluster + // End of Branch + // Pages found inside of Clusters + // Do not filter out Cluster Page(s) because we count a cluster as one. + // By keeping the cluster page, we get our 1 + $validpages = array(); + while ($pageid != 0) { + if ($pages[$pageid]->qtype == LESSON_CLUSTER) { + $clusterpageid = $pageid; // copy it + $validpages[$clusterpageid] = 1; // add the cluster page as a valid page + $pageid = $pages[$pageid]->nextpageid; // get next page - // now, remove all necessary viewed paged ids from the viewedpageids array. - while ($pages[$pageid]->qtype != LESSON_ENDOFCLUSTER and $pageid != 0) { - if (in_array($pageid, $viewedpageids)) { - unset($viewedpageids[array_search($pageid, $viewedpageids)]); // remove it - // since the user did see one page in the cluster, add the cluster pageid to the viewedpageids - if (!in_array($clusterpageid, $viewedpageids)) { - $viewedpageids[] = $clusterpageid; + // now, remove all necessary viewed paged ids from the viewedpageids array. + while ($pages[$pageid]->qtype != LESSON_ENDOFCLUSTER and $pageid != 0) { + if (in_array($pageid, $viewedpageids)) { + unset($viewedpageids[array_search($pageid, $viewedpageids)]); // remove it + // since the user did see one page in the cluster, add the cluster pageid to the viewedpageids + if (!in_array($clusterpageid, $viewedpageids)) { + $viewedpageids[] = $clusterpageid; + } } + $pageid = $pages[$pageid]->nextpageid; } + } elseif ($pages[$pageid]->qtype == LESSON_ENDOFCLUSTER or $pages[$pageid]->qtype == LESSON_ENDOFBRANCH) { + // dont count these, just go to next + $pageid = $pages[$pageid]->nextpageid; + } else { + // a counted page + $validpages[$pageid] = 1; $pageid = $pages[$pageid]->nextpageid; } - } elseif ($pages[$pageid]->qtype == LESSON_ENDOFCLUSTER or $pages[$pageid]->qtype == LESSON_ENDOFBRANCH) { - // dont count these, just go to next - $pageid = $pages[$pageid]->nextpageid; - } else { - // a counted page - $validpages[$pageid] = 1; - $pageid = $pages[$pageid]->nextpageid; - } - } + } - // progress calculation as a percent - $progress = round(count($viewedpageids)/count($validpages), 2) * 100; + // progress calculation as a percent + $progress = round(count($viewedpageids)/count($validpages), 2) * 100; + } else { + $progress = 100; + } // print out the Progress Bar. Attempted to put as much as possible in the style sheets. echo '
'; diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php index 95f85ccc39f..458e2f99ff0 100644 --- a/mod/lesson/styles.php +++ b/mod/lesson/styles.php @@ -63,6 +63,12 @@ } +.mod-lesson .skip { + position: absolute; + left: -1000em; + width: 20em; +} + /*** *** Lesson Buttons diff --git a/mod/lesson/view.php b/mod/lesson/view.php index fcacbd4ce1d..cb6f2d64fca 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -433,6 +433,8 @@ // start of left menu if ($lesson->displayleft) { echo '"; + echo ''; if ($answer != end($answers)) { - echo ""; + echo ''; } $i++; } @@ -778,7 +783,7 @@ break; case LESSON_MATCHING : - echo "
'; + // skip navigation link + echo ''; if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { // print the pages echo '
'."\n"; @@ -456,6 +458,8 @@ $width = ' width="100%" '; } echo '
'; + // skip to anchor + echo ''; } elseif ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { echo '"; + echo "'; + echo ''; if ($answer != end($answers)) { echo ""; - } + } + $i++; } echo '
'; // only want this if no left menu } @@ -689,6 +693,10 @@ } echo ''; } + // default format text options + $options = new stdClass; + $options->para = false; // no

+ $options->noclean = true; switch ($page->qtype) { case LESSON_SHORTANSWER : case LESSON_NUMERICAL : @@ -697,8 +705,8 @@ } else { $value = ""; } - echo "
".get_string("youranswer", "lesson"). - ": \n"; + echo '
'. + ": \n"; echo '
'; print_simple_box_end(); echo "
"; + echo '
'; if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { - $checked = "checked=\"checked\""; + $checked = 'checked="checked"'; } else { - $checked = ""; + $checked = ''; } - echo "id}\" $checked />"; + echo "id}\" $checked />"; echo ""; - $options = new stdClass; - $options->para = false; // no

- $options->noclean = true; - echo format_text(trim($answer->answer), FORMAT_MOODLE, $options); - echo "

'; print_simple_box_end(); @@ -732,37 +739,35 @@ case LESSON_MULTICHOICE : $i = 0; shuffle($answers); + foreach ($answers as $answer) { - echo "
"; + echo '
'; if ($page->qoption) { - $checked = ""; + $checked = ''; if (isset($USER->modattempts[$lesson->id])) { $answerids = explode(",", $attempt->useranswer); if (in_array($answer->id, $answerids)) { - $checked = "checked=\"checked\""; + $checked = ' checked="checked"'; } else { - $checked = ""; + $checked = ''; } } // more than one answer allowed - echo "id}\" $checked />"; + echo "id}\"$checked />"; } else { if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { - $checked = "checked=\"checked\""; + $checked = ' checked="checked"'; } else { - $checked = ""; + $checked = ''; } // only one answer allowed - echo "id}\" $checked />"; + echo "id}\"$checked />"; } - echo ""; - $options = new stdClass; - $options->para = false; // no

- $options->noclean = true; - echo format_text(trim($answer->answer), FORMAT_MOODLE, $options); - echo "
'; + echo "'; + echo '


"; + echo '
'; // don't suffle answers (could be an option??) foreach ($answers as $answer) { // get all the response @@ -788,38 +793,33 @@ } shuffle($responses); $responses = array_unique($responses); - + + $responseoptions = array(); + foreach ($responses as $response) { + $responseoptions[htmlspecialchars(trim($response))] = $response; + } + if (isset($USER->modattempts[$lesson->id])) { - $useranswers = explode(",", $attempt->useranswer); + $useranswers = explode(',', $attempt->useranswer); $t = 0; } foreach ($answers as $answer) { if ($answer->response != NULL) { - echo ""; + echo ''; if ($answer != end($answers)) { - echo ""; + echo ''; } } } @@ -883,11 +883,11 @@ $options = new stdClass; $options->noclean = true; echo '
'.format_text($page->contents, FORMAT_MOODLE, $options).'
';; - echo "
"; - $options = new stdClass; - $options->para = false; - $options->noclean = true; - echo "".format_text($answer->answer,FORMAT_MOODLE,$options).": "; - echo "
'; + echo ": '; + if (isset($USER->modattempts[$lesson->id])) { - $selected = trim($answers[$useranswers[$t]]->response); - echo ""; - foreach ($responses as $response) { - if (trim($answers[$useranswers[$t]]->response) != $response) { - echo ""; - } - } + $selected = htmlspecialchars(trim($answers[$useranswers[$t]]->response)); // gets the user's previous answer + choose_from_menu ($responseoptions, "response[$answer->id]", $selected); $t++; } else { - echo ""; - foreach ($responses as $response) { - echo ""; - } + choose_from_menu ($responseoptions, "response[$answer->id]"); } - echo ""; - echo "


"; + echo '
'; } else { - echo "
"; + echo '
'; } - echo ""; + echo ''; if (!$lesson->slideshow) { if (!empty($buttons['next']) or !empty($buttons['prev'])) { @@ -910,11 +910,11 @@ } else { $value = ""; } - echo "
".get_string("youranswer", "lesson").":". - "\n"; - echo "
"; + echo '
:'. + '\n"; + echo '
'; print_simple_box_end(); - echo "