/** * col_status * * @param xxx $row * @return xxx */ function col_status($row) { $text = hotpot::format_status($row->status); return $this->format_review_link($text, $row); }
/** * Print single activity item prepared by {@see hotpot_get_recent_mod_activity()} * * This function is called from: {@link course/recent.php} * * @param object $activity an object created by {@link get_recent_mod_activity()} * @param integer $courseid id in the "course" table * @param boolean $detail * true : print a link to the hotpot activity * false : do no print a link to the hotpot activity * @param xxx $modnames * @param xxx $viewfullnames * @return no return value is required */ function hotpot_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames) { global $CFG, $OUTPUT; require_once $CFG->dirroot . '/mod/hotpot/locallib.php'; static $dateformat = null; if (is_null($dateformat)) { $dateformat = get_string('strftimerecentfull'); } $table = new html_table(); $table->cellpadding = 3; $table->cellspacing = 0; if ($detail) { $row = new html_table_row(); $cell = new html_table_cell(' ', array('width' => 15)); $row->cells[] = $cell; // activity icon and link to activity $src = $OUTPUT->pix_url('icon', $activity->type); $img = html_writer::tag('img', array('src' => $src, 'class' => 'icon', $alt => $activity->name)); // link to activity $href = new moodle_url('/mod/hotpot/view.php', array('id' => $activity->cmid)); $link = html_writer::link($href, $activity->name); $cell = new html_table_cell("{$img} {$link}"); $cell->colspan = 6; $row->cells[] = $cell; $table->data[] = new html_table_row(array(new html_table_cell(' ', array('width' => 15)), new html_table_cell("{$img} {$link}"))); $table->data[] = $row; } $row = new html_table_row(); // set rowspan to (number of attempts) + 1 $rowspan = count($activity->attempts) + 1; $cell = new html_table_cell(' ', array('width' => 15)); $cell->rowspan = $rowspan; $row->cells[] = $cell; $picture = $OUTPUT->user_picture($activity->user, array('courseid' => $courseid)); $cell = new html_table_cell($picture, array('width' => 35, 'valign' => 'top', 'class' => 'forumpostpicture')); $cell->rowspan = $rowspan; $row->cells[] = $cell; $href = new moodle_url('/user/view.php', array('id' => $activity->user->userid, 'course' => $courseid)); $cell = new html_table_cell(html_writer::link($href, $activity->user->fullname)); $cell->colspan = 5; $row->cells[] = $cell; $table->data[] = $row; foreach ($activity->attempts as $attempt) { if ($attempt->duration) { $duration = '(' . hotpot::format_time($attempt->duration) . ')'; } else { $duration = ' '; } $href = new moodle_url('/mod/hotpot/review.php', array('id' => $attempt->id)); $link = html_writer::link($href, userdate($attempt->timemodified, $dateformat)); $table->data[] = new html_table_row(array(new html_table_cell($attempt->attempt), new html_table_cell($attempt->score . '%'), new html_table_cell(hotpot::format_status($attempt->status, true)), new html_table_cell($link), new html_table_cell($duration))); } echo html_writer::table($table); }
/** * format_attempt_data * * @param xxx $attempt * @param xxx $field * @param xxx $strtimeformat * @return xxx */ static function format_attempt_data($attempt, $field, $strtimeformat) { switch ($field) { case 'status': return hotpot::format_status($attempt->{$field}); case 'duration': return format_time($attempt->timemodified - $attempt->timestart); case 'timemodified': return trim(userdate($attempt->{$field}, $strtimeformat)); default: return $attempt->{$field}; } }
function hotpot_print_overview($courses, &$htmlarray) { global $CFG, $DB, $USER; require_once $CFG->dirroot . '/mod/hotpot/locallib.php'; if (empty($CFG->hotpot_enablemymoodle)) { return; // HotPots are not shown on MyMoodle on this site } if (!isset($courses) || !is_array($courses) || !count($courses)) { return; // no courses } if (!($hotpots = get_all_instances_in_courses('hotpot', $courses))) { return; // no hotpots } $strhotpot = get_string('modulename', 'mod_hotpot'); $strtimeopen = get_string('timeopen', 'mod_hotpot'); $strtimeclose = get_string('timeclose', 'mod_hotpot'); $strdateformat = get_string('strftimerecentfull'); $strattempted = get_string('attempted', 'mod_hotpot'); $strcompleted = get_string('completed', 'mod_hotpot'); $strnotattemptedyet = get_string('notattemptedyet', 'mod_hotpot'); $now = time(); foreach ($hotpots as $hotpot) { if ($hotpot->timeopen > $now || $hotpot->timeclose < $now) { continue; // skip activities that are not open, or are closed } $str = '' . '<div class="hotpot overview">' . '<div class="name">' . $strhotpot . ': ' . '<a ' . ($hotpot->visible ? '' : ' class="dimmed"') . 'title="' . $strhotpot . '" href="' . $CFG->wwwroot . '/mod/hotpot/view.php?id=' . $hotpot->coursemodule . '">' . format_string($hotpot->name) . '</a></div>'; if ($hotpot->timeopen) { $str .= '<div class="info">' . $strtimeopen . ': ' . userdate($hotpot->timeopen, $strdateformat) . '</div>'; } if ($hotpot->timeclose) { $str .= '<div class="info">' . $strtimeclose . ': ' . userdate($hotpot->timeclose, $strdateformat) . '</div>'; } $modulecontext = hotpot_get_context(CONTEXT_MODULE, $hotpot->coursemodule); if (has_capability('mod/hotpot:reviewallattempts', $modulecontext)) { // manager: show class grades stats // attempted: 99/99, completed: 99/99 if ($students = get_users_by_capability($modulecontext, 'mod/hotpot:attempt', 'u.id,u.id', 'u.id', '', '', 0, '', false)) { $count = count($students); $attempted = 0; $completed = 0; // search hotpot_attempts for highest status for each userid list($where, $params) = $DB->get_in_or_equal(array_keys($students)); $select = 'userid, SUM(CASE WHEN status = ' . hotpot::STATUS_COMPLETED . ' THEN 1 ELSE 0 END) AS iscompleted'; $from = '{hotpot_attempts}'; $where = 'userid ' . $where . ' AND hotpotid = ?'; $params[] = $hotpot->id; if ($attempts = $DB->get_records_sql("SELECT {$select} FROM {$from} WHERE {$where} GROUP BY userid", $params)) { $attempted = count($attempts); foreach ($attempts as $attempt) { if ($attempt->iscompleted) { $completed++; } } } unset($attempts); unset($students); $str .= '<div class="info">' . $strattempted . ': ' . $attempted . ' / ' . $count . ', ' . $strcompleted . ': ' . $completed . ' / ' . $count . '</div>'; } } else { // student: show grade and status if ($grade = hotpot_get_grades($hotpot, $USER->id, 'timestart')) { $grade = $grade[$USER->id]; $href = new moodle_url('/mod/hotpot/report.php', array('hp' => $hotpot->id)); if ($hotpot->gradeweighting) { $str .= '<div class="info">' . get_string('grade') . ': ' . '<a href="' . $href . '">' . $grade->rawgrade . '%</a></div>'; } $str .= '<div class="info">' . get_string('status', 'hotpot') . ': ' . '<a href="' . $href . '">' . hotpot::format_status($grade->maxstatus) . '</a></div>'; } } $str .= "</div>\n"; if (empty($htmlarray[$hotpot->course]['hotpot'])) { $htmlarray[$hotpot->course]['hotpot'] = $str; } else { $htmlarray[$hotpot->course]['hotpot'] .= $str; } } }