I've been trying to get my head around how Moodle actually uses capabilities and contexts and such, but I've run into something strange that has thrown me completely and I have no idea what's going on.
I have created a few test capabilities:
1.
'block/elbp_timetable:student' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'student' => CAP_ALLOW,
)
)
2.
'block/elbp_timetable:teacher' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW
)
)
3.
'block/elbp:elbp_teacher' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW
)
)
As you can see the first two capabilities are defined in block "elbp_timetable", whilst the 3rd is defined in the block "elbp".
If I test capability #1 against Course ID 2, that works perfectly fine, it returns true if the user in question is a student on that course and false otherwise.
If I test capability #3 against Course ID 2, again that works fine, it returns true if the user in question is a teacher or non-editing teacher on that course, and false otherwise.
However, if I try it with capability #2 (which apart from the name and component) is identical to capability #3, it does not work. It returns false for a teacher who is indeed on that course, when it should return true.
I've gone into Adminsitration -> Define Roles and the teacher and editingteacher roles both have that "elbp_timetable:teacher" set to Allow, so there's nothing wrong there.
I just can't see why it works fine for one capability but not for an identical one in a different block, since I'm testing against the context of a course, the block itself isn't even relevant.
Could any shed any light on where I'm going wrong with this?
Cheers.