PHP Class Elgg\Database\AccessCollections

Since: 1.10.0
Show file Open project: elgg/elgg

Protected Properties

Property Type Description
$access_cache
$config Elgg\Config
$db Elgg\Database
$entities EntityTable
$hooks Elgg\PluginHooksService
$session ElggSessio\ElggSession
$translator Elgg\I18n\Translator

Public Methods

Method Description
__construct ( Config $config, Database $db, EntityTable $entities, ElggStaticVariableCach\ElggStaticVariableCache $cache, PluginHooksService $hooks, ElggSessio\ElggSession $session, Translator $translator ) Constructor
addUser ( integer $user_guid, integer $collection_id ) : boolean Adds a user to an access collection.
canEdit ( integer $collection_id, mixed $user_guid = null ) : boolean Can the user change this access collection?
create ( string $name, integer $owner_guid ) : integer | false Creates a new access collection.
delete ( integer $collection_id ) : boolean Deletes a specified access collection and its membership.
get ( integer $collection_id ) : object | false Get a specified access collection
getAccessArray ( integer $user_guid, boolean $flush = false ) : array Returns an array of access IDs a user is permitted to see.
getAccessList ( integer $user_guid, boolean $flush = false ) : string Return a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause.
getCollectionsByMember ( integer $member_guid ) : array | false Return an array of database row objects of the access collections $entity_guid is a member of.
getEntityCollections ( integer $owner_guid ) : array | false Returns an array of database row objects of the access collections owned by $owner_guid.
getMembers ( integer $collection_id, boolean $guids_only = false ) : ElggUse\ElggUser[] | int[] | false Get all of members of an access collection
getReadableAccessLevel ( integer $entity_access_id ) : string Return the name of an ACCESS_* constant or an access collection, but only if the logged in user owns the access collection or is an admin.
getWhereSql ( array $options = [] ) : string Returns the SQL where clause for enforcing read access to data.
getWriteAccessArray ( integer $user_guid, boolean $flush = false, array $input_params = [] ) : array Returns an array of access permissions that the user is allowed to save content with.
hasAccessToEntity ( ElggEntit\ElggEntity $entity, ElggUse\ElggUser $user = null ) : boolean Can a user access an entity.
removeUser ( integer $user_guid, integer $collection_id ) : boolean Removes a user from an access collection.
update ( integer $collection_id, array $members ) : boolean Updates the membership in an access collection.

Method Details

__construct() public method

Constructor
public __construct ( Config $config, Database $db, EntityTable $entities, ElggStaticVariableCach\ElggStaticVariableCache $cache, PluginHooksService $hooks, ElggSessio\ElggSession $session, Translator $translator )
$config Elgg\Config Config
$db Elgg\Database Database
$entities EntityTable Entity table
$cache ElggStaticVariableCach\ElggStaticVariableCache Access cache
$hooks Elgg\PluginHooksService Hooks
$session ElggSessio\ElggSession Session
$translator Elgg\I18n\Translator Translator

addUser() public method

Triggers the 'access:collections:add_user', 'collection' plugin hook.
public addUser ( integer $user_guid, integer $collection_id ) : boolean
$user_guid integer The GUID of the user to add
$collection_id integer The ID of the collection to add them to
return boolean

canEdit() public method

Use the plugin hook of 'access:collections:write', 'user' to change this.
See also: get_write_access_array() for details on the hook. Respects access control disabling for admin users and {@link elgg_set_ignore_access()}
See also: get_write_access_array()
public canEdit ( integer $collection_id, mixed $user_guid = null ) : boolean
$collection_id integer The collection id
$user_guid mixed The user GUID to check for. Defaults to logged in user.
return boolean

create() public method

Access colletions allow plugins and users to create granular access for entities. Triggers plugin hook 'access:collections:addcollection', 'collection'
public create ( string $name, integer $owner_guid ) : integer | false
$name string The name of the collection.
$owner_guid integer The GUID of the owner (default: currently logged in user).
return integer | false The collection ID if successful and false on failure.

delete() public method

Deletes a specified access collection and its membership.
public delete ( integer $collection_id ) : boolean
$collection_id integer The collection ID
return boolean

get() public method

Get a specified access collection
See also: get_members_of_access_collection()
public get ( integer $collection_id ) : object | false
$collection_id integer The collection ID
return object | false

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

getAccessList() public method

Return a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause.
See also: get_access_array()
public getAccessList ( integer $user_guid, boolean $flush = false ) : string
$user_guid integer User ID; defaults to currently logged in user
$flush boolean If set to true, will refresh the access list from the database rather than using this function's cache.
return string A list of access collections suitable for using in an SQL call

getCollectionsByMember() public method

Return an array of database row objects of the access collections $entity_guid is a member of.
public getCollectionsByMember ( integer $member_guid ) : array | false
$member_guid integer The entity guid
return array | false

getEntityCollections() public method

Returns an array of database row objects of the access collections owned by $owner_guid.
public getEntityCollections ( integer $owner_guid ) : array | false
$owner_guid integer The entity guid
return array | false

getMembers() public method

Get all of members of an access collection
public getMembers ( integer $collection_id, boolean $guids_only = false ) : ElggUse\ElggUser[] | int[] | false
$collection_id integer The collection's ID
$guids_only boolean If set to true, will only return the members' GUIDs (default: false)
return ElggUse\ElggUser[] | int[] | false guids or entities if successful, false if not

getReadableAccessLevel() public method

Ownership requirement prevents us from exposing names of access collections that current user has been added to by other members and may contain sensitive classification of the current user (e.g. close friends vs acquaintances). Returns a string in the language of the user for global access levels, e.g.'Public, 'Friends', 'Logged in', 'Private'; or a name of the owned access collection, e.g. 'My work colleagues'; or a name of the group or other access collection, e.g. 'Group: Elgg technical support'; or 'Limited' if the user access is restricted to read-only, e.g. a friends collection the user was added to
Since: 1.11
public getReadableAccessLevel ( integer $entity_access_id ) : string
$entity_access_id integer The entity's access id
return string

getWhereSql() public method

Note that if this code is executed in privileged mode it will return (1=1). Otherwise it returns a where clause to retrieve the data that a user has permission to read. Plugin authors can hook into the 'get_sql', 'access' plugin hook to modify, remove, or add to the where clauses. The plugin hook will pass an array with the current ors and ands to the function in the form: array( 'ors' => array(), 'ands' => array() ) The results will be combined into an SQL where clause in the form: ((or1 OR or2 OR orN) AND (and1 AND and2 AND andN))
public getWhereSql ( array $options = [] ) : string
$options array Array in format: table_alias => STR Optional table alias. This is based on the select and join clauses. Default is 'e'. user_guid => INT Optional GUID for the user that we are retrieving data for. Defaults to the logged in user if null. Passing 0 will build a query for a logged out user (even if there is a logged in user) use_enabled_clause => BOOL Optional. Should we append the enabled clause? The default is set by access_show_hidden_entities(). access_column => STR Optional access column name. Default is 'access_id'. owner_guid_column => STR Optional owner_guid column. Default is 'owner_guid'. guid_column => STR Optional guid_column. Default is 'guid'.
return string

getWriteAccessArray() public method

Permissions returned are of the form (id => 'name'). Example return value in English: array( 0 => 'Private', -2 => 'Friends', 1 => 'Logged in users', 2 => 'Public', 34 => 'My favorite friends', ); Plugin hook of 'access:collections:write', 'user'
public getWriteAccessArray ( integer $user_guid, boolean $flush = false, array $input_params = [] ) : array
$user_guid integer The user's GUID.
$flush boolean If this is set to true, this will ignore a cached access array
$input_params array Some parameters passed into an input/access view
return array List of access permissions

hasAccessToEntity() public method

Can a user access an entity.
public hasAccessToEntity ( ElggEntit\ElggEntity $entity, ElggUse\ElggUser $user = null ) : boolean
$entity ElggEntit\ElggEntity The entity to check access for.
$user ElggUse\ElggUser Optionally user to check access for. Defaults to logged in user (which is a useless default).
return boolean

removeUser() public method

Triggers the 'access:collections:remove_user', 'collection' plugin hook.
public removeUser ( integer $user_guid, integer $collection_id ) : boolean
$user_guid integer The user GUID
$collection_id integer The access collection ID
return boolean

update() public method

Updates the membership in an access collection.
public update ( integer $collection_id, array $members ) : boolean
$collection_id integer The ID of the collection.
$members array Array of member GUIDs
return boolean

Property Details

$access_cache protected property

protected $access_cache

$config protected property

protected Config,Elgg $config
return Elgg\Config

$db protected property

protected Database,Elgg $db
return Elgg\Database

$entities protected property

protected EntityTable,Elgg\Database $entities
return EntityTable

$hooks protected property

protected PluginHooksService,Elgg $hooks
return Elgg\PluginHooksService

$session protected property

protected ElggSession,ElggSessio $session
return ElggSessio\ElggSession

$translator protected property

protected Translator,Elgg\I18n $translator
return Elgg\I18n\Translator