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
コード例 #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);
     }
 }
コード例 #2
0
ファイル: UserCapabilities.php プロジェクト: elgg/elgg
 /**
  * Can a user annotate an entity?
  *
  * @tip Can be overridden by registering for the plugin hook [permissions_check:annotate:<name>,
  * <entity type>] or [permissions_check:annotate, <entity type>]. The hooks are called in that order.
  *
  * @tip If you want logged out users to annotate an object, do not call
  * canAnnotate(). It's easier than using the plugin hook.
  *
  * @param ElggEntity $entity          Objet entity
  * @param int        $user_guid       User guid (default is logged in user)
  * @param string     $annotation_name The name of the annotation (default is unspecified)
  *
  * @return bool
  */
 public function canAnnotate(ElggEntity $entity, $user_guid = 0, $annotation_name = '')
 {
     if ($annotation_name === null || $annotation_name === false) {
         // accepting these for BC
         $annotation_name = '';
     } elseif (!is_string($annotation_name)) {
         throw new InvalidArgumentException(__METHOD__ . ' expects \\$annotation_name to be a string');
     }
     try {
         $user = $this->entities->getUserForPermissionsCheck($user_guid);
     } catch (UserFetchFailureException $e) {
         return false;
     }
     $return = (bool) $user;
     $params = ['entity' => $entity, 'user' => $user, 'annotation_name' => $annotation_name];
     if (!empty($annotation_name)) {
         $return = $this->hooks->trigger("permissions_check:annotate:{$annotation_name}", $entity->getType(), $params, $return);
     }
     return $this->hooks->trigger('permissions_check:annotate', $entity->getType(), $params, $return);
 }