/** * Creates the blocks main content * * @return string */ public function get_content() { global $USER, $COURSE, $CFG, $OUTPUT, $DB; // If content has already been generated, don't waste time generating it again. if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; $blockinstancesonpage = array(); // Guests do not have any progress. Don't show them the block. if (!isloggedin() or isguestuser()) { return $this->content; } // Draw the multi-bar content for the Dashboard and Front page. if (block_progress_on_site_page()) { $courses = enrol_get_my_courses(); $coursenametoshow = get_config('block_progress', 'coursenametoshow') ?: 'shortname'; $sql = "SELECT bi.id,\n bp.id AS blockpositionid,\n COALESCE(bp.region, bi.defaultregion) AS region,\n COALESCE(bp.weight, bi.defaultweight) AS weight,\n COALESCE(bp.visible, 1) AS visible,\n bi.configdata\n FROM {block_instances} bi\n LEFT JOIN {block_positions} bp ON bp.blockinstanceid = bi.id\n AND " . $DB->sql_like('bp.pagetype', ':pagetype', false) . "\n WHERE bi.blockname = 'progress'\n AND bi.parentcontextid = :contextid\n ORDER BY region, weight, bi.id"; foreach ($courses as $courseid => $course) { // Get specific block config and context. $modules = block_progress_modules_in_use($course->id); if ($course->visible && !empty($modules)) { $context = block_progress_get_course_context($course->id); $params = array('contextid' => $context->id, 'pagetype' => 'course-view-%'); $blockinstances = $DB->get_records_sql($sql, $params); $blockinstancesonpage = array_merge($blockinstancesonpage, array_keys($blockinstances)); foreach ($blockinstances as $blockid => $blockinstance) { $blockinstance->config = unserialize(base64_decode($blockinstance->configdata)); if (!empty($blockinstance->config)) { $blockinstance->events = block_progress_event_information($blockinstance->config, $modules, $course->id); $blockinstance->events = block_progress_filter_visibility($blockinstance->events, $USER->id, $context, $course); } if ($blockinstance->visible == 0 || empty($blockinstance->config) || $blockinstance->events == 0 || !empty($blockinstance->config->group) && !has_capability('moodle/site:accessallgroups', $context) && !groups_is_member($blockinstance->config->group, $USER->id)) { unset($blockinstances[$blockid]); } } // Output the Progress Bar. if (!empty($blockinstances)) { $courselink = new moodle_url('/course/view.php', array('id' => $course->id)); $linktext = HTML_WRITER::tag('h3', s($course->{$coursenametoshow})); $this->content->text .= HTML_WRITER::link($courselink, $linktext); } foreach ($blockinstances as $blockid => $blockinstance) { if ($blockinstance->config->progressTitle != '') { $this->content->text .= HTML_WRITER::tag('p', s(format_string($blockinstance->config->progressTitle))); } $attempts = block_progress_attempts($modules, $blockinstance->config, $blockinstance->events, $USER->id, $course->id); $this->content->text .= block_progress_bar($modules, $blockinstance->config, $blockinstance->events, $USER->id, $blockinstance->id, $attempts, $course->id); } } } // Show a message explaining lack of bars, but only while editing is on. if ($this->page->user_is_editing() && $this->content->text == '') { $this->content->text = get_string('no_blocks', 'block_progress'); } } else { // Check if user is in group for block. if (!empty($this->config->group) && !has_capability('moodle/site:accessallgroups', $this->context) && !groups_is_member($this->config->group, $USER->id)) { return $this->content; } // Check if any activities/resources have been created. $modules = block_progress_modules_in_use($COURSE->id); if (empty($modules)) { if (has_capability('moodle/block:edit', $this->context)) { $this->content->text .= get_string('no_events_config_message', 'block_progress'); } return $this->content; } // Check if activities/resources have been selected in config. $events = block_progress_event_information($this->config, $modules, $COURSE->id); $context = block_progress_get_course_context($COURSE->id); $events = block_progress_filter_visibility($events, $USER->id, $context); if ($events === null || $events === 0) { if (has_capability('moodle/block:edit', $this->context)) { $this->content->text .= get_string('no_events_message', 'block_progress'); if ($USER->editing) { $parameters = array('id' => $COURSE->id, 'sesskey' => sesskey(), 'bui_editid' => $this->instance->id); $url = new moodle_url('/course/view.php', $parameters); $label = get_string('selectitemstobeadded', 'block_progress'); $this->content->text .= $OUTPUT->single_button($url, $label); if ($events === 0) { $url->param('turnallon', '1'); $label = get_string('addallcurrentitems', 'block_progress'); $this->content->text .= $OUTPUT->single_button($url, $label); } } } return $this->content; } else { if (empty($events)) { if (has_capability('moodle/block:edit', $this->context)) { $this->content->text .= get_string('no_visible_events_message', 'block_progress'); } return $this->content; } } // Display progress bar. $attempts = block_progress_attempts($modules, $this->config, $events, $USER->id, $COURSE->id); $this->content->text = block_progress_bar($modules, $this->config, $events, $USER->id, $this->instance->id, $attempts, $COURSE->id); $blockinstancesonpage = array($this->instance->id); // Allow teachers to access the overview page. if (has_capability('block/progress:overview', $this->context)) { $parameters = array('progressbarid' => $this->instance->id, 'courseid' => $COURSE->id); $url = new moodle_url('/blocks/progress/overview.php', $parameters); $label = get_string('overview', 'block_progress'); $options = array('class' => 'overviewButton'); $this->content->text .= $OUTPUT->single_button($url, $label, 'post', $options); } } // Organise access to JS. $jsmodule = array('name' => 'block_progress', 'fullpath' => '/blocks/progress/module.js', 'requires' => array(), 'strings' => array()); $arguments = array($blockinstancesonpage, array($USER->id)); $this->page->requires->js_init_call('M.block_progress.init', $arguments, false, $jsmodule); return $this->content; }
$rows = array(); for ($i = $startuser; $i < $enduser; $i++) { if ($CFG->enablenotes || $CFG->messaging) { $selectattributes = array('type' => 'checkbox', 'class' => 'usercheckbox', 'name' => 'user' . $users[$i]->id); $select = html_writer::empty_tag('input', $selectattributes); } $picture = $OUTPUT->user_picture($users[$i], array('course' => $course->id)); $namelink = html_writer::link($CFG->wwwroot . '/user/view.php?id=' . $users[$i]->id . '&course=' . $course->id, fullname($users[$i])); if (empty($users[$i]->lastonlinetime)) { $lastonline = get_string('never'); } else { $lastonline = userdate($users[$i]->lastonlinetime); } $userevents = block_progress_filter_visibility($events, $users[$i]->id, $context, $course); if (!empty($userevents)) { $attempts = block_progress_attempts($modules, $progressconfig, $userevents, $users[$i]->id, $course->id); $progressbar = block_progress_bar($modules, $progressconfig, $userevents, $users[$i]->id, $progressblock->id, $attempts, $course->id, true); $progressvalue = block_progress_percentage($userevents, $attempts, true); $progress = $progressvalue . '%'; } else { $progressbar = get_string('no_visible_events_message', 'block_progress'); $progressvalue = 0; $progress = '?'; } $rows[] = array('firstname' => $users[$i]->firstname, 'lastname' => strtoupper($users[$i]->lastname), 'select' => $select, 'picture' => $picture, 'fullname' => $namelink, 'lastonlinetime' => $users[$i]->lastonlinetime, 'lastonline' => $lastonline, 'progressbar' => $progressbar, 'progressvalue' => $progressvalue, 'progress' => $progress); } // Build the table content and output. if ($sortbyprogress) { usort($rows, 'block_progress_compare_rows'); } if ($numberofusers > 0) {