107 $this->access_cache = $cache;
112 $this->table =
"{$this->db->prefix}access_collections";
113 $this->membership_table =
"{$this->db->prefix}access_collection_membership";
122 $this->init_complete =
true;
138 $access_ids = implode(
',', $access_array);
139 $list =
"($access_ids)";
143 $this->access_cache->add($hash,
$list);
180 $user_guid = $this->session->getLoggedInUserGuid();
188 $access_array = $cache[$hash];
200 FROM {$this->table} ac 201 WHERE ac.owner_guid = :user_guid 203 FROM {$this->membership_table} 204 WHERE access_collection_id = ac.id 205 AND user_guid = :user_guid) 208 $collections = $this->db->getData(
$query, null, [
212 if (!empty($collections)) {
213 foreach ($collections as $collection) {
214 $access_array[] = (int) $collection->id;
218 $ignore_access = $this->capabilities->canBypassPermissionsCheck(
$user_guid);
220 if ($ignore_access ===
true) {
225 if ($this->init_complete) {
226 $cache[$hash] = $access_array;
235 return $this->hooks->trigger(
'access:collections:read',
'user',
$options, $access_array);
322 $user_guid = $this->session->getLoggedInUserGuid();
327 $hash =
$user_guid .
'get_write_access_array';
330 $access_array = $cache[$hash];
339 if (!empty($collections)) {
340 foreach ($collections as $collection) {
341 $access_array[$collection->id] = $collection->getDisplayName();
345 if ($this->init_complete) {
346 $cache[$hash] = $access_array;
355 $access_array = $this->hooks->trigger(
'access:collections:write',
'user',
$options, $access_array);
359 if (!isset($access_array[$access])) {
363 $temp = $access_array[
$access];
364 unset($access_array[$access]);
365 $access_array[
$access] = $temp;
369 return $access_array;
393 $collection = $this->
get($collection_id);
399 if ($this->capabilities->canBypassPermissionsCheck(
$user->guid)) {
404 return array_key_exists($collection_id, $write_access);
433 _elgg_services()->logger->error(
"The subtype length for access collections cannot be greater than 255");
439 $owner_guid = $this->session->getLoggedInUserGuid();
443 INSERT INTO {$this->table} 446 owner_guid = :owner_guid 460 $this->access_cache->clear();
463 'collection_id' =>
$id,
469 if (!$this->hooks->trigger(
'access:collections:addcollection',
'collection', $hook_params,
true)) {
487 UPDATE {$this->table} 494 ':id' => (int) $collection_id,
498 $this->access_cache->clear();
499 return (
int) $collection_id;
519 public function update($collection_id, array $new_members = []) {
520 $acl = $this->
get($collection_id);
526 $to_guid =
function($elem) {
530 if (is_object($elem)) {
531 return (
int) $elem->guid;
536 $current_members = [];
537 $new_members = array_map($to_guid, $new_members);
539 $current_members_batch = $this->
getMembers($collection_id, [
545 foreach ($current_members_batch as $row) {
546 $current_members[] = $to_guid($row);
549 $remove_members = array_diff($current_members, $new_members);
550 $add_members = array_diff($new_members, $current_members);
554 foreach ($add_members as
$guid) {
558 foreach ($remove_members as $guid) {
562 $this->access_cache->clear();
573 public function delete($collection_id) {
574 $collection_id = (int) $collection_id;
577 'collection_id' => $collection_id,
580 if (!$this->hooks->trigger(
'access:collections:deletecollection',
'collection',
$params,
true)) {
586 DELETE FROM {$this->membership_table} 587 WHERE access_collection_id = :access_collection_id 589 $this->db->deleteData(
$query, [
590 ':access_collection_id' => $collection_id,
594 DELETE FROM {$this->table} 598 ':id' => $collection_id,
601 $this->access_cache->clear();
613 return new \ElggAccessCollection($row);
627 public function get($collection_id) {
629 $callback = [$this,
'rowToElggAccessCollection'];
632 SELECT * FROM {$this->table} 637 ':id' => (
int) $collection_id,
673 $collection = $this->
get($collection_id);
684 'collection_id' => $collection->id,
688 $result = $this->hooks->trigger(
'access:collections:add_user',
'collection', $hook_params,
true);
695 INSERT INTO {$this->membership_table} 696 SET access_collection_id = :access_collection_id, 697 user_guid = :user_guid 698 ON DUPLICATE KEY UPDATE user_guid = user_guid 702 ':access_collection_id' => (
int) $collection->id,
706 $this->access_cache->clear();
723 'collection_id' => (int) $collection_id,
727 if (!$this->hooks->trigger(
'access:collections:remove_user',
'collection',
$params,
true)) {
732 DELETE FROM {$this->membership_table} 733 WHERE access_collection_id = :access_collection_id 734 AND user_guid = :user_guid 737 $this->access_cache->clear();
739 return (
bool) $this->db->deleteData(
$query, [
740 ':access_collection_id' => (
int) $collection_id,
754 $callback = [$this,
'rowToElggAccessCollection'];
756 $supported_options = [
'owner_guid',
'subtype'];
760 foreach ($supported_options as $option) {
762 if (!isset($option_value)) {
765 $wheres[] =
"{$option} = :{$option}";
766 $params[
":{$option}"] = $option_value;
769 $query =
"SELECT * FROM {$this->table}";
770 if (!empty($wheres)) {
771 $query .=
' WHERE ' . implode(
' AND ', $wheres);
773 $query .=
' ORDER BY name ASC';
787 $qb->
join($table_alias,
'access_collection_membership',
'acm', $qb->
compare(
'acm.user_guid',
'=',
"$table_alias.guid"));
803 $callback = [$this,
'rowToElggAccessCollection'];
806 SELECT ac.* FROM {$this->table} ac 807 JOIN {$this->membership_table} acm 808 ON ac.id = acm.access_collection_id 809 WHERE acm.user_guid = :member_guid 813 return $this->db->getData(
$query, $callback, [
814 ':member_guid' => (
int) $member_guid,
836 $access = (int) $entity_access_id;
848 if (array_key_exists(
$access, $access_array)) {
855 $collection = $this->
get(
$access);
859 return $translator->translate(
'access:limited:label');
862 return $collection->getDisplayName();
if(!$user||!$user->canDelete()) $name
$params
Saves global plugin settings.
removeUser($user_guid, $collection_id)
Removes a user from an access collection.
static find(array $options=[])
Build and execute a new query from an array of legacy options.
canEdit($user_guid=null)
Check if user can this collection.
hasAccessToEntity($entity, $user=null)
Can a user access an entity.
markInitComplete()
Mark the access system as initialized.
const ELGG_VALUE_INTEGER
Value types.
rename($collection_id, $name)
Renames an access collection.
Database abstraction query builder.
$guid
Removes an admin notice.
getAccessArray($user_guid=0, $flush=false)
Returns an array of access IDs a user is permitted to see.
create($name, $owner_guid=0, $subtype=null)
Creates a new access collection.
$user_guid
Validate a user.
addUser($user_guid, $collection_id)
Adds a user to an access collection.
$id
River item delete action.
getMembers($collection_id, array $options=[])
Get members of an access collection.
getWriteAccessArray($user_guid=0, $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
getEntityCollections($options=[])
Returns access collections.
rowToElggAccessCollection(\stdClass $row)
Transforms a database row to an instance of ElggAccessCollection.
getCollectionsByMember($member_guid)
Return an array of collections that the entity is member of.
Exception indicating a user could not be looked up for a permissions check.
hasUser($user_guid, $collection_id)
Check if user is already in the collection.
join($fromAlias, $join, $alias, $condition=null)
{}
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getAccessList($user_guid=0, $flush=false)
Returns a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause...
__construct(Config $config, Database $db, EntityTable $entities, UserCapabilities $capabilities, ElggCache $cache, PluginHooksService $hooks, ElggSession $session, Translator $translator)
Constructor.
getReadableAccessLevel($entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user owns ...
_elgg_services()
Get the global service provider.
canEdit($collection_id, $user_guid=null)
Can the user change this access collection?
update($collection_id, array $new_members=[])
Updates the membership in an access collection.