예제 #1
0
/**
 * Inject $members_template global with follow status for each member in the
 * group members loop.
 *
 * Once the group members loop has queried and built a $members_template
 * object, fetch all of the member IDs in the object and bulk fetch the
 * following status for all the group members in one query.
 *
 * This is significantly more efficient that querying for every member inside
 * of the loop.
 *
 * @author r-a-y
 * @since 1.1
 *
 * @global $members_template The members template object containing all fetched members in the loop
 * @uses BP_Follow::bulk_check_follow_status() Check the following status for more than one member
 * @param $has_members - Whether any members where actually returned in the loop
 * @return $has_members - Return the original $has_members param as this is a filter function.
 */
function bp_follow_inject_group_member_follow_status($has_members)
{
    global $members_template;
    if (empty($has_members)) {
        return $has_members;
    }
    $user_ids = array();
    foreach ((array) $members_template->members as $i => $member) {
        if ($member->user_id != bp_loggedin_user_id()) {
            $user_ids[] = $member->user_id;
        }
        $members_template->members[$i]->is_following = false;
    }
    if (empty($user_ids)) {
        return $has_members;
    }
    $following = BP_Follow::bulk_check_follow_status($user_ids);
    if (empty($following)) {
        return $has_members;
    }
    foreach ((array) $following as $is_following) {
        foreach ((array) $members_template->members as $i => $member) {
            if ($is_following->leader_id == $member->user_id) {
                $members_template->members[$i]->is_following = true;
            }
        }
    }
    return $has_members;
}
예제 #2
0
 /**
  * Bulk-check the follow status of all blogs in a blogs loop.
  *
  * This is so we don't have query each follow blog status individually.
  */
 public function bulk_inject_blog_follow_status($has_blogs)
 {
     global $blogs_template;
     if (empty($has_blogs)) {
         return $has_blogs;
     }
     if (!is_user_logged_in()) {
         return $has_blogs;
     }
     $blog_ids = array();
     foreach ((array) $blogs_template->blogs as $i => $blog) {
         // add blog ID to array
         $blog_ids[] = $blog->blog_id;
         // set default follow status to false
         $blogs_template->blogs[$i]->is_following = false;
     }
     if (empty($blog_ids)) {
         return $has_blogs;
     }
     $following = BP_Follow::bulk_check_follow_status($blog_ids, bp_loggedin_user_id(), 'blogs');
     if (empty($following)) {
         return $has_blogs;
     }
     foreach ((array) $following as $is_following) {
         foreach ((array) $blogs_template->blogs as $i => $blog) {
             // set follow status to true if the logged-in user is following
             if ($is_following->leader_id == $blog->blog_id) {
                 $blogs_template->blogs[$i]->is_following = true;
             }
         }
     }
     return $has_blogs;
 }
 public function bulk_inject_follow_status($retval)
 {
     global $activities_template;
     if (empty($retval)) {
         return $retval;
     }
     if (!is_user_logged_in()) {
         return $retval;
     }
     $activity_ids = array();
     foreach ((array) $activities_template->activities as $i => $activity) {
         // add blog ID to array
         $activity_ids[] = $activity->id;
         // set default follow status to false
         $activities_template->activities[$i]->is_following = false;
     }
     if (empty($activity_ids)) {
         return $retval;
     }
     $following = BP_Follow::bulk_check_follow_status($activity_ids, bp_loggedin_user_id(), 'activity');
     if (empty($following)) {
         return $retval;
     }
     foreach ((array) $following as $is_following) {
         foreach ((array) $activities_template->activities as $i => $activity) {
             // set follow status to true if the logged-in user is following
             if ($is_following->leader_id == $activity->id) {
                 $activities_template->activities[$i]->is_following = true;
             }
         }
     }
     return $retval;
 }