Exemple #1
0
/**
 * Adds a recycle bin link to the course admin menu.
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the tool
 * @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_course($navigation, $course, $context)
{
    global $PAGE;
    // Only add this settings item on non-site course pages.
    if (!$PAGE->course || $PAGE->course->id == SITEID || !\tool_recyclebin\course_bin::is_enabled()) {
        return null;
    }
    $coursebin = new \tool_recyclebin\course_bin($context->instanceid);
    // Check we can view the recycle bin.
    if (!$coursebin->can_view()) {
        return null;
    }
    $url = null;
    $settingnode = null;
    $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 = $coursebin->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);
}
Exemple #2
0
 * @package    tool_recyclebin
 * @copyright  2015 University of Kent
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../../../config.php';
require_once $CFG->libdir . '/tablelib.php';
$contextid = required_param('contextid', PARAM_INT);
$action = optional_param('action', null, PARAM_ALPHA);
$context = context::instance_by_id($contextid, MUST_EXIST);
$PAGE->set_context($context);
// We could be a course or a category.
switch ($context->contextlevel) {
    case CONTEXT_COURSE:
        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', '');
        }