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


PHP BP_Core_User::get_last_activity方法代码示例

本文整理汇总了PHP中BP_Core_User::get_last_activity方法的典型用法代码示例。如果您正苦于以下问题:PHP BP_Core_User::get_last_activity方法的具体用法?PHP BP_Core_User::get_last_activity怎么用?PHP BP_Core_User::get_last_activity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BP_Core_User的用法示例。


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

示例1: bp_get_user_last_activity

/**
 * Get the last activity for a given user.
 *
 * @since 1.9.0
 *
 * @param int $user_id The ID of the user.
 * @return string Time of last activity, in 'Y-m-d H:i:s' format, or an empty
 *                string if none is found.
 */
function bp_get_user_last_activity($user_id = 0)
{
    $activity = '';
    $last_activity = BP_Core_User::get_last_activity($user_id);
    if (!empty($last_activity[$user_id])) {
        $activity = $last_activity[$user_id]['date_recorded'];
    }
    /**
     * Filters the last activity for a given user.
     *
     * @since 1.9.0
     *
     * @param string $activity Time of last activity, in 'Y-m-d H:i:s' format or
     *                         an empty string if none found.
     * @param int    $user_id  ID of the user being checked.
     */
    return apply_filters('bp_get_user_last_activity', $activity, $user_id);
}
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:27,代码来源:bp-members-functions.php

示例2: populate_extras

 /**
  * Perform a database query to populate any extra metadata we might need.
  *
  * Different components will hook into the 'bp_user_query_populate_extras'
  * action to loop in the things they want.
  *
  * @since 1.7.0
  *
  * @global WPDB $wpdb Global WordPress database access object.
  */
 public function populate_extras()
 {
     global $wpdb;
     // Bail if no users.
     if (empty($this->user_ids) || empty($this->results)) {
         return;
     }
     // Bail if the populate_extras flag is set to false
     // In the case of the 'popular' sort type, we force
     // populate_extras to true, because we need the friend counts.
     if ('popular' == $this->query_vars['type']) {
         $this->query_vars['populate_extras'] = 1;
     }
     if (!(bool) $this->query_vars['populate_extras']) {
         return;
     }
     // Turn user ID's into a query-usable, comma separated value.
     $user_ids_sql = implode(',', wp_parse_id_list($this->user_ids));
     /**
      * Allows users to independently populate custom extras.
      *
      * Note that anything you add here should query using $user_ids_sql, to
      * avoid running multiple queries per user in the loop.
      *
      * Two BuddyPress components currently do this:
      * - XProfile: To override display names.
      * - Friends:  To set whether or not a user is the current users friend.
      *
      * @see bp_xprofile_filter_user_query_populate_extras()
      * @see bp_friends_filter_user_query_populate_extras()
      *
      * @since 1.7.0
      *
      * @param BP_User_Query $this         Current BP_User_Query instance.
      * @param string        $user_ids_sql Comma-separated string of user IDs.
      */
     do_action_ref_array('bp_user_query_populate_extras', array($this, $user_ids_sql));
     // Fetch last_active data from the activity table.
     $last_activities = BP_Core_User::get_last_activity($this->user_ids);
     // Set a last_activity value for each user, even if it's empty.
     foreach ($this->results as $user_id => $user) {
         $user_last_activity = isset($last_activities[$user_id]) ? $last_activities[$user_id]['date_recorded'] : '';
         $this->results[$user_id]->last_activity = $user_last_activity;
     }
     // Fetch usermeta data
     // We want the three following pieces of info from usermeta:
     // - friend count
     // - latest update.
     $total_friend_count_key = bp_get_user_meta_key('total_friend_count');
     $bp_latest_update_key = bp_get_user_meta_key('bp_latest_update');
     // Total_friend_count must be set for each user, even if its
     // value is 0.
     foreach ($this->results as $uindex => $user) {
         $this->results[$uindex]->total_friend_count = 0;
     }
     // Create, prepare, and run the separate usermeta query.
     $user_metas = $wpdb->get_results($wpdb->prepare("SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN (%s,%s) AND user_id IN ({$user_ids_sql})", $total_friend_count_key, $bp_latest_update_key));
     // The $members_template global expects the index key to be different
     // from the meta_key in some cases, so we rejig things here.
     foreach ($user_metas as $user_meta) {
         switch ($user_meta->meta_key) {
             case $total_friend_count_key:
                 $key = 'total_friend_count';
                 break;
             case $bp_latest_update_key:
                 $key = 'latest_update';
                 break;
         }
         if (isset($this->results[$user_meta->user_id])) {
             $this->results[$user_meta->user_id]->{$key} = $user_meta->meta_value;
         }
     }
     // When meta_key or meta_value have been passed to the query,
     // fetch the resulting values for use in the template functions.
     if (!empty($this->query_vars['meta_key'])) {
         $meta_sql = array('select' => "SELECT user_id, meta_key, meta_value", 'from' => "FROM {$wpdb->usermeta}", 'where' => $wpdb->prepare("WHERE meta_key = %s", $this->query_vars['meta_key']));
         if (false !== $this->query_vars['meta_value']) {
             $meta_sql['where'] .= $wpdb->prepare(" AND meta_value = %s", $this->query_vars['meta_value']);
         }
         $metas = $wpdb->get_results("{$meta_sql['select']} {$meta_sql['from']} {$meta_sql['where']}");
         if (!empty($metas)) {
             foreach ($metas as $meta) {
                 if (isset($this->results[$meta->user_id])) {
                     $this->results[$meta->user_id]->meta_key = $meta->meta_key;
                     if (!empty($meta->meta_value)) {
                         $this->results[$meta->user_id]->meta_value = $meta->meta_value;
                     }
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:igniterealtime,项目名称:community-plugins,代码行数:101,代码来源:class-bp-user-query.php

示例3: get_bulk_last_active

    /**
     * Get the last active date of many users at once.
     *
     * @todo Why is this in the Friends component?
     *
     * @param array $user_ids IDs of users whose last_active meta is
     *                        being queried.
     *
     * @return array $retval Array of last_active values + user_ids.
     */
    public static function get_bulk_last_active($user_ids)
    {
        global $wpdb;
        $last_activities = BP_Core_User::get_last_activity($user_ids);
        // Sort and structure as expected in legacy function
        usort($last_activities, create_function('$a, $b', '
			if ( $a["date_recorded"] == $b["date_recorded"] ) {
				return 0;
			}

			return ( strtotime( $a["date_recorded"] ) < strtotime( $b["date_recorded"] ) ) ? 1 : -1;
		'));
        $retval = array();
        foreach ($last_activities as $last_activity) {
            $u = new stdClass();
            $u->last_activity = $last_activity['date_recorded'];
            $u->user_id = $last_activity['user_id'];
            $retval[] = $u;
        }
        return $retval;
    }
开发者ID:AceMedia,项目名称:BuddyPress,代码行数:31,代码来源:class-bp-friends-friendship.php

示例4: bp_get_user_last_activity

/**
 * Get the last activity for a given user.
 *
 * @param int $user_id The ID of the user.
 * @return string Time of last activity, in 'Y-m-d H:i:s' format, or an empty
 *         string if none is found.
 */
function bp_get_user_last_activity($user_id = 0)
{
    $activity = '';
    $last_activity = BP_Core_User::get_last_activity($user_id);
    if (!empty($last_activity[$user_id])) {
        $activity = $last_activity[$user_id]['date_recorded'];
    }
    return apply_filters('bp_get_user_last_activity', $activity, $user_id);
}
开发者ID:eresyyl,项目名称:mk,代码行数:16,代码来源:bp-members-functions.php

示例5: test_delete_last_activity

 /**
  * @group last_activity
  */
 public function test_delete_last_activity()
 {
     $u = $this->factory->user->create();
     $time = bp_core_current_time();
     BP_Core_User::update_last_activity($u, $time);
     $a = BP_Core_User::get_last_activity($u);
     $found = isset($a[$u]['date_recorded']) ? $a[$u]['date_recorded'] : '';
     $this->assertEquals($time, $found);
     BP_Core_User::delete_last_activity($u);
     $a = BP_Core_User::get_last_activity($u);
     $found = isset($a[$u]['date_recorded']) ? $a[$u]['date_recorded'] : '';
     $this->assertEquals('', $found);
 }
开发者ID:JeroenNouws,项目名称:BuddyPress,代码行数:16,代码来源:class-bp-core-user.php


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