public function display_stopwatch(cm_info $cm, $stopwatch) { // TODO strings!!!! $timecompleted = ''; if (($userrecord = mod_stopwatch_get_user_record($cm)) && $userrecord->duration) { $class = 'class="stopped"'; $timevalue = mod_stopwatch_duration_to_string($userrecord->duration); $started = $userrecord->timecreated - $userrecord->duration; $completed = $userrecord->timecreated; // timecreated is when the record was created and it was created when user completed the module. $timestarted = $this->print_times($started, $completed); $stoplabel = 'Adjust'; } else { $this->page->requires->js_init_call('M.mod_stopwatch.init', array($cm->id), true); $class = ''; $timevalue = ''; $timestarted = $this->print_times(time()); $stoplabel = 'I\'m finished!'; } $sesskey = sesskey(); $action = new moodle_url('/mod/stopwatch/view.php'); $str = <<<EOD <form id="stopwatchform" method="POST" action="{$action}" {$class}> <input type="hidden" name="sesskey" value="{$sesskey}" /> <input type="hidden" name="id" value="{$cm->id}" /> <input type="hidden" name="cmd" value="updateduration" /> <div class="clockface"> <input id="clock" name="durationstr" value="{$timevalue}" class="clockdisplay" /> <input id="reset" type="button" value="Reset" class="graybutton" /> <div class="timestartedcompleted">{$timestarted}</div> </div> <br/> <input id="start" type="button" value="Start" class="greenbutton" /> <input id="resume" type="button" value="Resume" class="bigstopwatchbutton greenbutton" /> <input id="pause" type="button" value="Pause" class="bigstopwatchbutton yellowbutton" /> <input id="stop" type="submit" value="{$stoplabel}" class="bigstopwatchbutton redbutton" /> EOD; $str .= '</form><br/>'; $str .= $this->output->single_button(course_get_url($cm->course), get_string('back'), 'GET'); return $str; }
/** * Overwrites the content in the course-module object * * @param cm_info $cm */ function stopwatch_cm_info_view(cm_info $cm) { global $CFG; if ($cm->uservisible && has_capability('mod/stopwatch:view', $cm->context)) { require_once $CFG->dirroot . '/mod/stopwatch/locallib.php'; if (($record = mod_stopwatch_get_user_record($cm)) && $record->duration) { // TODO string $cm->set_content('Completed in <b>' . mod_stopwatch_duration_to_string($record->duration) . '</b> on ' . userdate($record->timecreated, '%d/%m/%y <b>%H:%M</b>')); } } }