Elgg\Database\AccessCollections::getAccessArray PHP Method

getAccessArray() public method

Can be overridden with the 'access:collections:read', 'user' plugin hook.
See also: get_write_access_array() for the access levels that a user can write to.
public getAccessArray ( integer $user_guid, boolean $flush = false ) : array
$user_guid integer User ID; defaults to currently logged in user
$flush boolean If set to true, will refresh the access ids from the database rather than using this function's cache.
return array An array of access collections ids
    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);
    }