当前位置: 首页>>代码示例>>PHP>>正文


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怎么用?PHP elgg_get_entity_time_where_sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了elgg_get_entity_time_where_sql函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: elgg_get_entities

/**
 * Returns an array of entities with optional filtering.
 *
 * Entities are the basic unit of storage in Elgg.  This function
 * provides the simplest way to get an array of entities.  There
 * are many options available that can be passed to filter
 * what sorts of entities are returned.
 *
 * @tip To output formatted strings of entities, use {@link elgg_list_entities()} and
 * its cousins.
 *
 * @tip Plural arguments can be written as singular if only specifying a
 * single element.  ('type' => 'object' vs 'types' => array('object')).
 *
 * @param array $options Array in format:
 *
 * 	types => NULL|STR entity type (type IN ('type1', 'type2')
 *           Joined with subtypes by AND. See below)
 *
 * 	subtypes => NULL|STR entity subtype (SQL: subtype IN ('subtype1', 'subtype2))
 *              Use ELGG_ENTITIES_NO_VALUE for no subtype.
 *
 * 	type_subtype_pairs => NULL|ARR (array('type' => 'subtype'))
 *                        (type = '$type' AND subtype = '$subtype') pairs
 *
 *	guids => NULL|ARR Array of entity guids
 *
 * 	owner_guids => NULL|ARR Array of owner guids
 *
 * 	container_guids => NULL|ARR Array of container_guids
 *
 * 	site_guids => NULL (current_site)|ARR Array of site_guid
 *
 * 	order_by => NULL (time_created desc)|STR SQL order by clause
 *
 *  reverse_order_by => BOOL Reverse the default order by clause
 *
 * 	limit => NULL (10)|INT SQL limit clause (0 means no limit)
 *
 * 	offset => NULL (0)|INT SQL offset clause
 *
 * 	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
 *
 * 	count => TRUE|FALSE return a count instead of entities
 *
 * 	wheres => array() Additional where clauses to AND together
 *
 * 	joins => array() Additional joins
 *
 * 	callback => string A callback function to pass each row through
 *
 * @return mixed If count, int. If not count, array. false on errors.
 * @since 1.7.0
 * @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()
 * @link http://docs.elgg.org/DataModel/Entities/Getters
 */
function elgg_get_entities(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' => 'entity_row_to_elggstar');
    $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_normalise_plural_options_array($options, $singulars);
    // evaluate where clauses
    if (!is_array($options['wheres'])) {
        $options['wheres'] = array($options['wheres']);
    }
    // subsite manager: modify options
    $options = elgg_trigger_plugin_hook("entities:get", "system", $options, $options);
    $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;
//.........这里部分代码省略.........
开发者ID:pleio,项目名称:subsite_manager,代码行数:101,代码来源:entities.php

示例2: elgg_solr_get_entity_guids_18

function elgg_solr_get_entity_guids_18($options)
{
    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.guid 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_normalise_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 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 .= get_access_sql_suffix('e');
    // 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}";
        }
        $dt = get_data($query);
        return $dt;
    } else {
        $total = get_data_row($query);
//.........这里部分代码省略.........
开发者ID:ewinslow,项目名称:elgg_solr,代码行数:101,代码来源:functions.php

示例3: 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
 *
 *  annotation_ids => NULL|ARR Annotation IDs
 *
 * @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, 'annotation_ids' => 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', 'annotation_id');
    $options = elgg_normalise_plural_options_array($options, $singulars);
    if (!($options = elgg_entities_get_metastrings_options('annotation', $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);
}
开发者ID:nachopavon,项目名称:Elgg,代码行数:57,代码来源:annotations.php

示例4: 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 mixed
 * @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', 'limit' => 10, 'offset' => 0, 'count' => FALSE, 'selects' => array(), 'wheres' => array(), 'joins' => array(), '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_normalise_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_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']);
    $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'];
//.........这里部分代码省略.........
开发者ID:nachopavon,项目名称:Elgg,代码行数:101,代码来源:metastrings.php

示例5: 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 	false/array - 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_normalise_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 != ''";
    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']);
    // remove identical where clauses
    $wheres = array_unique($wheres);
    // 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]);
        }
    }
    $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]);
        }
    }
    $query = "SELECT msv.string as tag, count(msv.id) as total ";
//.........这里部分代码省略.........
开发者ID:redvabel,项目名称:Vabelgg,代码行数:101,代码来源:tags.php

示例6: elgg_get_entities

/**
 * Get all entities.  NB: Plural arguments can be written as
 * singular if only specifying a single element.  (e.g., 'type' => 'object'
 * vs 'types' => array('object')).
 *
 * @param array $options Array in format:
 *
 * 	types => NULL|STR entity type (SQL: type = '$type' OR...see below...)
 *
 * 	subtypes => NULL|STR entity subtype (SQL: subtype = '$subtype'...see above)
 *
 * 	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
 *
 * 	order_by => NULL (time_created desc)|STR SQL order by clause
 *
 * 	limit => NULL (10)|INT SQL limit clause
 *
 * 	offset => NULL (0)|INT SQL offset clause
 *
 * 	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
 *
 * 	count => TRUE|FALSE return a count instead of entities
 *
 * 	wheres => array() Additional where clauses to AND together
 *
 * 	joins => array() Additional joins
 *
 * @return 	if count, int
 * 			if not count, array or false if no entities
 */
function elgg_get_entities(array $options = array())
{
    global $CONFIG;
    $defaults = array('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, 'order_by' => 'e.time_created desc', 'group_by' => ELGG_ENTITIES_ANY_VALUE, 'limit' => 10, 'offset' => 0, 'count' => FALSE, 'selects' => array(), 'wheres' => array(), 'joins' => array());
    $options = array_merge($defaults, $options);
    $singulars = array('type', 'subtype', 'owner_guid', 'container_guid', 'site_guid');
    $options = elgg_normalise_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_entity_site_where_sql('e', $options['site_guids']);
    $wheres[] = elgg_get_entity_owner_where_sql('e', $options['owner_guids']);
    $wheres[] = elgg_get_entity_container_where_sql('e', $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']);
    // remove identical where clauses
    $wheres = array_unique($wheres);
    // 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]);
        }
    }
    // 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']) {
        $query = "SELECT DISTINCT e.*{$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} ";
//.........这里部分代码省略.........
开发者ID:adamboardman,项目名称:Elgg,代码行数:101,代码来源:entities.php

示例7: am_get_entities_from_tag_and_container_tag

/**
 * Screwy function name I know.. this is a hacked up entity getter
 * function that gets entities with given tag ($params['tag']) and
 * entities with a container guid with given tag. This is mostly for images, but 
 * could work on just about anything. I couldn't do this with any existing elgg
 * core functions, so I have this here custom query.
 *
 * @uses $params['tag']
 * @uses $params['callback'] - pass in a callback, or use none (return just data rows)
 * @return array
 */
function am_get_entities_from_tag_and_container_tag($params)
{
    global $CONFIG;
    // Default Callback
    if (!$params['callback']) {
        $params['callback'] = 'entity_row_to_elggstar';
    }
    // Default Types
    if (!$params['types']) {
        $params['types'] = array('object');
    }
    $px = $CONFIG->dbprefix;
    $type_subtype_sql = elgg_get_entity_type_subtype_where_sql('e', $params['types'], $params['subtypes'], $params['type_subtype_pairs']);
    if (is_array($params['owner_guids'])) {
        $owner_guids_sql = " AND " . elgg_get_guid_based_where_sql('e.owner_guid', $params['owner_guids']) . " ";
    }
    if ((int) $params['created_time_upper'] && (int) $params['created_time_lower']) {
        $date_sql = " AND " . elgg_get_entity_time_where_sql('e', $params['created_time_upper'], $params['created_time_lower'], $params['modified_time_upper'], $params['modified_time_lower']);
    }
    $access_sql = get_access_sql_suffix('e');
    // Include additional wheres
    if ($params['wheres']) {
        foreach ($params['wheres'] as $where) {
            $wheres .= " AND {$where}";
        }
    }
    // Support Multiple tags
    if (is_array($params['tags']) && count($params['tags']) > 1) {
        foreach ($params['tags'] as $idx => $tag) {
            $index = $idx + 1;
            $metadata .= "\n\t\t\t\tJOIN {$px}metadata n_table{$index} on e.guid = n_table{$index}.entity_guid \n\t\t\t\tJOIN {$px}metastrings msn{$index} on n_table{$index}.name_id = msn{$index}.id \n\t\t\t\tJOIN {$px}metastrings msv{$index} on n_table{$index}.value_id = msv{$index}.id \n\t\t\t";
            $container_metadata .= "\n\t\t\t\tJOIN {$px}metadata c_table{$index} on e.container_guid = c_table{$index}.entity_guid \n\t\t\t\tJOIN {$px}metastrings cmsn{$index} on c_table{$index}.name_id = cmsn{$index}.id \n\t\t\t\tJOIN {$px}metastrings cmsv{$index} on c_table{$index}.value_id = cmsv{$index}.id \n\t\t\t";
            $m_wheres .= "(msn{$index}.string = 'tags' AND msv{$index}.string = '{$tag}')";
            $container_m_wheres .= "(cmsn{$index}.string = 'tags' AND cmsv{$index}.string = '{$tag}')";
            if (count($params['tags']) != $index) {
                $m_wheres .= " AND ";
                $container_m_wheres .= " AND ";
            }
        }
    } else {
        // Single tag
        $metadata = "\n\t\t\tJOIN {$px}metadata n_table1 on e.guid = n_table1.entity_guid \n\t\t\tJOIN {$px}metastrings msn1 on n_table1.name_id = msn1.id \n\t\t\tJOIN {$px}metastrings msv1 on n_table1.value_id = msv1.id\n\t\t";
        $m_wheres = "(msn1.string = 'tags' AND msv1.string = '{$params['tag']}')";
        $container_metadata = "\n\t\t\tJOIN {$px}metadata c_table on e.container_guid = c_table.entity_guid \n\t\t\tJOIN {$px}metastrings cmsn on c_table.name_id = cmsn.id \n\t\t\tJOIN {$px}metastrings cmsv on c_table.value_id = cmsv.id \n\t\t";
        $container_m_wheres = "(cmsn.string = 'tags' AND cmsv.string = '{$params['tag']}')";
    }
    if ($params['container_guid']) {
        $cont = $params['container_guid'];
        $container_guid_join = "JOIN {$px}entities container_e on e.container_guid = container_e.guid";
        $wheres .= "AND (e.container_guid in ({$cont}) OR container_e.container_guid in ({$cont}))";
    }
    $query = "(SELECT e.* FROM {$CONFIG->dbprefix}entities e \n\t\t\t\t{$metadata}\n\t\t\t\t{$container_guid_join}\n\t\t\t\tWHERE {$m_wheres}\n\t\t\t\t\tAND {$type_subtype_sql}\n\t\t\t\t\t{$owner_guids_sql}\n\t\t\t\t\t{$container_guid_sql}\n\t\t\t\t\t{$date_sql}\n\t\t\t\t\tAND (e.site_guid IN ({$CONFIG->site_guid}))\n\t\t\t\t\tAND {$access_sql}\n\t\t\t\t\t{$wheres}) \n\t\t\t\tUNION DISTINCT\n\t\t\t\t(SELECT e.* FROM {$CONFIG->dbprefix}entities e \n\t\t\t\t{$container_metadata}\n\t\t\t\t{$container_guid_join}\n\t\t\t\tWHERE {$container_m_wheres}\n\t\t\t\t\tAND {$type_subtype_sql}\n\t\t\t\t\t{$owner_guids_sql}\n\t\t\t\t\t{$container_guid_sql}\n\t\t\t\t\t{$date_sql}\n\t\t\t\t\tAND (e.site_guid IN ({$CONFIG->site_guid}))\n\t\t\t\t\tAND {$access_sql}\n\t\t\t\t\t{$wheres}) ";
    if (!$params['count']) {
        $query .= " ORDER BY time_created desc";
        if ($params['limit']) {
            $limit = sanitise_int($params['limit']);
            $offset = sanitise_int($params['offset']);
            $query .= " LIMIT {$offset}, {$limit}";
        }
        $dt = get_data($query, $params['callback']);
        return $dt;
    } else {
        $dt = get_data($query);
        return count($dt);
    }
}
开发者ID:amcfarlane1251,项目名称:ongarde,代码行数:77,代码来源:ajaxmodule.php


注:本文中的elgg_get_entity_time_where_sql函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。