MDL-42192 accesslib: tweak get_all_capabilities

Tony thinks its bike shed painting, I think its a bit more readable
and memory efficient. I am using integrator dictatorship for sure.
This commit is contained in:
Dan Poltawski 2015-06-16 09:03:28 +01:00 committed by Eloy Lafuente (stronk7)
parent a6661ae013
commit a0dffaa946
2 changed files with 8 additions and 7 deletions

View File

@ -2976,18 +2976,19 @@ function get_capability_info($capabilityname) {
/**
* Returns all capabilitiy records, preferably from MUC and not database.
*
* @return array All capability records
* @return array All capability records indexed by capability name
*/
function get_all_capabilities() {
global $DB;
$cache = cache::make('core', 'capabilities');
if (!$allcaps = $cache->get('core_capabilities')) {
$allcaps = $DB->get_records('capabilities', null, '', 'name as uniquename, *');
foreach ($allcaps as $k => $v) {
unset($v->uniquename);
$v->riskbitmask = (int) $v->riskbitmask;
$allcaps[$k] = (array) $v;
$rs = $DB->get_recordset('capabilities');
$allcaps = array();
foreach ($rs as $capability) {
$capability->riskbitmask = (int) $capability->riskbitmask;
$allcaps[$capability->name] = (array) $capability;
}
$rs->close();
$cache->set('core_capabilities', $allcaps);
}
return $allcaps;

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2015061200.01; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2015061600.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.