80 $this->access_cache = $cache;
92 $this->init_complete =
true;
127 $user_guid = $this->session_manager->getLoggedInUserGuid();
133 $access_array = $cache[$hash];
145 $membership_query = $select->subquery(self::MEMBERSHIP_TABLE_NAME);
146 $membership_query->select(
'access_collection_id')
149 $select->select(
'id')
151 ->orWhere($select->compare(
'id',
'in', $membership_query->getSQL()));
153 $collections = $this->db->getData($select);
154 if (!empty($collections)) {
155 foreach ($collections as $collection) {
156 $access_array[] = (int) $collection->id;
160 $ignore_access = $this->capabilities->canBypassPermissionsCheck(
$user_guid);
162 if ($ignore_access ===
true) {
167 if ($this->init_complete) {
168 $cache[$hash] = $access_array;
177 return $this->events->triggerResults(
'access:collections:read',
'user',
$options, $access_array);
220 return $this->entities->getRow($entity->guid,
$user_guid);
257 $user_guid = $this->session_manager->getLoggedInUserGuid();
260 $hash =
$user_guid .
'get_write_access_array';
263 $access_array = $cache[$hash];
273 if ($this->init_complete) {
274 $cache[$hash] = $access_array;
283 $access_array = $this->events->triggerResults(
'access:collections:write',
'user',
$options, $access_array);
287 if (!isset($access_array[$access])) {
291 $temp = $access_array[
$access];
292 unset($access_array[$access]);
293 $access_array[
$access] = $temp;
297 return $access_array;
309 $subtypes = $this->events->triggerResults(
'access:collections:write:subtypes',
'user', [
'owner_guid' => $owner_guid], []);
314 $select->compare(
'subtype',
'is null'),
321 ->where($select->compare(
'owner_guid',
'=', $owner_guid,
ELGG_VALUE_GUID))
322 ->andWhere($select->merge($ors,
'OR'))
323 ->orderBy(
'name',
'ASC');
325 $collections = $this->db->getData($select, [$this,
'rowToElggAccessCollection']);
326 if (empty($collections)) {
331 foreach ($collections as $collection) {
332 $result[$collection->id] = $collection->getDisplayName();
362 $collection = $this->
get($collection_id);
367 if ($this->capabilities->canBypassPermissionsCheck(
$user->guid)) {
372 return array_key_exists($collection_id, $write_access);
391 if (!empty($acl->id)) {
392 return $this->
update($acl);
403 $id = $this->db->insertData($insert);
410 $this->access_cache->clear();
424 if (empty($acl->id)) {
425 return $this->
create($acl);
433 ->where($update->compare(
'id',
'=', $acl->id,
ELGG_VALUE_ID));
435 if (!$this->db->updateData($update)) {
439 $this->access_cache->clear();
453 if (empty($acl->id)) {
457 return $this->events->triggerSequence(
'delete', $acl->getType(), $acl,
function (
\ElggAccessCollection $acl) {
461 if (!$this->db->deleteData(
$delete)) {
467 $delete_membership->where($delete_membership->compare(
'access_collection_id',
'=', $acl->id,
ELGG_VALUE_ID));
469 $this->db->deleteData($delete_membership);
472 $this->access_cache->clear();
486 return new \ElggAccessCollection($row);
501 return $this->db->getDataRow(
$query, [$this,
'rowToElggAccessCollection']) ?: null;
531 $collection = $this->
get($collection_id);
536 $user = $this->entities->get($user_guid);
542 'collection_id' => $collection->id,
547 $result = $this->events->triggerResults(
'access:collections:add_user',
'collection',
$event_params,
true);
555 'access_collection_id' => $insert->param($collection_id,
ELGG_VALUE_ID),
560 $result = $this->db->insertData($insert);
562 $prev = $e->getPrevious();
563 if ($prev instanceof UniqueConstraintViolationException) {
571 $this->access_cache->clear();
589 'collection_id' => $collection_id,
594 if (!$this->events->triggerResults(
'access:collections:remove_user',
'collection',
$params,
true)) {
602 $this->access_cache->clear();
604 return (
bool) $this->db->deleteData(
$delete);
616 $supported_options = [
'owner_guid',
'subtype'];
620 ->orderBy(
'name',
'ASC');
622 foreach ($supported_options as $option) {
624 if (!isset($option_value)) {
630 $select->andWhere($select->compare($option,
'=', $option_value,
ELGG_VALUE_GUID));
633 $select->andWhere($select->compare($option,
'=', $option_value,
ELGG_VALUE_STRING));
638 return $this->db->getData($select, [$this,
'rowToElggAccessCollection']);
651 $qb->
join($table_alias, self::MEMBERSHIP_TABLE_NAME,
'acm', $qb->
compare(
'acm.user_guid',
'=',
"{$table_alias}.guid"));
668 $select->join($select->getTableAlias(), self::MEMBERSHIP_TABLE_NAME,
'acm', $select->compare(
"{$select->getTableAlias()}.id",
'=',
'acm.access_collection_id'));
670 $select->select(
"{$select->getTableAlias()}.*")
671 ->where($select->compare(
'acm.user_guid',
'=', $member_guid,
ELGG_VALUE_GUID))
672 ->orderBy(
'name',
'ASC');
674 return $this->db->getData($select, [$this,
'rowToElggAccessCollection']);
705 if (array_key_exists($entity_access_id, $access_array)) {
706 return $access_array[$entity_access_id];
712 $collection = $this->
get($entity_access_id);
716 return $translator->
translate(
'access:limited:label');
719 return $collection->getDisplayName();
getReadableAccessLevel(int $entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user owns ...
canEdit(int $user_guid=null)
Check if user can edit this collection.
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
static table(string $table)
Returns a QueryBuilder for updating data in a given table.
removeUser(int $user_guid, int $collection_id)
Removes a user from an access collection.
hasAccessToEntity(\ElggEntity $entity, int $user_guid=0)
Can a user access an entity.
$params
Saves global plugin settings.
const ELGG_ENFORCE_ACCESS
static find(array $options=[])
Build and execute a new query from an array of legacy options.
markInitComplete()
Mark the access system as initialized.
const ELGG_VALUE_INTEGER
Value types.
const MEMBERSHIP_TABLE_NAME
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
canEdit(int $collection_id, int $user_guid=null)
Can the user change this access collection?
Database abstraction query builder.
translate(string $message_key, array $args=[], string $language= '')
Given a message key, returns an appropriately translated full-text string.
clear()
Clear out all the contents of the cache.
static intoTable(string $table)
Returns a QueryBuilder for inserting data in a given table.
SessionManagerService $session_manager
getCollectionsForWriteAccess(int $owner_guid)
Returns an array of access collections to be used in the write access array.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
getWriteAccessArray(int $user_guid=0, bool $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
trait Loggable
Enables adding a logger.
getCollectionsByMember(int $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.
UserCapabilities $capabilities
rowToElggAccessCollection(\stdClass $row)
Transforms a database row to an instance of ElggAccessCollection.
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
A generic parent class for database exceptions.
static fromTable(string $table)
Returns a QueryBuilder for deleting data from a given table.
The Elgg cache base class.
getEntityCollections(array $options=[])
Returns access collections.
create(\ElggAccessCollection $acl)
Creates a new access collection.
__construct(Config $config, Database $db, EntityTable $entities, UserCapabilities $capabilities, BaseCache $cache, EventsService $events, SessionManagerService $session_manager, Translator $translator)
Constructor.
addUser(int $user_guid, int $collection_id)
Adds a user to an access collection.
getAccessArray(int $user_guid=0, bool $flush=false)
Returns an array of access IDs a user is permitted to see.
update(\ElggAccessCollection $acl)
Update an existing access collection.
static fromTable(string $table, string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
join(string $fromAlias, string $join, string $alias,?string $condition=null)
{}
User capabilities service.
Access collections database service.
$id
Generic annotation delete action.
Entity table database service.
hasUser(int $user_guid, int $collection_id)
Check if user is already in the collection.
getMembers(int $collection_id, array $options=[])
Get members of an access collection.