$capsearch ="";
}
+/// Set up SQL fragments for timestart, timeend etc
+ $now = time();
+ $timesql = "AND ((ra.timestart = 0 || ra.timestart < $now) && (ra.timeend = 0 || ra.timeend > $now))";
+
/// Then we use 1 giant SQL to bring out all relevant capabilities.
/// The first part gets the capabilities of orginal role.
/// The second part gets the capabilities of overriden roles.
$searchcontexts1
rc.contextid=$siteinstance->id
$capsearch
+ $timesql
GROUP BY
rc.capability, (c1.aggregatelevel * 100), c1.id
HAVING
$searchcontexts2
rc.contextid != $siteinstance->id
$capsearch
+ $timesql
GROUP BY
rc.capability, (c1.aggregatelevel * 100 + c2.aggregatelevel), c1.id
}
}
return $usercourses;
+}
+
+
+/** This function finds the roles assigned directly to this context only
+ * i.e. no parents role
+ * @param object $context
+ * @return array
+ */
+function get_roles_on_exact_context($context) {
+
+ global $CFG;
+ return get_records_sql("SELECT DISTINCT r.*
+ FROM {$CFG->prefix}role_assignments ra,
+ {$CFG->prefix}role r
+ WHERE ra.roleid = r.id
+ AND ra.contextid = $context->id");
+
}
\ No newline at end of file