/** * This generates the the structure of the course that won't be generated when * the modules and sections are added. * * Things such as the reports branch, the participants branch, blogs... get * added to the course node by this method. * * @param navigation_node $coursenode * @param stdClass $course * @return bool True for successfull generation */ public function add_front_page_course_essentials(navigation_node $coursenode, stdClass $course) { global $CFG; if ($coursenode == false || $coursenode->get('frontpageloaded', navigation_node::TYPE_CUSTOM)) { return true; } // Hidden node that we use to determine if the front page navigation is loaded. // This required as there are not other guaranteed nodes that may be loaded. $coursenode->add('frontpageloaded', null, self::TYPE_CUSTOM, null, 'frontpageloaded')->display = false; //Participants if (has_capability('moodle/course:viewparticipants', get_system_context())) { $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id=' . $course->id), self::TYPE_CUSTOM, get_string('participants'), 'participants'); } $filterselect = 0; // Blogs if (has_capability('moodle/blog:view', $this->page->context)) { require_once $CFG->dirroot . '/blog/lib.php'; if (blog_is_enabled_for_user()) { $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); $coursenode->add(get_string('blogs', 'blog'), $blogsurls->out()); } } // Notes if (!empty($CFG->enablenotes) && (has_capability('moodle/notes:manage', $this->page->context) || has_capability('moodle/notes:view', $this->page->context))) { $coursenode->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('filtertype' => 'course', 'filterselect' => $filterselect))); } // Tags if (!empty($CFG->usetags) && isloggedin()) { $coursenode->add(get_string('tags', 'tag'), new moodle_url('/tag/search.php')); } // View course reports if (has_capability('moodle/site:viewreports', $this->page->context)) { // basic capability for listing of reports $reportnav = $coursenode->add(get_string('reports'), new moodle_url('/course/report.php', array('id' => $course->id)), self::TYPE_CONTAINER, null, null, new pix_icon('i/stats', '')); $coursereports = get_plugin_list('coursereport'); foreach ($coursereports as $report => $dir) { $libfile = $CFG->dirroot . '/course/report/' . $report . '/lib.php'; if (file_exists($libfile)) { require_once $libfile; $reportfunction = $report . '_report_extend_navigation'; if (function_exists($report . '_report_extend_navigation')) { $reportfunction($reportnav, $course, $this->page->context); } } } } return true; }
/** * Get the blog options relating to the given module for the given user * * @staticvar array $moduleoptions Cache * @param stdClass|cm_info $module The module to get options for * @param stdClass $user The user to get options for null == currentuser * @return array */ function blog_get_options_for_module($module, $user = null) { global $CFG, $USER; // Cache static $moduleoptions = array(); $options = array(); // User must be logged in, blogs must be enabled if (!blog_is_enabled_for_user()) { return $options; } // Check the user can associate with the module $modcontext = context_module::instance($module->id); $sitecontext = context_system::instance(); if (!has_capability('moodle/blog:associatemodule', $modcontext)) { return $options; } // Generate the cache key $key = $module->id . ':'; if (!empty($user)) { $key .= $user->id; } else { $key .= $USER->id; } if (array_key_exists($key, $moduleoptions)) { // Serve from the cache so we don't have to regenerate return $moduleoptions[$module->id]; } $canparticipate = (is_enrolled($modcontext) or is_viewing($modcontext)); if (has_capability('moodle/blog:view', $modcontext)) { // Save correct module name for later usage. $modulename = get_string('modulename', $module->modname); // We can view! if ($CFG->bloglevel >= BLOG_SITE_LEVEL) { // View all entries about this module $a = new stdClass(); $a->type = $modulename; $options['moduleview'] = array('string' => get_string('viewallmodentries', 'blog', $a), 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id))); } // View MY entries about this module $options['moduleviewmine'] = array('string' => get_string('viewmyentriesaboutmodule', 'blog', $modulename), 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id, 'userid' => $USER->id))); if (!empty($user) && $CFG->bloglevel >= BLOG_SITE_LEVEL) { // View the given users entries about this module $a = new stdClass(); $a->mod = $modulename; $a->user = fullname($user); $options['moduleviewuser'] = array('string' => get_string('blogentriesbyuseraboutmodule', 'blog', $a), 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id, 'userid' => $user->id))); } } if (has_capability('moodle/blog:create', $sitecontext) and $canparticipate) { // The user can blog about this module $options['moduleadd'] = array('string' => get_string('blogaboutthismodule', 'blog', $modulename), 'link' => new moodle_url('/blog/edit.php', array('action' => 'add', 'modid' => $module->id))); } // Cache the options $moduleoptions[$key] = $options; // Return the options return $options; }
/** * Add nodes to myprofile page. * * @param \core_user\output\myprofile\tree $tree Tree object * @param stdClass $user user object * @param bool $iscurrentuser * @param stdClass $course Course object * * @return bool */ function core_blog_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) { global $CFG; if (!blog_is_enabled_for_user() || isguestuser($user)) { // The guest user cannot post, so it is not possible to view any posts. // Also blogs might be disabled. // May as well just bail aggressively here. return true; } if (!blog_user_can_view_user_entry($user->id)) { return true; } $url = new moodle_url("/blog/index.php", array('userid' => $user->id)); if (!empty($course)) { $url->param('courseid', $course->id); } if ($iscurrentuser) { $title = get_string('blogentries', 'core_blog'); } else { $title = get_string('myprofileuserblogs', 'core_blog'); } $blognode = new core_user\output\myprofile\node('miscellaneous', 'blogs', $title, null, $url); $tree->add_node($blognode); return true; }