Skip to:
Content
Pages
Categories
Search
Top
Bottom

BP_Group_Member_Query type alphabetical


  • Garrett Hyder
    Participant

    @garrett-eclipse

    Hello,

    I seemed to have found a bug with the BP_Group_Member_Query and the type argument. I’ve specified it be ‘alphabetical’ and yet the results are still spit out in order of registration.

    
            $query = new BP_Group_Member_Query(array(
                'group_id'   => $group->id,
                'group_role' => 'mod',
                'type'       => 'alphabetical',
            ));
    
            if (!empty($query->results)) {
                $group->mods = $query->results;
            }
    

    Thoughts?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

  • Garrett Hyder
    Participant

    @garrett-eclipse

    O crap,

    scratch that I didn’t read the function properly, that was wrapped in a check for populate_extras

        if (empty($group->args['populate_extras'])) {

    So it never even executed and just used the $group from the global $groups_template->group which already had the admins/mods on it.

    So I guess my question is how can you control the order or sort the $group->admins and $group->mods

    Thanks


    shanebp
    Moderator

    @shanebp

    BP_Group_Member_Query is a class extension of BP_User_Query
    Take a look at the code examples here:

    BP_User_Query


    Garrett Hyder
    Participant

    @garrett-eclipse

    Thanks @shanebp,

    I finally figured that the BP_Group_Member_Query as alphabetical was functioning properly what I’m wondering about now is if I can by default order the admins and mods listings on the $groups_template->group object in alphabetical order?

    Thanks


    shanebp
    Moderator

    @shanebp

    It’d be a lot easier to answer your questions if you were explicit about the functions you’re using, for example: bp_group_list_admins()

    Since it’s called in a template, overload the template and make a call to your own version of that function that sets ‘type’ to whatever you want.


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @shanebp,

    Sorry for the confusion, I’ve created a bp_group_list_managers that’s a merge of bp_group_list_admins and bp_group_list_mods to provide a single consolidated listing.

    function bp_group_list_managers($group=false) {
        global $groups_template;
        if(empty($group)) {
            $group =& $groups_template->group;
        }
    
        // fetch group admins if 'populate_extras' flag is false
        if (empty($group->args['populate_extras']) || true) {
            $query = new BP_Group_Member_Query(array(
                'group_id'   => $group->id,
                'group_role' => 'admin',
                'type'       => 'alphabetical',
            ));
    
            if (!empty($query->results)) {
                $group->admins = $query->results;
            }
        }
    
        // fetch group mods if 'populate_extras' flag is false
        if (empty($group->args['populate_extras']) || true) {
            $query = new BP_Group_Member_Query(array(
                'group_id'   => $group->id,
                'group_role' => 'mod',
                'type'       => 'alphabetical',
            ));
    
            if (!empty($query->results)) {
                $group->mods = $query->results;
            }
        }
    
        $admins = (array)$group->admins;
        $mods = (array)$group->mods;
    
        usort($admins, 'bp_group_member_sort');
        usort($mods, 'bp_group_member_sort');
    
        $group->managers = array_merge($admins, $mods);
    
        if (!empty($group->managers)) { ?>
            <ul id="group-managers">
                <?php foreach((array)$group->managers as $manager) { ?>
                    <li>
                        <a href="<?php echo bp_core_get_user_domain($manager->user_id, $manager->user_nicename, $manager->user_login); ?>"><?php echo bp_core_fetch_avatar(array('item_id' => $manager->user_id, 'email' => $manager->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname($manager->user_id)))) ?></a>
                    </li>
                <?php } ?>
            </ul>
    <?php } else { ?>
        <span class="activity"><?php _e( 'No Managers', 'buddypress' ) ?></span>
    <?php }
    }

    As you can see I set the type here to alphabetical and was first confused why it did nothing then I realized the BP_Group_Member_Query’s were never even called as I guess populate_extras was set so not empty. This meant that the $group->admins and $group->mods came from the global $group_template->group which wasn’t ordered. I’m curious how to make that global $group_template->group admin/mod lists could be alphabetically ordered by default.

    For now I just amended my method to simply force the BP_Group_Member_Query’s to be used instead which has allowed for the alphabetical ordering.

    Hope that clears things up.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘BP_Group_Member_Query type alphabetical’ is closed to new replies.
Skip to toolbar