/** * Creates the block content * * @return stdClass|stdObject */ public function get_content() { global $COURSE, $USER; $courseid = $COURSE->id; $context = context_course::instance($courseid); $blockid = $this->instance->id; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->footer = ""; $skills = get_user_skills($USER->id, $courseid); if (count($skills) > 0 && has_capability("block/skill_bars:viewpages", $context)) { $this->content->items[] = array(); $this->content->icons[] = array(); // Set the bar length and max values $bar_length = 100; $bar_height = 12; $bar_max = 100; if (isset($this->config)) { $bar_length = $this->config->bar_length; $bar_height = $this->config->bar_height; $bar_max = $this->config->bar_value; } for ($i = 0; $i < count($skills); $i++) { $this->content->items[$i] = ' ' . $skills[$i]->name; $this->content->icons[$i] = get_skillbar_icon($skills[$i]->points, $bar_max, $bar_length, $bar_height); // $pts = $skills[$i]->points / $bar_max * 100; // // TODO: find a better way to apply CSS // $bar_attributes = array('style' => 'width: '. $bar_length .'px; height: '. $bar_height .'px; position: relative; border: 1px solid #ccc;'); // $progress_attributes = array('style' => 'width: '. $pts .'%; height:100%; position: absolute; background-color: orange;'); // $this->content->items[$i] = ' '. $skills[$i]->name; // $this->content->icons[$i] = html_writer::start_div('bar_icon', $bar_attributes); // $this->content->icons[$i] .= html_writer::start_div('bar_icon_progress', $progress_attributes); // $this->content->icons[$i] .= html_writer::end_div() . html_writer::end_div(); } $profurl = new moodle_url('/blocks/skill_bars/view.php', array('blockid' => $blockid, 'courseid' => $courseid)); $this->content->footer .= html_writer::link($profurl, get_string('gotoprofile', 'block_skill_bars')); $this->content->footer .= html_writer::empty_tag('br'); } else { $profurl = new moodle_url('/blocks/skill_bars/view.php', array('blockid' => $blockid, 'courseid' => $courseid)); $this->content->footer .= html_writer::link($profurl, get_string('makeprofile', 'block_skill_bars')); $this->content->footer .= html_writer::empty_tag('br'); } if (has_capability("block/skill_bars:managepages", $context)) { $editurl = new moodle_url('/blocks/skill_bars/edit.php', array('blockid' => $blockid, 'courseid' => $courseid)); $updateurl = new moodle_url('/blocks/skill_bars/update.php', array('blockid' => $blockid, 'courseid' => $courseid)); $this->content->footer .= html_writer::link($editurl, get_string('editskills', 'block_skill_bars')); $this->content->footer .= html_writer::empty_tag('br'); $this->content->footer .= html_writer::link($updateurl, get_string('updateskills', 'block_skill_bars')); $this->content->footer .= html_writer::empty_tag('br'); } return $this->content; }
function block_print_user_table($blockid, $courseid, $skillmax, $return = false) { $context = context_course::instance($courseid); $userfields = 'u.id, u.firstname, u.lastname'; $userlist = get_enrolled_users($context, 'block/skill_bars:viewpages', 0, $userfields); $skillslist = get_course_skills($courseid); $headers = array('User'); foreach ($skillslist as $skill) { $headers[] = $skill->name; } $showlist = new html_table(); $showlist->head = $headers; $showlistdata = array(); foreach ($userlist as $user) { $fullname = $user->firstname . " " . $user->lastname; $skills = get_user_skills($user->id, $courseid); $record = array(); if (count($skills)) { $url = new moodle_url('/blocks/skill_bars/update.php', array('blockid' => $blockid, 'courseid' => $courseid, 'userid' => $user->id)); $link = html_writer::link($url, $fullname); $record[] = $link; foreach ($skills as $skill) { $record[] = get_skillbar_icon($skill->points, $skillmax); } } else { $record[] = $fullname; foreach ($skillslist as $skill) { $record[] = ''; } } $showlistdata[] = $record; } $showlist->data = $showlistdata; if ($return) { return html_writer::table($showlist); } else { echo html_writer::table($showlist); } }