MDL-63500 enrol_cohort: refactoring get_contexts_for_userid

This issue is part of the MDL-62560 Epic.
This commit is contained in:
Shamim Rezaie 2018-10-05 06:29:40 +10:00 committed by David Monllao
parent e66a60b9c0
commit b36687b5e2

View File

@ -68,23 +68,7 @@ class provider implements
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
$contextlist = new contextlist();
$sql = "SELECT ctx.id
FROM {groups_members} gm
JOIN {groups} g ON gm.groupid = g.id
JOIN {context} ctx ON g.courseid = ctx.instanceid AND ctx.contextlevel = :contextlevel
WHERE gm.userid = :userid
AND gm.component = 'enrol_cohort'";
$params = [
'contextlevel' => CONTEXT_COURSE,
'userid' => $userid
];
$contextlist->add_from_sql($sql, $params);
return $contextlist;
return \core_group\privacy\provider::get_contexts_for_group_member($userid, 'enrol_cohort');
}
/**