public function testGetSqlWithSinglePairAndCaseInsensitiveStringValue() { $result = _elgg_get_entity_attribute_where_sql(array('types' => 'object', 'attribute_name_value_pairs' => array('name' => 'title', 'value' => 'foo', 'case_sensitive' => true), 'attribute_name_value_pairs_operator' => 'AND')); global $CONFIG; $expected = array('joins' => array("JOIN {$CONFIG->dbprefix}objects_entity type_table ON e.guid = type_table.guid"), 'wheres' => array("((BINARY type_table.title = 'foo'))")); $this->assertIdentical($expected, $result); }
/** * Gets entities based upon attributes in secondary tables. * Also accepts all options available to elgg_get_entities(), * elgg_get_entities_from_metadata(), and elgg_get_entities_from_relationship(). * * @warning requires that the entity type be specified and there can only be one * type. * * @see elgg_get_entities * @see elgg_get_entities_from_metadata * @see elgg_get_entities_from_relationship * * @param array $options 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 \ElggEntity[]|mixed If count, int. If not count, array. false on errors. * @throws InvalidArgumentException * @todo Does not support ordering by attributes or using an attribute pair shortcut like this ('title' => 'foo') */ 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); }