/** * Adds a recycle bin link to the course admin menu. * * @param navigation_node $navigation The navigation node to extend * @param context $context The context of the course * @return void|null return null if we don't want to display the node. */ function tool_recyclebin_extend_navigation_category_settings($navigation, $context) { global $PAGE; // Check if it is enabled. if (!\tool_recyclebin\category_bin::is_enabled()) { return null; } $categorybin = new \tool_recyclebin\category_bin($context->instanceid); // Check we can view the recycle bin. if (!$categorybin->can_view()) { return null; } $url = null; $settingnode = null; // Add a link to the category recyclebin. $url = new moodle_url('/admin/tool/recyclebin/index.php', array('contextid' => $context->id)); // If we are set to auto-hide, check the number of items. $autohide = get_config('tool_recyclebin', 'autohide'); if ($autohide) { $items = $categorybin->get_items(); if (empty($items)) { return null; } } // Add the recyclebin link. $pluginname = get_string('pluginname', 'tool_recyclebin'); $node = navigation_node::create($pluginname, $url, navigation_node::NODETYPE_LEAF, 'tool_recyclebin', 'tool_recyclebin', new pix_icon('trash', $pluginname, 'tool_recyclebin')); if ($PAGE->url->compare($url, URL_MATCH_BASE)) { $node->make_active(); } $navigation->add_node($node); }
require_login($context->instanceid); $recyclebin = new \tool_recyclebin\course_bin($context->instanceid); if (!$recyclebin->can_view()) { throw new required_capability_exception($context, 'tool/recyclebin:viewitems', 'nopermissions', ''); } $PAGE->set_pagelayout('incourse'); // Set the $PAGE heading - this is also the same as the h2 heading. $heading = format_string($COURSE->fullname, true, array('context' => $context)) . ': ' . get_string('pluginname', 'tool_recyclebin'); $PAGE->set_heading($heading); // Get the expiry to use later. $expiry = get_config('tool_recyclebin', 'coursebinexpiry'); break; case CONTEXT_COURSECAT: require_login(); $recyclebin = new \tool_recyclebin\category_bin($context->instanceid); if (!$recyclebin->can_view()) { throw new required_capability_exception($context, 'tool/recyclebin:viewitems', 'nopermissions', ''); } $PAGE->set_pagelayout('admin'); // Set the $PAGE heading. $PAGE->set_heading($COURSE->fullname); // The h2 heading on the page is going to be different than the $PAGE heading. $heading = $context->get_context_name() . ': ' . get_string('pluginname', 'tool_recyclebin'); // Get the expiry to use later. $expiry = get_config('tool_recyclebin', 'categorybinexpiry'); break; default: print_error('invalidcontext', 'tool_recyclebin'); break; } if (!$recyclebin::is_enabled()) {