I'm new and need a little guidance with capabilities

Re: I'm new and need a little guidance with capabilities

by Dominique Palumbo -
Number of replies: 0
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

in the view.php I've something like that.
So I use the variable $mode to choose what I display to student or to teacher (or any adminstrative role that can create the activity).
Only teacher has the capability to create the module.

if (has_capability('mod/modulename:create', $modulecontext)) {
    $mode = 'teacher';
} else {
    require_capability('mod/modulename:view', $modulecontext); // This to exclude user that have no righ to the activity.
    $mode = 'student';
}

You can also create capabilities to read.
For teacher and manager and if the user don't have this capacity display something else.

'mod/modulename:viewhigh' => array(
    'captype' => 'read',
    'contextlevel' => CONTEXT_MODULE,
    'archetypes' => array(
    'teacher' => CAP_ALLOW,
    'editingteacher' => CAP_ALLOW,
    'manager' => CAP_ALLOW)
),

I hope it's help.