alternate function for isadmin() in moodle2.0

alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা
Number of replies: 8
hello all! i need a help reg isadmin() function which is not working in moodle2.0 is there any alternate function to check whether the admin is logged in or not.
রেটিং এর গড়: -
In reply to harish kumar

Re: alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Moodle HQ এর ছবি Moodle Workplace team এর ছবি Particularly helpful Moodlers এর ছবি Peer reviewers এর ছবি Plugin developers এর ছবি Testers এর ছবি
is_primary_admin() still exists, plus there's get_admin() and get_admins() wink
In reply to Paul Holden

Re: alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা

thanks Paul Holden but all the three are not working to check whether the admin is logged in or not in moodle2.0 ,as i want to display the category names which are assigned to that user only in index page but admin should display all categories so in that i need to use this code so,i need help in this regard.

In reply to harish kumar

Re: alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Peer reviewers এর ছবি Plugin developers এর ছবি
If this is just a permission check, use has_capability('somecapability', $currentcontext)

The traditional admin check is:

has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))

You can also use require_capability (when processing requests which should give an error if users don't have this permission).

--sam

PS There might be some specific cases where you need to know if a user is the primary admin, but actually I can't think of any except some already handled in core code...
In reply to sam marshall

Re: alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা
Plugin developers এর ছবি

Hi Sam Marshall I need a teacher capability to check login user is a teacher? If teacher, I want a different Home Page i.e, my custom page If student, a different page. Before we're using isteacher() function, Could you suggest me in Moodl2.0? Thanks Lavanya

In reply to Lavanya Manne

Re: alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Peer reviewers এর ছবি Plugin developers এর ছবি

Sure, here's my suggestion: go into define roles screen. Look at capabilities that teacher have, and compare with student to see ones student doesn't have. Pick a capability that seems appropriate.

If no capabilities seem appropriate, create a new one.

--sam

In reply to sam marshall

Re: alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা
Plugin developers এর ছবি

Hi Marshall,

Thanks for your reply

I tried them, but there is no such capability for checking loggined user is a teacher?

In reply to Lavanya Manne

Re: alternate function for isadmin() in moodle2.0

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Particularly helpful Moodlers এর ছবি Peer reviewers এর ছবি Plugin developers এর ছবি

There are plenty of capabilities that a teacher will have but a student won't, e.g. the ability to edit the course page, or the ability to enter grades.  Following Sam's instructions will show you which particular capabilities to look for programatically.

If you're trying to establish the role of a user whereever they are (i.e. not just within a partiuclar course) you'll need to assign them a role in the system context and check for a capaibility given to that role.