本文整理汇总了PHP中BP_Groups_Group::get_group_extras方法的典型用法代码示例。如果您正苦于以下问题:PHP BP_Groups_Group::get_group_extras方法的具体用法?PHP BP_Groups_Group::get_group_extras怎么用?PHP BP_Groups_Group::get_group_extras使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BP_Groups_Group
的用法示例。
在下文中一共展示了BP_Groups_Group::get_group_extras方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_random
function get_random($limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false)
{
global $wpdb, $bp;
$pag_sql = $hidden_sql = $search_sql = $exclude_sql = '';
if (!empty($limit) && !empty($page)) {
$pag_sql = $wpdb->prepare(" LIMIT %d, %d", intval(($page - 1) * $limit), intval($limit));
}
if (!is_user_logged_in() || !bp_current_user_can('bp_moderate') && $user_id != bp_loggedin_user_id()) {
$hidden_sql = "AND g.status != 'hidden'";
}
if (!empty($search_terms)) {
$search_terms = like_escape($wpdb->escape($search_terms));
$search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
}
if (!empty($exclude)) {
$exclude = $wpdb->escape($exclude);
$exclude_sql = " AND g.id NOT IN ({$exclude})";
}
if (!empty($user_id)) {
$user_id = $wpdb->escape($user_id);
$paged_groups = $wpdb->get_results("SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY rand() {$pag_sql}");
$total_groups = $wpdb->get_var("SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}");
} else {
$paged_groups = $wpdb->get_results("SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY rand() {$pag_sql}");
$total_groups = $wpdb->get_var("SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} {$exclude_sql}");
}
if (!empty($populate_extras)) {
foreach ((array) $paged_groups as $group) {
$group_ids[] = $group->id;
}
$group_ids = $wpdb->escape(join(',', (array) $group_ids));
$paged_groups = BP_Groups_Group::get_group_extras($paged_groups, $group_ids, 'newest');
}
return array('groups' => $paged_groups, 'total' => $total_groups);
}
示例2: gtags_get_groups_by_tag
function gtags_get_groups_by_tag($limit = null, $page = null, $user_id = false, $search_terms = false, $group_tag = null)
{
global $wpdb, $bp;
$hidden_sql = $search_sql = $tag_sql = $pag_sql = '';
if ($limit && $page) {
$pag_sql = $wpdb->prepare(" LIMIT %d, %d", intval(($page - 1) * $limit), intval($limit));
}
if (!is_user_logged_in()) {
$hidden_sql = "AND g.status != 'hidden'";
}
if ($search_terms) {
$search_terms = like_escape($wpdb->escape($search_terms));
$search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
}
if ($group_tag) {
$group_tag = like_escape($wpdb->escape($group_tag));
$group_tag = stripslashes($group_tag);
$tag_sql = " AND ( gm3.meta_value LIKE '%%{$group_tag}%%' )";
}
$paged_groups = $wpdb->get_results("SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity, gm3.meta_value as gtags_group_tags FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND gm3.meta_key = 'gtags_group_tags' {$hidden_sql} {$search_sql} {$tag_sql} ORDER BY CONVERT(gm1.meta_value, SIGNED) DESC {$pag_sql}");
// this is commented out because it doesn't really work due to the over-inclusive issue.
//$total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND gm3.meta_key = 'gtags_group_tags' {$hidden_sql} {$search_sql} {$tag_sql}" );
// loop through results and return only exact matches in comma separated list.
$paged_groups2 = array();
foreach ((array) $paged_groups as $group) {
$items = explode(",", $group->gtags_group_tags);
$match = false;
foreach ($items as $item) {
if (trim(strtolower($item)) == strtolower($group_tag)) {
$match = true;
}
}
if ($match == true) {
$paged_groups2[] = $group;
}
}
$total_groups = count($paged_groups2);
// in place of the commented out code above
foreach ((array) $paged_groups2 as $group) {
$group_ids[] = $group->id;
}
$group_ids = $wpdb->escape(join(',', (array) $group_ids));
$paged_groups2 = BP_Groups_Group::get_group_extras(&$paged_groups2, $group_ids, 'popular');
return array('groups' => $paged_groups2, 'total' => $total_groups);
}
示例3: test_get_group_extras_banned
/**
* @group get_group_extras
*/
public function test_get_group_extras_banned()
{
$u = $this->factory->user->create();
$g = $this->factory->group->create();
$member = new BP_Groups_Member();
$member->group_id = $g;
$member->user_id = $u;
$member->date_modified = bp_core_current_time();
$member->is_banned = true;
$member->save();
$paged_groups = array();
$paged_groups[] = new stdClass();
$paged_groups[0]->id = $g;
$group_ids = array($g);
$expected = array();
foreach ($paged_groups as $key => $value) {
$expected[$key] = new stdClass();
$expected[$key]->id = $value->id;
$expected[$key]->is_member = '0';
$expected[$key]->is_invited = '0';
$expected[$key]->is_pending = '0';
$expected[$key]->is_banned = true;
}
$old_user = get_current_user_id();
$this->set_current_user($u);
$this->assertEquals($expected, BP_Groups_Group::get_group_extras($paged_groups, $group_ids));
$this->set_current_user($old_user);
}
示例4: foreach
/**
* Not declared as static in parent, but called statically
*/
function get_group_extras($paged_groups, $group_ids, $type = false)
{
foreach ($paged_groups as $key => $group) {
if (!isset($group->path)) {
$paged_groups[$key]->path = self::get_path($group->id);
$paged_groups[$key]->slug = $paged_groups[$key]->path;
}
}
if (empty($group_ids)) {
return $paged_groups;
}
return parent::get_group_extras($paged_groups, $group_ids, $type);
}