public function test_mod_stopwatch_duration_to_string() { $H = 3600; $M = 60; $this->assertEquals('01:15:20', mod_stopwatch_duration_to_string($H + 15 * $M + 20)); $this->assertEquals('00:04:59', mod_stopwatch_duration_to_string(4 * $M + 59)); $this->assertEquals('00:00:02', mod_stopwatch_duration_to_string(2)); $this->assertEquals('00:00:58', mod_stopwatch_duration_to_string(58)); }
public function display_grades(cm_info $cm, $stopwatch) { $sesskey = sesskey(); $action = new moodle_url('/mod/stopwatch/view.php'); $editlink = html_writer::link(new moodle_url('/course/modedit.php', array('update' => $cm->id)), 'Edit'); $str = ''; if ($stopwatch->grade > 0) { $str .= "<p>Maximum grade for the module is <b>{$stopwatch->grade}</b>. {$editlink}</p>"; } else { if ($stopwatch->grade < 0) { $str .= "<p>Scale grading is not yet implemented! {$editlink}</p>"; } else { $str .= "<p>No grading is enabled for this module. {$editlink}</p>"; } } $str = $str . <<<EOD <form id="stopwatchgradeform" method="POST" action="{$action}"> <input type="hidden" name="sesskey" value="{$sesskey}" /> <input type="hidden" name="id" value="{$cm->id}" /> <input type="hidden" name="cmd" value="updategrades" /> EOD; $table = new html_table(); $table->head = array('User', 'Duration', 'Completed on'); if ($stopwatch->grade) { $table->head[] = 'Grade'; $table->head[] = 'Graded on'; } $records = mod_stopwatch_get_all_users($cm, $stopwatch); foreach ($records as $record) { $duration = $record->duration ? mod_stopwatch_duration_to_string($record->duration) : ''; $durationinput = html_writer::empty_tag('input', array('type' => 'text', 'name' => "duration[{$record->userid}]", 'value' => $duration)); $data = (array) array(fullname($record), $durationinput, $record->timecreated ? userdate($record->timecreated, '%d/%m/%y <b>%H:%M</b>') : ''); if ($stopwatch->grade > 0) { $gradeinput = html_writer::empty_tag('input', array('type' => 'text', 'name' => "grade[{$record->userid}]", 'value' => strlen($record->grade) ? (double) $record->grade : '')); $data[] = $gradeinput; } else { if ($stopwatch->grade < 0) { $data[] = 'Not implemented, sorry....'; } } if ($stopwatch->grade) { $data[] = $record->timegraded ? userdate($record->timegraded, '%d/%m/%y <b>%H:%M</b>') : ''; } $table->data[] = $data; } $str .= html_writer::table($table); $str .= '<input id="grade" type="submit" value="Grade" />'; $str .= '</form >'; 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>')); } } }