86 $this->
site_guid = $this->config->get(
'site_guid');
89 $this->access_cache = $cache;
119 $user_guid = $this->session->getLoggedInUserGuid();
131 return $cache[$hash];
135 $access =
"(" . implode(
",", $access_array) .
")";
137 if ($init_finished) {
179 $user_guid = $this->session->getLoggedInUserGuid();
192 $access_array = $cache[$hash];
199 $prefix =
$db->prefix;
204 $query =
"SELECT am.access_collection_id" 205 .
" FROM {$prefix}access_collection_membership am" 206 .
" LEFT JOIN {$prefix}access_collections ag ON ag.id = am.access_collection_id" 207 .
" WHERE am.user_guid = $user_guid AND (ag.site_guid = $site_guid OR ag.site_guid = 0)";
209 $collections =
$db->getData($query);
212 if (!empty($collection->access_collection_id)) {
213 $access_array[] = (int) $collection->access_collection_id;
219 $query =
"SELECT ag.id FROM {$prefix}access_collections ag ";
220 $query .=
"WHERE ag.owner_guid = $user_guid AND (ag.site_guid = $site_guid OR ag.site_guid = 0)";
222 $collections =
$db->getData($query);
225 if (!empty($collection->id)) {
226 $access_array[] = (int) $collection->id;
233 if ($ignore_access ==
true) {
238 if ($init_finished) {
239 $cache[$hash] = $access_array;
249 return $this->hooks->trigger(
'access:collections:read',
'user',
$options, $access_array);
296 'table_alias' =>
'e',
297 'user_guid' => $this->session->getLoggedInUserGuid(),
299 'access_column' =>
'access_id',
300 'owner_guid_column' =>
'owner_guid',
301 'guid_column' =>
'guid',
316 foreach (array(
'table_alias',
'access_column',
'owner_guid_column',
'guid_column') as
$key) {
322 $table_alias =
$options[
'table_alias'] ?
$options[
'table_alias'] .
'.' :
'';
324 if (!isset(
$options[
'ignore_access'])) {
333 $prefix = $this->db->prefix;
336 $clauses[
'ors'][
'ignore_access'] =
'1 = 1';
339 $clauses[
'ors'][
'friends_access'] =
"$table_alias{$options['access_column']} = " .
ACCESS_FRIENDS .
" 340 AND $table_alias{$options['owner_guid_column']} IN ( 341 SELECT guid_one FROM {$prefix}entity_relationships 342 WHERE relationship = 'friend' AND guid_two = {$options['user_guid']} 346 $clauses[
'ors'][
'owner_access'] =
"$table_alias{$options['owner_guid_column']} = {$options['user_guid']}";
352 $clauses[
'ors'][
'acl_access'] =
"$table_alias{$options['access_column']} IN {$access_list}";
355 if (
$options[
'use_enabled_clause']) {
356 $clauses[
'ands'][
'use_enabled'] =
"{$table_alias}enabled = 'yes'";
359 $clauses = $this->hooks->trigger(
'get_sql',
'access',
$options, $clauses);
362 if (is_array($clauses[
'ors']) && $clauses[
'ors']) {
363 $clauses_str =
'(' . implode(
' OR ', $clauses[
'ors']) .
')';
366 if (is_array($clauses[
'ands']) && $clauses[
'ands']) {
368 $clauses_str .=
' AND ';
370 $clauses_str .=
'(' . implode(
' AND ', $clauses[
'ands']) .
')';
373 return "($clauses_str)";
462 $user_guid = $this->session->getLoggedInUserGuid();
475 $access_array = $cache[$hash];
478 $access_array = array(
488 $access_array[$collection->id] = $collection->name;
492 if ($init_finished) {
493 $cache[$hash] = $access_array;
500 'input_params' => $input_params,
502 return $this->hooks->trigger(
'access:collections:write',
'user',
$options, $access_array);
566 $owner_guid = $this->session->getLoggedInUserGuid();
573 $prefix =
$db->prefix;
577 $q =
"INSERT INTO {$prefix}access_collections 578 SET name = '{$name}', 579 owner_guid = {$owner_guid}, 580 site_guid = {$site_guid}";
581 $id =
$db->insertData($q);
587 'collection_id' =>
$id 590 if (!$this->hooks->trigger(
'access:collections:addcollection',
'collection',
$params,
true)) {
620 $cur_members = (is_array($cur_members)) ? $cur_members : array();
622 $remove_members = array_diff($cur_members,
$members);
623 $add_members = array_diff(
$members, $cur_members);
627 foreach ($add_members as
$guid) {
631 foreach ($remove_members as $guid) {
649 if (!$this->hooks->trigger(
'access:collections:deletecollection',
'collection',
$params,
true)) {
654 $prefix =
$db->prefix;
657 $q =
"DELETE FROM {$prefix}access_collection_membership 658 WHERE access_collection_id = {$collection_id}";
661 $q =
"DELETE FROM {$prefix}access_collections 662 WHERE id = {$collection_id}";
685 $prefix =
$db->prefix;
687 $query =
"SELECT * FROM {$prefix}access_collections WHERE id = {$collection_id}";
688 $get_collection =
$db->getDataRow($query);
690 return $get_collection;
719 $result = $this->hooks->trigger(
'access:collections:add_user',
'collection',
$params,
true);
725 $prefix =
$db->prefix;
728 $q =
"INSERT INTO {$prefix}access_collection_membership 729 SET access_collection_id = $collection_id, user_guid = $user_guid 730 ON DUPLICATE KEY UPDATE user_guid = user_guid";
762 if (!$this->hooks->trigger(
'access:collections:remove_user',
'collection',
$params,
true)) {
767 $prefix =
$db->prefix;
769 $q =
"DELETE FROM {$prefix}access_collection_membership 770 WHERE access_collection_id = {$collection_id} 771 AND user_guid = {$user_guid}";
773 return (
bool)
$db->deleteData($q);
793 $prefix =
$db->prefix;
795 $query =
"SELECT * FROM {$prefix}access_collections 796 WHERE owner_guid = {$owner_guid} 797 AND site_guid = {$site_guid} 800 $collections =
$db->getData($query);
817 $prefix =
$db->prefix;
820 $query =
"SELECT e.* FROM {$prefix}access_collection_membership m" 821 .
" JOIN {$prefix}entities e ON e.guid = m.user_guid" 822 .
" WHERE m.access_collection_id = {$collection_id}";
823 $collection_members =
$db->getData($query,
"entity_row_to_elggstar");
825 $query =
"SELECT e.guid FROM {$prefix}access_collection_membership m" 826 .
" JOIN {$prefix}entities e ON e.guid = m.user_guid" 827 .
" WHERE m.access_collection_id = {$collection_id}";
828 $collection_members =
$db->getData($query);
829 if (!$collection_members) {
832 foreach ($collection_members as
$key => $val) {
833 $collection_members[
$key] = $val->guid;
837 return $collection_members;
849 $member_guid = (int) $member_guid;
857 $prefix =
$db->prefix;
859 $query =
"SELECT ac.* FROM {$prefix}access_collections ac 860 JOIN {$prefix}access_collection_membership m ON ac.id = m.access_collection_id 861 WHERE m.user_guid = {$member_guid} 862 AND ac.site_guid = {$site_guid} 865 $collections =
$db->getData($query);
888 $access = (int) $entity_access_id;
893 $access_array = array(
900 if (array_key_exists(
$access, $access_array)) {
904 $user_guid = $this->session->getLoggedInUserGuid();
907 return $translator->translate(
'access:limited:label');
922 return $translator->translate(
'access:limited:label');
getAccessList($user_guid=0, $site_guid=0, $flush=false)
Return a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause...
getCollectionsByMember($member_guid, $site_guid=0)
Return an array of database row objects of the access collections $entity_guid is a member of...
removeUser($user_guid, $collection_id)
Removes a user from an access collection.
if($guid==elgg_get_logged_in_user_guid()) $name
getMembers($collection_id, $guids_only=false)
Get all of members of an access collection.
getWriteAccessArray($user_guid=0, $site_guid=0, $flush=false, array $input_params=array())
Returns an array of access permissions that the user is allowed to save content with.
$CONFIG site_guid
The guid of the current site object.
hasAccessToEntity($entity, $user=null)
Can a user access an entity.
update($collection_id, $members)
Updates the membership in an access collection.
getAccessArray($user_guid=0, $site_guid=0, $flush=false)
Returns an array of access IDs a user is permitted to see.
$guid
Removes an admin notice.
getWhereSql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
sanitize_string($string)
Sanitizes a string for use in a query.
elgg_get_ignore_access()
Get current ignore access setting.
addUser($user_guid, $collection_id)
Adds a user to an access collection.
$init_finished
A flag to set if Elgg's access initialization is finished.
getEntityCollections($owner_guid, $site_guid=0)
Returns an array of database row objects of the access collections owned by $owner_guid.
elgg_check_access_overrides($user_guid=0)
Decides if the access system should be ignored for a user.
get_user($guid)
Get a user object from a GUID.
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
$ENTITY_SHOW_HIDDEN_OVERRIDE
Allow disabled entities and metadata to be returned by getter functions.
Exception indicating a user could not be looked up for a permissions check.
elgg global
Pointer to the global context.
create($name, $owner_guid=0, $site_guid=0)
Creates a new access collection.
getReadableAccessLevel($entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user owns ...
__construct(Conf $config, Database $db, EntityTable $entities, ElggStaticVariableCache $cache, PluginHooksService $hooks, ElggSession $session, Translator $translator)
Constructor.
sanitize_int($int, $signed=true)
Sanitizes an integer for database use.
$user_guid
Avatar remove action.
if(!$collection_name) $id
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
canEdit($collection_id, $user_guid=null)
Can the user change this access collection?