mirror of
https://github.com/moodle/moodle.git
synced 2025-03-21 08:00:37 +01:00
Merge branch 'wip-MDL-46486-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
1e12b5688c
@ -556,44 +556,6 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
has_capability('moodle/category:viewhiddencategories', $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all categories visible to the current user
|
||||
*
|
||||
* This is a generic function that returns an array of
|
||||
* (category id => coursecat object) sorted by sortorder
|
||||
*
|
||||
* @see coursecat::get_children()
|
||||
*
|
||||
* @return cacheable_object_array array of coursecat objects
|
||||
*/
|
||||
public static function get_all_visible() {
|
||||
global $USER;
|
||||
$coursecatcache = cache::make('core', 'coursecat');
|
||||
$ids = $coursecatcache->get('user'. $USER->id);
|
||||
if ($ids === false) {
|
||||
$all = self::get_all_ids();
|
||||
$parentvisible = $all[0];
|
||||
$rv = array();
|
||||
foreach ($all as $id => $children) {
|
||||
if ($id && in_array($id, $parentvisible) &&
|
||||
($coursecat = self::get($id, IGNORE_MISSING)) &&
|
||||
(!$coursecat->parent || isset($rv[$coursecat->parent]))) {
|
||||
$rv[$id] = $coursecat;
|
||||
$parentvisible += $children;
|
||||
}
|
||||
}
|
||||
$coursecatcache->set('user'. $USER->id, array_keys($rv));
|
||||
} else {
|
||||
$rv = array();
|
||||
foreach ($ids as $id) {
|
||||
if ($coursecat = self::get($id, IGNORE_MISSING)) {
|
||||
$rv[$id] = $coursecat;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the complete corresponding record from DB table course_categories
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user