/** * If a timed lesson and not a teacher, then * return a block_contents containing the clock. * * @param int $cmid Course Module ID for this lesson * @param object $lesson Full lesson record object * @param object $timer Full timer record object * @return block_contents **/ function lesson_clock_block_contents($cmid, $lesson, $timer, $page) { // Display for timed lessons and for students only $context = get_context_instance(CONTEXT_MODULE, $cmid); if (!$lesson->timed || has_capability('mod/lesson:manage', $context)) { return null; } $content = '<div class="jshidewhenenabled">'; $content .= lesson_print_time_remaining($timer->starttime, $lesson->maxtime, true) . "\n"; $content .= '</div>'; $clocksettings = array('starttime' => $timer->starttime, 'servertime' => time(), 'testlength' => $lesson->maxtime * 60); $content .= $page->requires->data_for_js('clocksettings', $clocksettings)->now(); $content .= $page->requires->js('mod/lesson/timer.js')->now(); $content .= $page->requires->js_function_call('show_clock')->now(); $bc = new block_contents(); $bc->title = get_string('timeremaining', 'lesson'); $bc->set_classes('clock'); $bc->content = $content; return $bc; }
/** * If a timed lesson and not a teacher, then * print the clock * * @param int $cmid Course Module ID for this lesson * @param object $lesson Full lesson record object * @param object $timer Full timer record object * @return void **/ function lesson_print_clock_block($cmid, $lesson, $timer) { global $CFG; $context = get_context_instance(CONTEXT_MODULE, $cmid); // Display for timed lessons and for students only if ($lesson->timed and !has_capability('mod/lesson:manage', $context) and !empty($timer)) { $content = '<script type="text/javascript" charset="utf-8">' . "\n"; $content .= "<!--\n"; $content .= ' var starttime = ' . $timer->starttime . ";\n"; $content .= ' var servertime = ' . time() . ";\n"; $content .= ' var testlength = ' . $lesson->maxtime * 60 . ";\n"; $content .= ' document.write(\'<script type="text/javascript" src="' . $CFG->wwwroot . '/mod/lesson/timer.js" charset="utf-8"><\\/script>\');' . "\n"; $content .= " window.onload = function () { show_clock(); };\n"; $content .= "// -->\n"; $content .= "</script>\n"; $content .= "<noscript>\n"; $content .= lesson_print_time_remaining($timer->starttime, $lesson->maxtime, true) . "\n"; $content .= "</noscript>\n"; print_side_block(get_string('timeremaining', 'lesson'), $content, NULL, NULL, '', array('class' => 'clock'), get_string('timeremaining', 'lesson')); } }