Skip to:
Content

BuddyPress.org

Changeset 12551


Ignore:
Timestamp:
02/25/2020 11:51:13 PM (5 years ago)
Author:
imath
Message:

Add the total items amount in Activity and Groups Admin List Tables

The "All" view of the corresponding administration screens is now including the total amount of items between parenthesis.

Props bhargavbhandari90, DJPaul, Hnla

Fixes #7526

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-list-table.php

    r12542 r12551  
    4040
    4141    /**
     42     * Total number of activities.
     43     *
     44     * @since 6.0.0
     45     * @var int $all_count
     46     */
     47    public $all_count = 0;
     48
     49    /**
    4250     * Store activity-to-user-ID mappings for use in the In Response To column.
    4351     *
     
    98106
    99107        // Check if we're on the "Spam" view.
    100         if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) {
     108        if ( ! empty( $_REQUEST['activity_status'] ) && 'spam' === $_REQUEST['activity_status'] ) {
    101109            $spam       = 'spam_only';
    102110            $this->view = 'spam';
    103111        }
    104 
    105         // Sort order.
    106         if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] )
    107             $sort = 'ASC';
    108 
    109         // Order by.
    110         /*if ( !empty( $_REQUEST['orderby'] ) ) {
    111         }*/
    112112
    113113        // Filter.
    114114        if ( ! empty( $_REQUEST['activity_type'] ) ) {
    115115            $filter = array( 'action' => $_REQUEST['activity_type'] );
     116
     117            // Set the view as a filtered one.
     118            $this->view = 'filtered';
    116119
    117120            /**
     
    134137
    135138        // Are we doing a search?
    136         if ( !empty( $_REQUEST['s'] ) )
     139        if ( ! empty( $_REQUEST['s'] ) ) {
    137140            $search_terms = $_REQUEST['s'];
    138141
     142            // Set the view as a search request.
     143            $this->view = 'search';
     144        }
     145
    139146        // Check if user has clicked on a specific activity (if so, fetch only that, and any related, activity).
    140         if ( !empty( $_REQUEST['aid'] ) )
     147        if ( ! empty( $_REQUEST['aid'] ) ) {
    141148            $include_id = (int) $_REQUEST['aid'];
     149
     150            // Set the view as a single activity.
     151            $this->view = 'single';
     152        }
    142153
    143154        // Get the spam total (ignoring any search query or filter).
     
    161172            'filter_query'     => $filter_query,
    162173            'show_hidden'      => true,
    163             // 'sort'             => $sort,
    164174            'spam'             => $spam,
    165175            'count_total'      => 'count_query',
     
    185195
    186196        // Set raw data to display.
    187         $this->items       = $new_activities;
     197        $this->items = $new_activities;
    188198
    189199        // Store information needed for handling table pagination.
     
    196206        // Don't truncate activity items; bp_activity_truncate_entry() needs to be used inside a BP_Activity_Template loop.
    197207        remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
     208
     209        // Set the Total number of activities.
     210        if ( 'all' === $this->view ) {
     211            $this->all_count = (int) $activities['total'];
     212
     213        // Only perform a query if not on the main list view.
     214        } elseif ( 'single' !== $this->view ) {
     215            $count_activities = bp_activity_get(
     216                array(
     217                    'fields'      => 'ids',
     218                    'show_hidden' => true,
     219                    'count_total' => 'count_query',
     220                )
     221            );
     222
     223            if ( $count_activities['total'] ) {
     224                $this->all_count = (int) $count_activities['total'];
     225            }
     226        }
    198227    }
    199228
     
    310339        <h2 class="screen-reader-text"><?php
    311340            /* translators: accessibility text */
    312             _e( 'Filter activities list', 'buddypress' );
     341            esc_html_e( 'Filter activities list', 'buddypress' );
    313342        ?></h2>
    314343
    315344        <ul class="subsubsub">
    316             <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'spam' != $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
    317             <li class="spam"><a href="<?php echo esc_url( add_query_arg( array( 'activity_status' => 'spam' ), $url_base ) ); ?>" class="<?php if ( 'spam' == $this->view ) echo 'current'; ?>"><?php printf( __( 'Spam <span class="count">(%s)</span>', 'buddypress' ), number_format_i18n( $this->spam_count ) ); ?></a></li>
     345            <li class="all">
     346                <a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' === $this->view ) echo 'current'; ?>">
     347                <?php printf(
     348                        /* translators: %s is the placeholder for the count html tag `<span class="count"/>` */
     349                        esc_html__( 'All %s', 'buddypress' ),
     350                        sprintf(
     351                            '<span class="count">(%s)</span>',
     352                            number_format_i18n( $this->all_count )
     353                        )
     354                    ); ?>
     355                </a> |
     356            </li>
     357            <li class="spam">
     358                <a href="<?php echo esc_url( add_query_arg( array( 'activity_status' => 'spam' ), $url_base ) ); ?>" class="<?php if ( 'spam' === $this->view ) echo 'current'; ?>">
     359                    <?php printf(
     360                        /* translators: %s is the placeholder for the count html tag `<span class="count"/>` */
     361                        esc_html__( 'Spam %s', 'buddypress' ),
     362                        sprintf(
     363                            '<span class="count">(%s)</span>',
     364                            number_format_i18n( $this->spam_count )
     365                        )
     366                    ); ?>
     367                </a>
     368            </li>
    318369
    319370            <?php
  • trunk/src/bp-groups/classes/class-bp-groups-list-table.php

    r12331 r12551  
    9696        // Sort order.
    9797        $order = 'DESC';
    98         if ( !empty( $_REQUEST['order'] ) ) {
     98        if ( ! empty( $_REQUEST['order'] ) ) {
    9999            $order = ( 'desc' == strtolower( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
    100100        }
     
    120120
    121121        // Are we doing a search?
    122         if ( !empty( $_REQUEST['s'] ) )
     122        if ( ! empty( $_REQUEST['s'] ) ) {
    123123            $search_terms = $_REQUEST['s'];
    124124
     125            // Set the view as a search request.
     126            $this->view = 'search';
     127        }
     128
    125129        // Check if user has clicked on a specific group (if so, fetch only that group).
    126         if ( !empty( $_REQUEST['gid'] ) )
     130        if ( ! empty( $_REQUEST['gid'] ) ) {
    127131            $include_id = (int) $_REQUEST['gid'];
    128132
    129         // Set the current view.
     133            // Set the view as a single activity.
     134            $this->view = 'single';
     135        }
     136
     137        // Use the status request to set the current view.
    130138        if ( isset( $_GET['group_status'] ) && in_array( $_GET['group_status'], array( 'public', 'private', 'hidden' ) ) ) {
    131139            $this->view = $_GET['group_status'];
     
    187195            'total_pages' => ceil( $groups_template->total_group_count / $per_page )
    188196        ) );
     197
     198        // Set the Total number of groups.
     199        if ( 'all' === $this->view ) {
     200            $this->group_counts['all'] = (int) $groups_template->total_group_count;
     201
     202        // Only perform a query if not on the main list view.
     203        } elseif ( 'single' !== $this->view ) {
     204            $count_groups = groups_get_groups(
     205                array(
     206                    'fields'      => 'ids',
     207                    'show_hidden' => true,
     208                )
     209            );
     210
     211            if ( $count_groups['total'] ) {
     212                $this->group_counts['all'] = (int) $count_groups['total'];
     213            }
     214        }
    189215    }
    190216
     
    332358
    333359        <ul class="subsubsub">
    334             <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' == $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
    335             <li class="public"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'public', $url_base ) ); ?>" class="<?php if ( 'public' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Public <span class="count">(%s)</span>', 'Public <span class="count">(%s)</span>', $this->group_counts['public'], 'buddypress' ), number_format_i18n( $this->group_counts['public'] ) ); ?></a> |</li>
    336             <li class="private"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'private', $url_base ) ); ?>" class="<?php if ( 'private' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', $this->group_counts['private'], 'buddypress' ), number_format_i18n( $this->group_counts['private'] ) ); ?></a> |</li>
    337             <li class="hidden"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'hidden', $url_base ) ); ?>" class="<?php if ( 'hidden' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', $this->group_counts['hidden'], 'buddypress' ), number_format_i18n( $this->group_counts['hidden'] ) ); ?></a></li>
     360            <li class="all">
     361                <a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' === $this->view ) echo 'current'; ?>">
     362                    <?php printf(
     363                        /* translators: %s is the placeholder for the count html tag `<span class="count"/>` */
     364                        esc_html__( 'All %s', 'buddypress' ),
     365                        sprintf(
     366                            '<span class="count">(%s)</span>',
     367                            number_format_i18n( $this->group_counts['all'] )
     368                        )
     369                    ); ?>
     370                </a> |
     371            </li>
     372            <li class="public">
     373                <a href="<?php echo esc_url( add_query_arg( 'group_status', 'public', $url_base ) ); ?>" class="<?php if ( 'public' === $this->view ) echo 'current'; ?>">
     374                    <?php printf(
     375                        /* translators: %s is the placeholder for the count html `<span class="count"/>` */
     376                        _n( 'Public %s', 'Public %s', $this->group_counts['public'], 'buddypress' ),
     377                        sprintf(
     378                            '<span class="count">(%s)</span>',
     379                            number_format_i18n( $this->group_counts['public'] )
     380                        )
     381                    ); ?>
     382                </a> |
     383            </li>
     384            <li class="private">
     385                <a href="<?php echo esc_url( add_query_arg( 'group_status', 'private', $url_base ) ); ?>" class="<?php if ( 'private' === $this->view ) echo 'current'; ?>">
     386                    <?php printf(
     387                        /* translators: %s is the placeholder for the count html `<span class="count"/>` */
     388                        _n( 'Private %s', 'Private %s', $this->group_counts['private'], 'buddypress' ),
     389                        sprintf(
     390                            '<span class="count">(%s)</span>',
     391                            number_format_i18n( $this->group_counts['private'] )
     392                        )
     393                    ); ?>
     394                </a> |
     395            </li>
     396            <li class="hidden">
     397                <a href="<?php echo esc_url( add_query_arg( 'group_status', 'hidden', $url_base ) ); ?>" class="<?php if ( 'hidden' === $this->view ) echo 'current'; ?>">
     398                    <?php printf(
     399                        /* translators: %s is the placeholder for the count html tag */
     400                        _n( 'Hidden %s', 'Hidden %s', $this->group_counts['hidden'], 'buddypress' ),
     401                        sprintf(
     402                            '<span class="count">(%s)</span>',
     403                            number_format_i18n( $this->group_counts['hidden'] )
     404                        )
     405                    ); ?>
     406                </a>
     407            </li>
    338408
    339409            <?php
Note: See TracChangeset for help on using the changeset viewer.