|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00028 require_once("../../config.php"); 00029 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 00030 00031 $id = required_param('id', PARAM_INT); 00032 00033 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);; 00034 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00035 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST)); 00036 00037 require_login($course, false, $cm); 00038 require_sesskey(); 00039 00040 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00041 $canmanage = has_capability('mod/lesson:manage', $context); 00042 $lessonoutput = $PAGE->get_renderer('mod_lesson'); 00043 00044 $url = new moodle_url('/mod/lesson/continue.php', array('id'=>$cm->id)); 00045 $PAGE->set_url($url); 00046 $PAGE->navbar->add(get_string('continue', 'lesson')); 00047 00048 // This is the code updates the lesson time for a timed test 00049 // get time information for this user 00050 if (!$canmanage) { 00051 $lesson->displayleft = lesson_displayleftif($lesson); 00052 $timer = $lesson->update_timer(); 00053 if ($lesson->timed) { 00054 $timeleft = ($timer->starttime + $lesson->maxtime * 60) - time(); 00055 if ($timeleft <= 0) { 00056 // Out of time 00057 $lesson->add_message(get_string('eolstudentoutoftime', 'lesson')); 00058 redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id,'pageid'=>LESSON_EOL, 'outoftime'=>'normal'))); 00059 } else if ($timeleft < 60) { 00060 // One minute warning 00061 $lesson->add_message(get_string("studentoneminwarning", "lesson")); 00062 } 00063 } 00064 } else { 00065 $timer = new stdClass; 00066 } 00067 00068 // record answer (if necessary) and show response (if none say if answer is correct or not) 00069 $page = $lesson->load_page(required_param('pageid', PARAM_INT)); 00070 00071 $userhasgrade = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id)); 00072 $reviewmode = false; 00073 if ($userhasgrade && !$lesson->retake) { 00074 $reviewmode = true; 00075 } 00076 00077 // Check the page has answers [MDL-25632] 00078 if (count($page->answers) > 0) { 00079 $result = $page->record_attempt($context); 00080 } else { 00081 // The page has no answers so we will just progress to the next page in the 00082 // sequence (as set by newpageid). 00083 $result = new stdClass; 00084 $result->newpageid = optional_param('newpageid', $page->nextpageid, PARAM_INT); 00085 $result->nodefaultresponse = true; 00086 } 00087 00088 if (isset($USER->modattempts[$lesson->id])) { 00089 // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time 00090 if ($USER->modattempts[$lesson->id]->pageid == $page->id && $page->nextpageid == 0) { // remember, this session variable holds the pageid of the last page that the user saw 00091 $result->newpageid = LESSON_EOL; 00092 } else { 00093 $nretakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id)); 00094 $nretakes--; // make sure we are looking at the right try. 00095 $attempts = $DB->get_records("lesson_attempts", array("lessonid"=>$lesson->id, "userid"=>$USER->id, "retry"=>$nretakes), "timeseen", "id, pageid"); 00096 $found = false; 00097 $temppageid = 0; 00098 foreach($attempts as $attempt) { 00099 if ($found && $temppageid != $attempt->pageid) { // now try to find the next page, make sure next few attempts do no belong to current page 00100 $result->newpageid = $attempt->pageid; 00101 break; 00102 } 00103 if ($attempt->pageid == $page->id) { 00104 $found = true; // if found current page 00105 $temppageid = $attempt->pageid; 00106 } 00107 } 00108 } 00109 } elseif ($result->newpageid != LESSON_CLUSTERJUMP && $page->id != 0 && $result->newpageid > 0) { 00110 // going to check to see if the page that the user is going to view next, is a cluster page. 00111 // If so, dont display, go into the cluster. The $result->newpageid > 0 is used to filter out all of the negative code jumps. 00112 $newpage = $lesson->load_page($result->newpageid); 00113 if ($newpageid = $newpage->override_next_page($result->newpageid)) { 00114 $result->newpageid = $newpageid; 00115 } 00116 } elseif ($result->newpageid == LESSON_UNSEENBRANCHPAGE) { 00117 if ($canmanage) { 00118 if ($page->nextpageid == 0) { 00119 $result->newpageid = LESSON_EOL; 00120 } else { 00121 $result->newpageid = $page->nextpageid; 00122 } 00123 } else { 00124 $result->newpageid = lesson_unseen_question_jump($lesson, $USER->id, $page->id); 00125 } 00126 } elseif ($result->newpageid == LESSON_PREVIOUSPAGE) { 00127 $result->newpageid = $page->prevpageid; 00128 } elseif ($result->newpageid == LESSON_RANDOMPAGE) { 00129 $result->newpageid = lesson_random_question_jump($lesson, $page->id); 00130 } elseif ($result->newpageid == LESSON_CLUSTERJUMP) { 00131 if ($canmanage) { 00132 if ($page->nextpageid == 0) { // if teacher, go to next page 00133 $result->newpageid = LESSON_EOL; 00134 } else { 00135 $result->newpageid = $page->nextpageid; 00136 } 00137 } else { 00138 $result->newpageid = $lesson->cluster_jump($page->id); 00139 } 00140 } 00141 00142 if ($result->nodefaultresponse) { 00143 // Don't display feedback 00144 redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id,'pageid'=>$result->newpageid))); 00145 } 00146 00148 00149 if ($canmanage) { 00150 // This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher 00151 if(lesson_display_teacher_warning($lesson)) { 00152 $warningvars = new stdClass(); 00153 $warningvars->cluster = get_string("clusterjump", "lesson"); 00154 $warningvars->unseen = get_string("unseenpageinbranch", "lesson"); 00155 $lesson->add_message(get_string("teacherjumpwarning", "lesson", $warningvars)); 00156 } 00157 // Inform teacher that s/he will not see the timer 00158 if ($lesson->timed) { 00159 $lesson->add_message(get_string("teachertimerwarning", "lesson")); 00160 } 00161 } 00162 // Report attempts remaining 00163 if ($result->attemptsremaining != 0 && !$lesson->review && !$reviewmode) { 00164 $lesson->add_message(get_string('attemptsremaining', 'lesson', $result->attemptsremaining)); 00165 } 00166 // Report if max attempts reached 00167 if ($result->maxattemptsreached != 0 && !$lesson->review && !$reviewmode) { 00168 $lesson->add_message('('.get_string("maximumnumberofattemptsreached", "lesson").')'); 00169 } 00170 00171 $PAGE->set_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id)); 00172 $PAGE->set_subpage($page->id); 00173 00175 lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer); 00176 echo $lessonoutput->header($lesson, $cm, 'view', true, $page->id); 00177 00178 if ($lesson->displayleft) { 00179 echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>'; 00180 } 00181 // This calculates and prints the ongoing score message 00182 if ($lesson->ongoing && !$reviewmode) { 00183 echo $lessonoutput->ongoing_score($lesson); 00184 } 00185 echo $result->feedback; 00186 00187 // User is modifying attempts - save button and some instructions 00188 if (isset($USER->modattempts[$lesson->id])) { 00189 $url = $CFG->wwwroot.'/mod/lesson/view.php'; 00190 $content = $OUTPUT->box(get_string("gotoendoflesson", "lesson"), 'center'); 00191 $content .= $OUTPUT->box(get_string("or", "lesson"), 'center'); 00192 $content .= $OUTPUT->box(get_string("continuetonextpage", "lesson"), 'center'); 00193 $content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$cm->id)); 00194 $content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'pageid', 'value'=>LESSON_EOL)); 00195 $content .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'submit', 'value'=>get_string('finish', 'lesson'))); 00196 echo html_writer::tag('form', "<div>$content</div>", array('method'=>'post', 'action'=>$url)); 00197 } 00198 00199 // Review button back 00200 if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode && $lesson->review) { 00201 $url = $CFG->wwwroot.'/mod/lesson/view.php'; 00202 $content = html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$cm->id)); 00203 $content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'pageid', 'value'=>$page->id)); 00204 $content .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'submit', 'value'=>get_string('reviewquestionback', 'lesson'))); 00205 echo html_writer::tag('form', "<div class=\"singlebutton\">$content</div>", array('method'=>'post', 'action'=>$url)); 00206 } 00207 00208 $url = new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id, 'pageid'=>$result->newpageid)); 00209 if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion) { 00210 // Review button continue 00211 echo $OUTPUT->single_button($url, get_string('reviewquestioncontinue', 'lesson')); 00212 } else { 00213 // Normal continue button 00214 echo $OUTPUT->single_button($url, get_string('continue', 'lesson')); 00215 } 00216 00217 echo $lessonoutput->footer();