/** * Creates the blocks main content * * @return string */ public function get_content() { // Access to settings needed global $USER, $COURSE, $CFG, $DB, $OUTPUT; // 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 = ''; // Check if any activities/resources have been created $modules = modules_in_use(); 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 = event_information($this->config, $modules); 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; } else { $attempts = get_attempts($modules, $this->config, $events, $USER->id, $this->instance->id); $this->content->text = progress_bar($modules, $this->config, $events, $USER->id, $this->instance->id, $attempts); } } // Organise access to JS $jsmodule = array('name' => 'block_progress', 'fullpath' => '/blocks/progress/module.js', 'requires' => array(), 'strings' => array(array('time_expected', 'block_progress'))); $displaydate = !isset($this->config->displayNow) || $this->config->displayNow == 1; $arguments = array($CFG->wwwroot, array_keys($modules), $displaydate); $this->page->requires->js_init_call('M.block_progress.init', $arguments, false, $jsmodule); // Allow teachers to access the overview page if (has_capability('block/progress:overview', $this->context)) { $parameters = array('id' => $this->instance->id, 'courseid' => $COURSE->id); $url = new moodle_url('/blocks/progress/overview.php', $parameters); $label = get_string('overview', 'block_progress'); $this->content->text .= $OUTPUT->single_button($url, $label); } return $this->content; }
/** * Creates the blocks main content * * @return string */ public function get_content() { // Access to settings needed global $USER, $COURSE, $CFG, $DB, $OUTPUT; // 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 = ''; // Check if any activities/resources have been created $modules = modules_in_use(); 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 = event_information($this->config, $modules); $attempts = get_attempts($modules, $this->config, $events, $USER->id, $this->instance->id); $this->content->text = progress_bar($modules, $this->config, $events, $USER->id, $this->instance->id, $attempts); // Organise access to JS $jsmodule = array('name' => 'block_progress', 'fullpath' => '/blocks/progress/module.js', 'requires' => array(), 'strings' => array(array('time_expected', 'block_progress'))); $displaydate = !isset($this->config->displayNow) || $this->config->displayNow == 1; $arguments = array($CFG->wwwroot, array_keys($modules), $displaydate); $this->page->requires->js_init_call('M.block_progress.init', $arguments, false, $jsmodule); return $this->content; }
$PAGE->set_title($title); $PAGE->set_heading($title); $PAGE->navbar->add($title); $PAGE->set_pagelayout('standard'); // Check user is logged in and capable of grading require_login($course, false); require_capability('block/progress:overview', $context); // Get specific block config $block = $DB->get_record('block_instances', array('id' => $id)); $config = unserialize(base64_decode($block->configdata)); // Start page output echo $OUTPUT->header(); echo $OUTPUT->heading($title, 2); echo $OUTPUT->container_start('block_progress'); // Get the modules to check progress on $modules = modules_in_use(); if (empty($modules)) { echo get_string('no_events_config_message', 'block_progress'); echo $OUTPUT->footer(); die; } // Check if activities/resources have been selected in config $events = event_information($config, $modules); if ($events == null) { echo get_string('no_events_message', 'block_progress'); echo $OUTPUT->footer(); die; } if (empty($events)) { echo get_string('no_visible_events_message', 'block_progress'); echo $OUTPUT->footer();