function getAccessArray($user_guid = 0, $flush = false)
{
global $init_finished;
$cache = $this->access_cache;
if ($flush) {
$cache->clear();
}
if ($user_guid == 0) {
$user_guid = $this->session->getLoggedInUserGuid();
}
$user_guid = (int) $user_guid;
$hash = $user_guid . 'get_access_array';
if ($cache[$hash]) {
$access_array = $cache[$hash];
} else {
$access_array = array(ACCESS_PUBLIC);
// The following can only return sensible data for a known user.
if ($user_guid) {
$db = $this->db;
$prefix = $db->prefix;
$access_array[] = ACCESS_LOGGED_IN;
// Get ACL memberships
$query = "SELECT am.access_collection_id" . " FROM {$prefix}access_collection_membership am" . " LEFT JOIN {$prefix}access_collections ag ON ag.id = am.access_collection_id" . " WHERE am.user_guid = {$user_guid}";
$collections = $db->getData($query);
if ($collections) {
foreach ($collections as $collection) {
if (!empty($collection->access_collection_id)) {
$access_array[] = (int) $collection->access_collection_id;
}
}
}
// Get ACLs owned.
$query = "SELECT ag.id FROM {$prefix}access_collections ag ";
$query .= "WHERE ag.owner_guid = {$user_guid}";
$collections = $db->getData($query);
if ($collections) {
foreach ($collections as $collection) {
if (!empty($collection->id)) {
$access_array[] = (int) $collection->id;
}
}
}
$ignore_access = elgg_check_access_overrides($user_guid);
if ($ignore_access == true) {
$access_array[] = ACCESS_PRIVATE;
}
}
if ($init_finished) {
$cache[$hash] = $access_array;
}
}
$options = array('user_id' => $user_guid);
// see the warning in the docs for this function about infinite loop potential
return $this->hooks->trigger('access:collections:read', 'user', $options, $access_array);
}