コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
$PAGE->set_url('/blocks/progress/overview.php', array('progressbarid' => $id, 'courseid' => $courseid, 'page' => $page, 'perpage' => $perpage));
$PAGE->set_context($context);
$title = get_string('overview', 'block_progress');
$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', $progressblockcontext);
// 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 = block_progress_modules_in_use($course->id);
if (empty($modules)) {
    echo get_string('no_events_config_message', 'block_progress');
    echo $OUTPUT->container_end();
    echo $OUTPUT->footer();
    die;
}
// Check if activities/resources have been selected in config.
$events = block_progress_event_information($progressconfig, $modules, $course->id);
if ($events == null) {
    echo get_string('no_events_message', 'block_progress');
    echo $OUTPUT->container_end();
    echo $OUTPUT->footer();
    die;
}
if (empty($events)) {