/** * https://github.com/Elgg/Elgg/issues/4867 */ public function testElggGetEntityMetadataWhereSqlWithFalseValue() { $pair = array('name' => 'test', 'value' => false); $result = _elgg_get_entity_metadata_where_sql('e', 'metadata', null, null, $pair); $where = preg_replace('/\\s+/', ' ', $result['wheres'][0]); $this->assertTrue(strpos($where, "n_table1.name = 'test' AND BINARY n_table1.value = 0") > 0); $result = _elgg_get_entity_metadata_where_sql('e', 'metadata', array('test'), array(false)); $where = preg_replace('/\\s+/', ' ', $result['wheres'][0]); $this->assertTrue(strpos($where, "n_table.name IN ('test')) AND ( BINARY n_table.value IN ('0')")); }
/** * Returns options to pass to elgg_get_entities() for metastrings operations. * * @param string $type Metastring type: annotation or metadata * @param array $options Options * * @return array * @access private */ function _elgg_entities_get_metastrings_options($type, $options) { $valid_types = array('metadata', 'annotation'); if (!in_array($type, $valid_types)) { return false; } // the options for annotations are singular (annotation_name) but the table // is plural (elgg_annotations) so rewrite for the table name. $n_table = $type == 'annotation' ? 'annotations' : $type; $singulars = array("{$type}_name", "{$type}_value", "{$type}_name_value_pair", "{$type}_owner_guid"); $options = _elgg_normalize_plural_options_array($options, $singulars); $clauses = _elgg_get_entity_metadata_where_sql('e', $n_table, $options["{$type}_names"], $options["{$type}_values"], $options["{$type}_name_value_pairs"], $options["{$type}_name_value_pairs_operator"], $options["{$type}_case_sensitive"], $options["order_by_{$type}"], $options["{$type}_owner_guids"]); 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']); if ($clauses['orders']) { $order_by_metadata = implode(", ", $clauses['orders']); if (isset($options['order_by']) && $options['order_by']) { $options['order_by'] = "{$order_by_metadata}, {$options['order_by']}"; } else { $options['order_by'] = "{$order_by_metadata}, e.time_created DESC"; } } } return $options; }