Need a function that would reliably return the list of users who are able to see a particular activity.
\core_availability\info_module::filter_user_list() is not enough because it does not take into account permissions
How to get the list of users who can see a particular activity:
- For the normal course without guest access - take the list of enrolled users; otherwise take the list of all users
- If the course is not visible, filter out users without capability 'moodle/course:viewhidden' in the course context
- If the activity is hidden filter out users without capability 'moodle/course:viewhiddenactivities' in the module context
- If the capability 'mod/xxx:view' exist (xxx is the module type), filter out users without this capability in the module context
- If conditional availability is enabled users must either have capability 'moodle/course:viewhiddenactivities' in the module context or satisfy with conditions; method to filter list of users by conditional access is \core_availability\info_module::filter_user_list() (
MDL-48660is created to allow filter_user_list() take into account this cap)
Also the potential function should take additional filtering arguments $withcapability, $groupid as well as output arguments: $userfields, $orderby (will be especially great if it can also allow pagination).
Other problems that I foresee are:
- should we always hide suspended enrolments or have an argument for them?
- should we always filter by conditional access or have an argument for it? I imagine it will be interesting to respect group condition but ignore other-activity-completion-or-grade condition, what to do in this case?