2011年3月14日 星期一

Set up role permission

First, add this to \mod\your_module\db\access.php (after line $capabilities = array( )
    'mod/your_module:view' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_MODULE,
        'legacy' => array(
            'teacher' => CAP_ALLOW
        )
    )

Open \mod\your_module\lang\en\your_module.php, add this line:
$string['your_module:view'] = 'View your module';

Change version.php to new version, and then goto Notification.

Use this to test the permission:
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
has_capability('mod/your_module:view', $context)

沒有留言:

張貼留言