本文整理汇总了PHP中_elgg_get_entity_time_where_sql函数的典型用法代码示例。如果您正苦于以下问题:PHP _elgg_get_entity_time_where_sql函数的具体用法?PHP _elgg_get_entity_time_where_sql怎么用?PHP _elgg_get_entity_time_where_sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_elgg_get_entity_time_where_sql函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: elgg_solr_get_entity_guids
function elgg_solr_get_entity_guids(array $options = array())
{
global $CONFIG;
$defaults = array('types' => ELGG_ENTITIES_ANY_VALUE, 'subtypes' => ELGG_ENTITIES_ANY_VALUE, 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, 'guids' => ELGG_ENTITIES_ANY_VALUE, 'owner_guids' => ELGG_ENTITIES_ANY_VALUE, 'container_guids' => ELGG_ENTITIES_ANY_VALUE, 'site_guids' => $CONFIG->site_guid, 'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'reverse_order_by' => false, 'order_by' => 'e.time_created desc', 'group_by' => ELGG_ENTITIES_ANY_VALUE, 'limit' => 10, 'offset' => 0, 'count' => false, 'selects' => array(), 'wheres' => array(), 'joins' => array(), 'callback' => false, '__ElggBatch' => null);
$options = array_merge($defaults, $options);
// can't use helper function with type_subtype_pair because
// it's already an array...just need to merge it
if (isset($options['type_subtype_pair'])) {
if (isset($options['type_subtype_pairs'])) {
$options['type_subtype_pairs'] = array_merge($options['type_subtype_pairs'], $options['type_subtype_pair']);
} else {
$options['type_subtype_pairs'] = $options['type_subtype_pair'];
}
}
$singulars = array('type', 'subtype', 'guid', 'owner_guid', 'container_guid', 'site_guid');
$options = _elgg_normalize_plural_options_array($options, $singulars);
// evaluate where clauses
if (!is_array($options['wheres'])) {
$options['wheres'] = array($options['wheres']);
}
$wheres = $options['wheres'];
$wheres[] = _elgg_get_entity_type_subtype_where_sql('e', $options['types'], $options['subtypes'], $options['type_subtype_pairs']);
$wheres[] = _elgg_get_guid_based_where_sql('e.guid', $options['guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.site_guid', $options['site_guids']);
$wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'], $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']);
// see if any functions failed
// remove empty strings on successful functions
foreach ($wheres as $i => $where) {
if ($where === false) {
return false;
} elseif (empty($where)) {
unset($wheres[$i]);
}
}
// remove identical where clauses
$wheres = array_unique($wheres);
// evaluate join clauses
if (!is_array($options['joins'])) {
$options['joins'] = array($options['joins']);
}
// remove identical join clauses
$joins = array_unique($options['joins']);
foreach ($joins as $i => $join) {
if ($join === false) {
return false;
} elseif (empty($join)) {
unset($joins[$i]);
}
}
// evalutate selects
if ($options['selects']) {
$selects = '';
foreach ($options['selects'] as $select) {
$selects .= ", {$select}";
}
} else {
$selects = '';
}
if (!$options['count']) {
$distinct = '';
if ($options['require_distinct']) {
$distinct = ' DISTINCT';
}
$query = "SELECT{$distinct} e.guid{$selects} FROM {$CONFIG->dbprefix}entities e ";
} else {
$query = "SELECT count(DISTINCT e.guid) as total FROM {$CONFIG->dbprefix}entities e ";
}
// add joins
foreach ($joins as $j) {
$query .= " {$j} ";
}
// add wheres
$query .= ' WHERE ';
foreach ($wheres as $w) {
$query .= " {$w} AND ";
}
// Add access controls
$query .= _elgg_get_access_where_sql();
// reverse order by
if ($options['reverse_order_by']) {
$options['order_by'] = _elgg_sql_reverse_order_by_clause($options['order_by']);
}
if (!$options['count']) {
if ($options['group_by']) {
$query .= " GROUP BY {$options['group_by']}";
}
if ($options['order_by']) {
$query .= " ORDER BY {$options['order_by']}";
}
if ($options['limit']) {
$limit = sanitise_int($options['limit'], false);
$offset = sanitise_int($options['offset'], false);
$query .= " LIMIT {$offset}, {$limit}";
}
if ($options['callback'] === 'entity_row_to_elggstar') {
$dt = _elgg_fetch_entities_from_sql($query, $options['__ElggBatch']);
} else {
$dt = get_data($query, $options['callback']);
//.........这里部分代码省略.........
示例2: elgg_get_entities_from_annotations
/**
* Returns entities based upon annotations. Also accepts all options available
* to elgg_get_entities() and elgg_get_entities_from_metadata().
*
* Entity creation time is selected as maxtime. To sort based upon
* this, pass 'order_by' => 'maxtime asc' || 'maxtime desc'
*
* @see elgg_get_entities
* @see elgg_get_entities_from_metadata
*
* @param array $options Array in format:
*
* annotation_names => null|ARR annotations names
*
* annotation_values => null|ARR annotations values
*
* annotation_name_value_pairs => null|ARR (name = 'name', value => 'value',
* 'operator' => '=', 'case_sensitive' => true) entries.
* Currently if multiple values are sent via an array (value => array('value1', 'value2')
* the pair's operator will be forced to "IN".
*
* annotation_name_value_pairs_operator => null|STR The operator to use for combining
* (name = value) OPERATOR (name = value); default AND
*
* annotation_case_sensitive => BOOL Overall Case sensitive
*
* order_by_annotation => null|ARR (array('name' => 'annotation_text1', 'direction' => ASC|DESC,
* 'as' => text|integer),
*
* Also supports array('name' => 'annotation_text1')
*
* annotation_owner_guids => null|ARR guids for annotaiton owners
*
* @return mixed If count, int. If not count, array. false on errors.
* @since 1.7.0
*/
function elgg_get_entities_from_annotations(array $options = array())
{
$defaults = array('annotation_names' => ELGG_ENTITIES_ANY_VALUE, 'annotation_values' => ELGG_ENTITIES_ANY_VALUE, 'annotation_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE, 'annotation_name_value_pairs_operator' => 'AND', 'annotation_case_sensitive' => true, 'order_by_annotation' => array(), 'annotation_created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'annotation_created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'annotation_owner_guids' => ELGG_ENTITIES_ANY_VALUE, 'order_by' => 'maxtime DESC', 'group_by' => 'a.entity_guid');
$options = array_merge($defaults, $options);
$singulars = array('annotation_name', 'annotation_value', 'annotation_name_value_pair', 'annotation_owner_guid');
$options = _elgg_normalize_plural_options_array($options, $singulars);
$options = _elgg_entities_get_metastrings_options('annotation', $options);
if (!$options) {
return false;
}
// special sorting for annotations
//@todo overrides other sorting
$options['selects'][] = "MAX(n_table.time_created) AS maxtime";
$options['group_by'] = 'n_table.entity_guid';
$time_wheres = _elgg_get_entity_time_where_sql('a', $options['annotation_created_time_upper'], $options['annotation_created_time_lower']);
if ($time_wheres) {
$options['wheres'] = array_merge($options['wheres'], $time_wheres);
}
return elgg_get_entities_from_metadata($options);
}
示例3: elgg_get_tags
/**
* Get popular tags and their frequencies
*
* Supports similar arguments as elgg_get_entities()
*
* @param array $options Array in format:
*
* threshold => INT minimum tag count
*
* tag_names => array() metadata tag names - must be registered tags
*
* limit => INT number of tags to return
*
* types => null|STR entity type (SQL: type = '$type')
*
* subtypes => null|STR entity subtype (SQL: subtype = '$subtype')
*
* type_subtype_pairs => null|ARR (array('type' => 'subtype'))
* (SQL: type = '$type' AND subtype = '$subtype') pairs
*
* owner_guids => null|INT entity guid
*
* container_guids => null|INT container_guid
*
* site_guids => null (current_site)|INT site_guid
*
* created_time_lower => null|INT Created time lower boundary in epoch time
*
* created_time_upper => null|INT Created time upper boundary in epoch time
*
* modified_time_lower => null|INT Modified time lower boundary in epoch time
*
* modified_time_upper => null|INT Modified time upper boundary in epoch time
*
* wheres => array() Additional where clauses to AND together
*
* joins => array() Additional joins
*
* @return object[]|false If no tags or error, false
* otherwise, array of objects with ->tag and ->total values
* @since 1.7.1
*/
function elgg_get_tags(array $options = array())
{
global $CONFIG;
$defaults = array('threshold' => 1, 'tag_names' => array(), 'limit' => 10, 'types' => ELGG_ENTITIES_ANY_VALUE, 'subtypes' => ELGG_ENTITIES_ANY_VALUE, 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, 'owner_guids' => ELGG_ENTITIES_ANY_VALUE, 'container_guids' => ELGG_ENTITIES_ANY_VALUE, 'site_guids' => $CONFIG->site_guid, 'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'joins' => array(), 'wheres' => array());
$options = array_merge($defaults, $options);
$singulars = array('type', 'subtype', 'owner_guid', 'container_guid', 'site_guid', 'tag_name');
$options = _elgg_normalize_plural_options_array($options, $singulars);
$registered_tags = elgg_get_registered_tag_metadata_names();
if (!is_array($options['tag_names'])) {
return false;
}
// empty array so use all registered tag names
if (count($options['tag_names']) == 0) {
$options['tag_names'] = $registered_tags;
}
$diff = array_diff($options['tag_names'], $registered_tags);
if (count($diff) > 0) {
elgg_deprecated_notice('Tag metadata names must be registered by elgg_register_tag_metadata_name()', 1.7);
// return false;
}
$wheres = $options['wheres'];
// catch for tags that were spaces
$wheres[] = "msv.string != ''";
$sanitised_tags = array();
foreach ($options['tag_names'] as $tag) {
$sanitised_tags[] = '"' . sanitise_string($tag) . '"';
}
$tags_in = implode(',', $sanitised_tags);
$wheres[] = "(msn.string IN ({$tags_in}))";
$wheres[] = _elgg_get_entity_type_subtype_where_sql('e', $options['types'], $options['subtypes'], $options['type_subtype_pairs']);
$wheres[] = _elgg_get_guid_based_where_sql('e.site_guid', $options['site_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']);
$wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'], $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']);
// see if any functions failed
// remove empty strings on successful functions
foreach ($wheres as $i => $where) {
if ($where === false) {
return false;
} elseif (empty($where)) {
unset($wheres[$i]);
}
}
// remove identical where clauses
$wheres = array_unique($wheres);
$joins = $options['joins'];
$joins[] = "JOIN {$CONFIG->dbprefix}metadata md on md.entity_guid = e.guid";
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings msv on msv.id = md.value_id";
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings msn on md.name_id = msn.id";
// remove identical join clauses
$joins = array_unique($joins);
foreach ($joins as $i => $join) {
if ($join === false) {
return false;
} elseif (empty($join)) {
unset($joins[$i]);
}
}
//.........这里部分代码省略.........
示例4: getEntities
/**
* Returns entities based upon annotations. Also accepts all options available
* to elgg_get_entities() and elgg_get_entities_from_metadata().
*
* @see elgg_get_entities
* @see elgg_get_entities_from_metadata
*
* @param array $options Array in format:
*
* annotation_names => null|ARR annotations names
*
* annotation_values => null|ARR annotations values
*
* annotation_name_value_pairs => null|ARR (name = 'name', value => 'value',
* 'operator' => '=', 'case_sensitive' => true) entries.
* Currently if multiple values are sent via an array (value => array('value1', 'value2')
* the pair's operator will be forced to "IN".
*
* annotation_name_value_pairs_operator => null|STR The operator to use for combining
* (name = value) OPERATOR (name = value); default AND
*
* annotation_case_sensitive => BOOL Overall Case sensitive
*
* order_by_annotation => null|ARR (array('name' => 'annotation_text1', 'direction' => ASC|DESC,
* 'as' => text|integer),
*
* Also supports array('name' => 'annotation_text1')
*
* annotation_owner_guids => null|ARR guids for annotaiton owners
*
* @return mixed If count, int. If not count, array. false on errors.
*/
function getEntities(array $options = array())
{
$defaults = array('annotation_names' => ELGG_ENTITIES_ANY_VALUE, 'annotation_values' => ELGG_ENTITIES_ANY_VALUE, 'annotation_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE, 'annotation_name_value_pairs_operator' => 'AND', 'annotation_case_sensitive' => true, 'order_by_annotation' => array(), 'annotation_created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'annotation_created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'annotation_owner_guids' => ELGG_ENTITIES_ANY_VALUE);
$options = array_merge($defaults, $options);
$singulars = array('annotation_name', 'annotation_value', 'annotation_name_value_pair', 'annotation_owner_guid');
$options = _elgg_normalize_plural_options_array($options, $singulars);
$options = _elgg_entities_get_metastrings_options('annotation', $options);
if (!$options) {
return false;
}
// because of performance issues support for ordering by maxtime has been dropped
// @see https://github.com/Elgg/Elgg/issues/6638
if (isset($options['order_by']) && preg_match('~\\bmaxtime\\b~i', $options['order_by'])) {
// check if the user provided maxtime
$deprecated = true;
if (isset($options['selects'])) {
$selects = $options['selects'];
if (!is_array($selects)) {
$selects = array($selects);
}
foreach ($selects as $select) {
if (preg_match('~\\bmaxtime\\b~i', $options['order_by'])) {
$deprecated = false;
break;
}
}
}
// the user didn't provide maxtime
if ($deprecated) {
// special sorting for annotations
elgg_deprecated_notice(__FUNCTION__ . ": no longer orders by annotations by default. If you order" . " by maxtime, you must provide that column via \$options['selects']. See" . " https://github.com/Elgg/Elgg/issues/6638#issuecomment-41562034", "1.10");
$options['selects'][] = "MAX(n_table.time_created) AS maxtime";
$options['group_by'] = 'n_table.entity_guid';
}
}
$time_wheres = _elgg_get_entity_time_where_sql('a', $options['annotation_created_time_upper'], $options['annotation_created_time_lower']);
if ($time_wheres) {
$options['wheres'] = array_merge($options['wheres'], $time_wheres);
}
return elgg_get_entities_from_metadata($options);
}
示例5: getEntities
//.........这里部分代码省略.........
* @return mixed If count, int. If not count, array. false on errors.
* @see elgg_get_entities_from_metadata()
* @see elgg_get_entities_from_relationship()
* @see elgg_get_entities_from_access_id()
* @see elgg_get_entities_from_annotations()
* @see elgg_list_entities()
*/
function getEntities(array $options = array())
{
$defaults = array('types' => ELGG_ENTITIES_ANY_VALUE, 'subtypes' => ELGG_ENTITIES_ANY_VALUE, 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, 'guids' => ELGG_ENTITIES_ANY_VALUE, 'owner_guids' => ELGG_ENTITIES_ANY_VALUE, 'container_guids' => ELGG_ENTITIES_ANY_VALUE, 'site_guids' => $this->CONFIG->site_guid, 'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'reverse_order_by' => false, 'order_by' => 'e.time_created desc', 'group_by' => ELGG_ENTITIES_ANY_VALUE, 'limit' => _elgg_services()->config->get('default_limit'), 'offset' => 0, 'count' => false, 'selects' => array(), 'wheres' => array(), 'joins' => array(), 'preload_owners' => false, 'preload_containers' => false, 'callback' => 'entity_row_to_elggstar', 'distinct' => true, '__ElggBatch' => null);
$options = array_merge($defaults, $options);
// can't use helper function with type_subtype_pair because
// it's already an array...just need to merge it
if (isset($options['type_subtype_pair'])) {
if (isset($options['type_subtype_pairs'])) {
$options['type_subtype_pairs'] = array_merge($options['type_subtype_pairs'], $options['type_subtype_pair']);
} else {
$options['type_subtype_pairs'] = $options['type_subtype_pair'];
}
}
$singulars = array('type', 'subtype', 'guid', 'owner_guid', 'container_guid', 'site_guid');
$options = _elgg_normalize_plural_options_array($options, $singulars);
$options = $this->autoJoinTables($options);
// evaluate where clauses
if (!is_array($options['wheres'])) {
$options['wheres'] = array($options['wheres']);
}
$wheres = $options['wheres'];
$wheres[] = _elgg_get_entity_type_subtype_where_sql('e', $options['types'], $options['subtypes'], $options['type_subtype_pairs']);
$wheres[] = _elgg_get_guid_based_where_sql('e.guid', $options['guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.site_guid', $options['site_guids']);
$wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'], $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']);
// see if any functions failed
// remove empty strings on successful functions
foreach ($wheres as $i => $where) {
if ($where === false) {
return false;
} elseif (empty($where)) {
unset($wheres[$i]);
}
}
// remove identical where clauses
$wheres = array_unique($wheres);
// evaluate join clauses
if (!is_array($options['joins'])) {
$options['joins'] = array($options['joins']);
}
// remove identical join clauses
$joins = array_unique($options['joins']);
foreach ($joins as $i => $join) {
if ($join === false) {
return false;
} elseif (empty($join)) {
unset($joins[$i]);
}
}
// evalutate selects
if ($options['selects']) {
$selects = '';
foreach ($options['selects'] as $select) {
$selects .= ", {$select}";
}
} else {
$selects = '';
示例6: getEntities
/**
* Returns entities based upon annotations. Also accepts all options available
* to elgg_get_entities() and elgg_get_entities_from_metadata().
*
* @see elgg_get_entities
* @see elgg_get_entities_from_metadata
*
* @param array $options Array in format:
*
* annotation_names => null|ARR annotations names
*
* annotation_values => null|ARR annotations values
*
* annotation_name_value_pairs => null|ARR (name = 'name', value => 'value',
* 'operator' => '=', 'case_sensitive' => true) entries.
* Currently if multiple values are sent via an array (value => array('value1', 'value2')
* the pair's operator will be forced to "IN".
*
* annotation_name_value_pairs_operator => null|STR The operator to use for combining
* (name = value) OPERATOR (name = value); default AND
*
* annotation_case_sensitive => BOOL Overall Case sensitive
*
* order_by_annotation => null|ARR (array('name' => 'annotation_text1', 'direction' => ASC|DESC,
* 'as' => text|integer),
*
* Also supports array('name' => 'annotation_text1')
*
* annotation_owner_guids => null|ARR guids for annotaiton owners
*
* @return mixed If count, int. If not count, array. false on errors.
*/
function getEntities(array $options = array())
{
$defaults = array('annotation_names' => ELGG_ENTITIES_ANY_VALUE, 'annotation_values' => ELGG_ENTITIES_ANY_VALUE, 'annotation_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE, 'annotation_name_value_pairs_operator' => 'AND', 'annotation_case_sensitive' => true, 'order_by_annotation' => array(), 'annotation_created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'annotation_created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'annotation_owner_guids' => ELGG_ENTITIES_ANY_VALUE);
$options = array_merge($defaults, $options);
$singulars = array('annotation_name', 'annotation_value', 'annotation_name_value_pair', 'annotation_owner_guid');
$options = _elgg_normalize_plural_options_array($options, $singulars);
$options = _elgg_entities_get_metastrings_options('annotation', $options);
if (!$options) {
return false;
}
$time_wheres = _elgg_get_entity_time_where_sql('n_table', $options['annotation_created_time_upper'], $options['annotation_created_time_lower']);
if ($time_wheres) {
$options['wheres'][] = $time_wheres;
}
return elgg_get_entities_from_metadata($options);
}
示例7: getEntities
/**
* Return entities matching a given query joining against a relationship.
* Also accepts all options available to elgg_get_entities() and
* elgg_get_entities_from_metadata().
*
* To ask for entities that do not have a particular relationship to an entity,
* use a custom where clause like the following:
*
* $options['wheres'][] = "NOT EXISTS (
* SELECT 1 FROM {$db_prefix}entity_relationships
* WHERE guid_one = e.guid
* AND relationship = '$relationship'
* )";
*
* @see elgg_get_entities
* @see elgg_get_entities_from_metadata
*
* @param array $options Array in format:
*
* relationship => null|STR Type of the relationship. E.g. "member"
*
* relationship_guid => null|INT GUID of the subject of the relationship, unless "inverse_relationship" is set
* to true, in which case this will specify the target.
*
* inverse_relationship => false|BOOL Are we searching for relationship subjects? By default, the query finds
* targets of relationships.
*
* relationship_join_on => null|STR How the entities relate: guid (default), container_guid, or owner_guid
* Examples using the relationship 'friend':
* 1. use 'guid' if you want the user's friends
* 2. use 'owner_guid' if you want the entities the user's friends own
* (including in groups)
* 3. use 'container_guid' if you want the entities in the user's personal
* space (non-group)
*
* relationship_created_time_lower => null|INT Relationship created time lower boundary in epoch time
*
* relationship_created_time_upper => null|INT Relationship created time upper boundary in epoch time
*
* @return \ElggEntity[]|mixed If count, int. If not count, array. false on errors.
*/
function getEntities($options)
{
$defaults = array('relationship' => null, 'relationship_guid' => null, 'inverse_relationship' => false, 'relationship_join_on' => 'guid', 'relationship_created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'relationship_created_time_upper' => ELGG_ENTITIES_ANY_VALUE);
$options = array_merge($defaults, $options);
$join_column = "e.{$options['relationship_join_on']}";
$clauses = elgg_get_entity_relationship_where_sql($join_column, $options['relationship'], $options['relationship_guid'], $options['inverse_relationship']);
if ($clauses) {
// merge wheres to pass to 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']);
// limit based on time created
$time_wheres = _elgg_get_entity_time_where_sql('r', $options['relationship_created_time_upper'], $options['relationship_created_time_lower']);
if ($time_wheres) {
$options['wheres'] = array_merge($options['wheres'], array($time_wheres));
}
// merge joins to pass to 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 (isset($options['selects']) && !is_array($options['selects'])) {
$options['selects'] = array($options['selects']);
} elseif (!isset($options['selects'])) {
$options['selects'] = array();
}
$select = array('r.id');
$options['selects'] = array_merge($options['selects'], $select);
if (!isset($options['group_by'])) {
$options['group_by'] = $clauses['group_by'];
}
}
return elgg_get_entities_from_metadata($options);
}
示例8: _elgg_get_metastring_based_objects
/**
* Returns an array of either \ElggAnnotation or \ElggMetadata objects.
* Accepts all elgg_get_entities() options for entity restraints.
*
* @see elgg_get_entities
*
* @param array $options Array in format:
*
* metastring_names => null|ARR metastring names
*
* metastring_values => null|ARR metastring values
*
* metastring_ids => null|ARR metastring ids
*
* metastring_case_sensitive => BOOL Overall Case sensitive
*
* metastring_owner_guids => null|ARR Guids for metadata owners
*
* metastring_created_time_lower => INT Lower limit for created time.
*
* metastring_created_time_upper => INT Upper limit for created time.
*
* metastring_calculation => STR Perform the MySQL function on the metastring values
* returned.
* This differs from egef_annotation_calculation in that
* it returns only the calculation of all annotation values.
* You can sum, avg, count, etc. egef_annotation_calculation()
* returns \ElggEntities ordered by a calculation on their
* annotation values.
*
* metastring_type => STR metadata or annotation(s)
*
* @return \ElggExtender[]|int An array or count of metastring based objects
* @access private
*/
function _elgg_get_metastring_based_objects($options)
{
$options = _elgg_normalize_metastrings_options($options);
switch ($options['metastring_type']) {
case 'metadata':
$type = 'metadata';
$callback = 'row_to_elggmetadata';
break;
case 'annotations':
case 'annotation':
$type = 'annotations';
$callback = 'row_to_elggannotation';
break;
default:
return false;
}
$defaults = array('types' => ELGG_ENTITIES_ANY_VALUE, 'subtypes' => ELGG_ENTITIES_ANY_VALUE, 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, 'guids' => ELGG_ENTITIES_ANY_VALUE, 'owner_guids' => ELGG_ENTITIES_ANY_VALUE, 'container_guids' => ELGG_ENTITIES_ANY_VALUE, 'site_guids' => get_config('site_guid'), 'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'metastring_names' => ELGG_ENTITIES_ANY_VALUE, 'metastring_values' => ELGG_ENTITIES_ANY_VALUE, 'metastring_case_sensitive' => true, 'metastring_calculation' => ELGG_ENTITIES_NO_VALUE, 'metastring_created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'metastring_created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'metastring_owner_guids' => ELGG_ENTITIES_ANY_VALUE, 'metastring_ids' => ELGG_ENTITIES_ANY_VALUE, 'order_by' => 'n_table.time_created ASC, n_table.id ASC', 'limit' => elgg_get_config('default_limit'), 'offset' => 0, 'count' => false, 'selects' => array(), 'wheres' => array(), 'joins' => array(), 'distinct' => true, 'preload_owners' => false, 'callback' => $callback);
// @todo Ignore site_guid right now because of #2910
$options['site_guid'] = ELGG_ENTITIES_ANY_VALUE;
$options = array_merge($defaults, $options);
// can't use helper function with type_subtype_pair because
// it's already an array...just need to merge it
if (isset($options['type_subtype_pair'])) {
if (isset($options['type_subtype_pairs'])) {
$options['type_subtype_pairs'] = array_merge($options['type_subtype_pairs'], $options['type_subtype_pair']);
} else {
$options['type_subtype_pairs'] = $options['type_subtype_pair'];
}
}
$singulars = array('type', 'subtype', 'type_subtype_pair', 'guid', 'owner_guid', 'container_guid', 'site_guid', 'metastring_name', 'metastring_value', 'metastring_owner_guid', 'metastring_id', 'select', 'where', 'join');
$options = _elgg_normalize_plural_options_array($options, $singulars);
if (!$options) {
return false;
}
$db_prefix = elgg_get_config('dbprefix');
// evaluate where clauses
if (!is_array($options['wheres'])) {
$options['wheres'] = array($options['wheres']);
}
$wheres = $options['wheres'];
// entities
$wheres[] = _elgg_services()->entityTable->getEntityTypeSubtypeWhereSql('e', $options['types'], $options['subtypes'], $options['type_subtype_pairs']);
$wheres[] = _elgg_get_guid_based_where_sql('e.guid', $options['guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']);
$wheres[] = _elgg_get_guid_based_where_sql('e.site_guid', $options['site_guids']);
$wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'], $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']);
$wheres[] = _elgg_get_entity_time_where_sql('n_table', $options['metastring_created_time_upper'], $options['metastring_created_time_lower'], null, null);
$wheres[] = _elgg_get_guid_based_where_sql('n_table.owner_guid', $options['metastring_owner_guids']);
// see if any functions failed
// remove empty strings on successful functions
foreach ($wheres as $i => $where) {
if ($where === false) {
return false;
} elseif (empty($where)) {
unset($wheres[$i]);
}
}
// remove identical where clauses
$wheres = array_unique($wheres);
// evaluate join clauses
if (!is_array($options['joins'])) {
$options['joins'] = array($options['joins']);
}
$joins = $options['joins'];
//.........这里部分代码省略.........