Elgg\Database\EntityTable::getEntitiesFromAttributes PHP Method

getEntitiesFromAttributes() public method

Also accepts all options available to elgg_get_entities(), elgg_get_entities_from_metadata(), and elgg_get_entities_from_relationship().
See also: elgg_get_entities
See also: elgg_get_entities_from_metadata
See also: elgg_get_entities_from_relationship
public getEntitiesFromAttributes ( array $options = [] ) : ElggEntit\ElggEntity[] | mixed
$options array Array in format: attribute_name_value_pairs => ARR ( 'name' => 'name', 'value' => 'value', 'operand' => '=', (optional) 'case_sensitive' => false (optional) ) If multiple values are sent via an array ('value' => array('value1', 'value2') the pair's operand will be forced to "IN". attribute_name_value_pairs_operator => null|STR The operator to use for combining (name = value) OPERATOR (name = value); default is AND
return ElggEntit\ElggEntity[] | mixed If count, int. If not count, array. false on errors.
    public function getEntitiesFromAttributes(array $options = array())
    {
        $defaults = array('attribute_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE, 'attribute_name_value_pairs_operator' => 'AND');
        $options = array_merge($defaults, $options);
        $singulars = array('type', 'attribute_name_value_pair');
        $options = _elgg_normalize_plural_options_array($options, $singulars);
        $clauses = _elgg_get_entity_attribute_where_sql($options);
        if ($clauses) {
            // merge wheres to pass to elgg_get_entities()
            if (isset($options['wheres']) && !is_array($options['wheres'])) {
                $options['wheres'] = array($options['wheres']);
            } elseif (!isset($options['wheres'])) {
                $options['wheres'] = array();
            }
            $options['wheres'] = array_merge($options['wheres'], $clauses['wheres']);
            // merge joins to pass to elgg_get_entities()
            if (isset($options['joins']) && !is_array($options['joins'])) {
                $options['joins'] = array($options['joins']);
            } elseif (!isset($options['joins'])) {
                $options['joins'] = array();
            }
            $options['joins'] = array_merge($options['joins'], $clauses['joins']);
        }
        return elgg_get_entities_from_relationship($options);
    }

Usage Example

コード例 #1
0
ファイル: UsersTable.php プロジェクト: elgg/elgg
 /**
  * Get an array of users from an email address
  *
  * @param string $email Email address
  * @return array
  */
 public function getByEmail($email)
 {
     if (!$email) {
         return [];
     }
     $users = $this->entities->getEntitiesFromAttributes(['types' => 'user', 'attribute_name_value_pairs' => ['name' => 'email', 'value' => $email], 'limit' => 1]);
     return $users ?: [];
 }