Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/10/2010 08:12:08 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Clean-up pagination in all components. Fixes #2625. Props BenFremer on your first trac ticket!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-groups/bp-groups-templatetags.php

    r3201 r3245  
    2727
    2828        $this->pag_page = isset( $_REQUEST['grpage'] ) ? intval( $_REQUEST['grpage'] ) : $page;
    29         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    30 
    31         if ( 'invites' == $type )
     29        $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     30
     31        if ( 'invites' == $type ) {
    3232            $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page );
    33         else if ( 'single-group' == $type ) {
     33        } else if ( 'single-group' == $type ) {
    3434            $group = new stdClass;
    3535            $group->group_id = BP_Groups_Group::get_id_from_slug($slug);
    36             $this->groups = array( $group );
    37         } else
     36            $this->groups    = array( $group );
     37        } else {
    3838            $this->groups = groups_get_groups( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' =>$this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
     39        }
    3940
    4041        if ( 'invites' == $type ) {
    4142            $this->total_group_count = (int)$this->groups['total'];
    42             $this->group_count = (int)$this->groups['total'];
     43            $this->group_count       = (int)$this->groups['total'];
     44            $this->groups            = $this->groups['groups'];
     45        } else if ( 'single-group' == $type ) {
     46            $this->single_group      = true;
     47            $this->total_group_count = 1;
     48            $this->group_count       = 1;
     49        } else {
     50            if ( !$max || $max >= (int)$this->groups['total'] ) {
     51                $this->total_group_count = (int)$this->groups['total'];
     52            } else {
     53                $this->total_group_count = (int)$max;
     54            }
     55
    4356            $this->groups = $this->groups['groups'];
    44         } else if ( 'single-group' == $type ) {
    45             $this->single_group = true;
    46             $this->total_group_count = 1;
    47             $this->group_count = 1;
    48         } else {
    49             if ( !$max || $max >= (int)$this->groups['total'] )
    50                 $this->total_group_count = (int)$this->groups['total'];
    51             else
    52                 $this->total_group_count = (int)$max;
    53 
    54             $this->groups = $this->groups['groups'];
    5557
    5658            if ( $max ) {
    57                 if ( $max >= count($this->groups) )
    58                     $this->group_count = count($this->groups);
    59                 else
     59                if ( $max >= count($this->groups) ) {
     60                    $this->group_count = count( $this->groups );
     61                } else {
    6062                    $this->group_count = (int)$max;
     63                }
    6164            } else {
    62                 $this->group_count = count($this->groups);
     65                $this->group_count = count( $this->groups );
    6366            }
    6467        }
    6568
    66         $this->pag_links = paginate_links( array(
    67             'base' => add_query_arg( array( 'grpage' => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order ) ),
    68             'format' => '',
    69             'total' => ceil($this->total_group_count / $this->pag_num),
    70             'current' => $this->pag_page,
    71             'prev_text' => '←',
    72             'next_text' => '→',
    73             'mid_size' => 1
    74         ));
     69        // Build pagination links
     70        if ( (int)$this->total_group_count && (int)$this->pag_num ) {
     71            $this->pag_links = paginate_links( array(
     72                'base'      => add_query_arg( array( 'grpage' => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order ) ),
     73                'format'    => '',
     74                'total'     => ceil( (int)$this->total_group_count / (int)$this->pag_num ),
     75                'current'   => $this->pag_page,
     76                'prev_text' => '←',
     77                'next_text' => '→',
     78                'mid_size'  => 1
     79            ) );
     80        }
    7581    }
    7682
Note: See TracChangeset for help on using the changeset viewer.