/**
* Can the user change this access collection?
*
* Use the plugin hook of 'access:collections:write', 'user' to change this.
* @see get_write_access_array() for details on the hook.
*
* Respects access control disabling for admin users and {@link elgg_set_ignore_access()}
*
* @see get_write_access_array()
*
* @param int $collection_id The collection id
* @param mixed $user_guid The user GUID to check for. Defaults to logged in user.
* @return bool
*/
function canEdit($collection_id, $user_guid = null)
{
try {
$user = $this->entities->getUserForPermissionsCheck($user_guid);
} catch (UserFetchFailureException $e) {
return false;
}
$collection = $this->get($collection_id);
if (!$user || !$collection) {
return false;
}
$write_access = $this->getWriteAccessArray($user->guid, true);
// don't ignore access when checking users.
if ($user_guid) {
return array_key_exists($collection_id, $write_access);
} else {
return elgg_get_ignore_access() || array_key_exists($collection_id, $write_access);
}
}