Hopefully a role guru can help me with this. When updating the certificate mod for roles, I was hoping to code it to print the teachers on the certificate that are assigned the role of editing teachers at the module level. However, not only does it print the teachers that have been assigned for the mod, but it also prints the teachers assigned at the course level. I've tried different things using override, like setting certificate printteacher to allow instead of inherit, etc. but nothing I do prevents the course teacher from being printed on the certificate. Any help on how I can code this or set the roles to NOT print the teachers at the course level would be appreciated. Here's the code I am using.
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($teachers = get_users_by_capability($context, 'mod/certificate:printteacher')) {
Thanks
Hi Chardelle,
You might want to use
function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.lastname ASC', $view=false)
To get the role you can use
get_roles_with_capability().
Cheers,
Yu
You might want to use
function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.lastname ASC', $view=false)
To get the role you can use
get_roles_with_capability().
Cheers,
Yu
Thanks Zhang,
I see now that get_users_by_capability sort default is last access--so thanks for that tip. I can't get get_role_users to work--for some reason (I'm not using this as a lib function)
However, what I need is a function that gets users by capability by contextid. I still don't understand why this function doesn't do that--are you sure the sql is correct?. For example, for a certificate that has two teachers set (at the context level), in my role_assignments table I see those two users set for the teacher role (3) for that context (40). This is what I want to get--only those two users -- instead I am getting all of the users set for that role in the course.
Any more ideas?
I see now that get_users_by_capability sort default is last access--so thanks for that tip. I can't get get_role_users to work--for some reason (I'm not using this as a lib function)
However, what I need is a function that gets users by capability by contextid. I still don't understand why this function doesn't do that--are you sure the sql is correct?. For example, for a certificate that has two teachers set (at the context level), in my role_assignments table I see those two users set for the teacher role (3) for that context (40). This is what I want to get--only those two users -- instead I am getting all of the users set for that role in the course.
Any more ideas?