Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/25/2020 11:51:13 PM (7 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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.