Elgg\Database\EntityTable::getUserForPermissionsCheck PHP Method

getUserForPermissionsCheck() public method

Get a user by GUID even if the entity is hidden or disabled
public getUserForPermissionsCheck ( integer $guid ) : ElggUse\ElggUser | false
$guid integer User GUID. Default is logged in user
return ElggUse\ElggUser | false
    public function getUserForPermissionsCheck($guid = 0)
    {
        if (!$guid) {
            return $this->session->getLoggedInUser();
        }
        // need to ignore access and show hidden entities for potential hidden/disabled users
        $ia = $this->session->setIgnoreAccess(true);
        $show_hidden = access_show_hidden_entities(true);
        $user = $this->get($guid, 'user');
        $this->session->setIgnoreAccess($ia);
        access_show_hidden_entities($show_hidden);
        if (!$user) {
            // requested to check access for a specific user_guid, but there is no user entity, so the caller
            // should cancel the check and return false
            $message = $this->translator->translate('UserFetchFailureException', array($guid));
            $this->logger->warn($message);
            throw new UserFetchFailureException();
        }
        return $user;
    }

Usage Example

コード例 #1
0
ファイル: AccessCollections.php プロジェクト: elgg/elgg
 /**
  * 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);
     }
 }
All Usage Examples Of Elgg\Database\EntityTable::getUserForPermissionsCheck