0

Below is my code for showing an extra option in navigation-drawer of Moodle LMS account.

function local_report_extend_navigation(global_navigation $navigation)

{

$main_node = $navigation->add(get_string('pluginname', 'local_report'), '/local/report/');
$main_node->nodetype = 1;
$main_node->collapse = false;
$main_node->force_open = true;
$main_node->isexpandable = false;
$main_node->showinflatnavigation = true; 
// $main_node->icon = new pix_icon('i/settings', get_string('pluginname', 'local_report'));
$main_node->icon = new pix_icon('i/files', get_string('pluginname', 'local_report'));

} The output for it is : This is the navigation-drawer. I want to show the Reports option to only admin, teacher and manager

Can anyone let me know how to make this done?

1 Answers1

0

You will need to create a capability in your local plugin. In local/report/db/access.php

$capabilities = array(
    'local/report:canview' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes' => array(
            'manager' => CAP_ALLOW,
            'teacher' => CAP_ALLOW,
            'editingteacher' => CAP_ALLOW,
        ),
    ),
);

Then use something like this in your function.

if (!has_capability('local/report:canview', \context_system::instance())) {
    return;
}
Russell England
  • 9,436
  • 1
  • 27
  • 41
  • now the report option is completely hidden – Bilal Ahmed Jan 05 '22 at 19:10
  • When you add a new capability you also need to update the plugin. So bump the version number so the capability is installed. Then use a user with that capability to test it. – Russell England Jan 05 '22 at 21:47
  • I did as you said. The manager is having the access but whenever I logged in as a teacher ( editing ) the reports option is not visible. Only visible when I am an admin or a manager – Bilal Ahmed Jan 10 '22 at 13:28