User system role

User system role

by Luke Bridges -
Number of replies: 5
Is there a variable or method i can use to get what system/local/course role a user has been assigned to ?
Average of ratings: -
In reply to Luke Bridges

Re: User system role

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Luke,

firtly, why would you ever need it? The role itself is nothing but a named set of capabilities. As a developer you check if the current user has some capability and you do not care the role. You usually use has_capability() or require_capability() for this. See the public API defined in lib/accesslib.php
In reply to David Mudrák

Re: User system role

by Luke Bridges -

we have a role called parent, and need some text to only display to parents and no one else so am looking for somthing like isadmin() but for othe roles....

unless i create a custom capability ( but i dont know how)

In reply to Luke Bridges

Re: User system role

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Depending on where the text goes you may be able to control this already by clever use of other capabilities (e.g. for a label on course page I think you can make the label hidden, then override to give parents 'viewhiddenactivities' on just that label).


If not then yes you should create a new capability. For example if the text is part of a new plugin you're building, your new capability should go in the access.php of that plugin. If it is not part of a plugin then it should probably go in local/db/access.php. See docs/source for more details on capabilities.

If you really really want to ensure the text appears to parents and not to any other role, even admin, then don't forget to use the 'false' flag to $doanything when you check has_capability.


--sam
In reply to sam marshall

Re: User system role

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Luke -where are you wanting this text only to parents to appear? As Sam says,if it's something like a label or a block you can set it up so only parents can see it as in the docs here
But again - it depends on where you want this text.