assigning only students to see popup

Re: assigning only students to see popup

by Purnendu Dash -
Number of replies: 0
Picture of Plugin developers

Dear Boris,

Just to keep you are informed, 'if(has_capability('...'))' , also known as legacy capability, has become obsolete in the advanced versions of Moodle. You may preferably do this with the predefined moodle function, as shown below:

global $USER;

$context = context_user::instance($USER->id);

Or

$context = get_context_instance(CONTEXT_MODULE, $cm->id); //where $cm->id is the course module id

$roles = get_user_roles($context, $USER->id, true);

foreach($roles as $role => $roleVal) {

if($roleVal->roleid == 5) {

// write your popup code here

}

Note:- By default the role id for student is 5. To confirm the role id refer to mdl_role table in your Moodle instance database.

To get various contexts of users  with respect to courses you may refer to the following link:- 

http://docs.moodle.org/dev/Access_API

Kindly let me know if this is useful.

Keep moodling smile

Purnendu

DualCube