Skip to:
Content

BuddyPress.org

Changeset 8066


Ignore:
Timestamp:
03/06/2014 07:22:16 PM (7 years ago)
Author:
boonebgorges
Message:

Code quality improvements to BP_Group_Membership_Requests_Template

  • Refactor constructor to accept params as an associative array
  • Don't use extract() in constructor
  • Docblock

See #5440

Props dcavins

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-template.php

    r8063 r8066  
    29292929    var $total_request_count;
    29302930
    2931     function __construct( $group_id, $per_page, $max ) {
     2931    /**
     2932     * Constructor method.
     2933     *
     2934     * @param array $args {
     2935     *     @type int $group_id ID of the group whose membership requests
     2936     *           are being queried. Default: current group id.
     2937     *     @type int $per_page Number of records to return per page of
     2938     *           results. Default: 10.
     2939     *     @type int $max Max items to return. Default: false (show all)
     2940     * }
     2941     */
     2942    function __construct( $args = array() ) {
     2943
     2944        // Backward compatibility with old method of passing arguments
     2945        if ( ! is_array( $args ) || func_num_args() > 1 ) {
     2946            _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     2947
     2948            $old_args_keys = array(
     2949                0 => 'group_id',
     2950                1 => 'per_page',
     2951                2 => 'max',
     2952            );
     2953
     2954            $func_args = func_get_args();
     2955            $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
     2956        }
     2957
     2958        $r = wp_parse_args( $args, array(
     2959            'group_id' => bp_get_current_group_id(),
     2960            'per_page' => 10,
     2961            'max' => false,
     2962        ) );
    29322963
    29332964        $this->pag_page = isset( $_REQUEST['mrpage'] ) ? intval( $_REQUEST['mrpage'] ) : 1;
    2934         $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    2935         $this->requests = BP_Groups_Group::get_membership_requests( $group_id, $this->pag_num, $this->pag_page );
    2936 
    2937         if ( !$max || $max >= (int) $this->requests['total'] )
     2965        $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $r['per_page'];
     2966        $this->requests = BP_Groups_Group::get_membership_requests( $r['group_id'], $this->pag_num, $this->pag_page );
     2967
     2968        if ( !$r['max'] || $r['max'] >= (int) $this->requests['total'] )
    29382969            $this->total_request_count = (int) $this->requests['total'];
    29392970        else
    2940             $this->total_request_count = (int) $max;
     2971            $this->total_request_count = (int) $r['max'];
    29412972
    29422973        $this->requests = $this->requests['requests'];
    29432974
    2944         if ( $max ) {
    2945             if ( $max >= count($this->requests) )
     2975        if ( $r['max'] ) {
     2976            if ( $r['max'] >= count($this->requests) )
    29462977                $this->request_count = count($this->requests);
    29472978            else
    2948                 $this->request_count = (int) $max;
     2979                $this->request_count = (int) $r['max'];
    29492980        } else {
    29502981            $this->request_count = count($this->requests);
     
    30153046
    30163047    $r = wp_parse_args( $args, $defaults );
    3017     extract( $r, EXTR_SKIP );
    3018 
    3019     $requests_template = new BP_Groups_Membership_Requests_Template( $group_id, $per_page, $max );
     3048
     3049    $requests_template = new BP_Groups_Membership_Requests_Template( $r );
    30203050    return apply_filters( 'bp_group_has_membership_requests', $requests_template->has_requests(), $requests_template );
    30213051}
Note: See TracChangeset for help on using the changeset viewer.