[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Groups membership request template loop class. 4 * 5 * @package BuddyPress 6 * @since 1.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Membership request template loop class. 14 * 15 * @since 1.0.0 16 */ 17 class BP_Groups_Membership_Requests_Template { 18 19 /** 20 * @since 1.0.0 21 * @var int 22 */ 23 public $current_request = -1; 24 25 /** 26 * @since 1.0.0 27 * @var int 28 */ 29 public $request_count; 30 31 /** 32 * @since 1.0.0 33 * @var array 34 */ 35 public $requests; 36 37 /** 38 * @since 1.0.0 39 * @var object 40 */ 41 public $request; 42 43 /** 44 * @sine 1.0.0 45 * @var bool 46 */ 47 public $in_the_loop; 48 49 /** 50 * @since 1.0.0 51 * @var int 52 */ 53 public $pag_page; 54 55 /** 56 * @since 1.0.0 57 * @var int 58 */ 59 public $pag_num; 60 61 /** 62 * @since 1.0.0 63 * @var array|string|void 64 */ 65 public $pag_links; 66 67 /** 68 * @since 1.0.0 69 * @var int 70 */ 71 public $total_request_count; 72 73 /** 74 * Constructor method. 75 * 76 * @since 1.5.0 77 * 78 * @param array $args { 79 * @type int $group_id ID of the group whose membership requests 80 * are being queried. Default: current group id. 81 * @type int $per_page Number of records to return per page of 82 * results. Default: 10. 83 * @type int $page Page of results to show. Default: 1. 84 * @type int $max Max items to return. Default: false (show all) 85 * } 86 */ 87 public function __construct( $args = array() ) { 88 $function_args = func_get_args(); 89 90 // Backward compatibility with old method of passing arguments. 91 if ( ! is_array( $args ) || count( $function_args ) > 1 ) { 92 /* translators: 1: the name of the method. 2: the name of the file. */ 93 _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__ ) ); 94 95 $old_args_keys = array( 96 0 => 'group_id', 97 1 => 'per_page', 98 2 => 'max', 99 ); 100 101 $args = bp_core_parse_args_array( $old_args_keys, $function_args ); 102 } 103 104 $r = bp_parse_args( 105 $args, 106 array( 107 'page' => 1, 108 'per_page' => 10, 109 'page_arg' => 'mrpage', 110 'max' => false, 111 'type' => 'first_joined', 112 'group_id' => bp_get_current_group_id(), 113 ), 114 'groups_membership_requests_template' 115 ); 116 117 $this->pag_arg = sanitize_key( $r['page_arg'] ); 118 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] ); 119 $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] ); 120 121 $mquery = new BP_Group_Member_Query( array( 122 'group_id' => $r['group_id'], 123 'type' => $r['type'], 124 'per_page' => $this->pag_num, 125 'page' => $this->pag_page, 126 127 // These filters ensure we only get pending requests. 128 'is_confirmed' => false, 129 'inviter_id' => 0, 130 ) ); 131 132 $this->requests = array_values( $mquery->results ); 133 $this->request_count = count( $this->requests ); 134 135 // Compatibility with legacy format of request data objects. 136 foreach ( $this->requests as $rk => $rv ) { 137 // For legacy reasons, the 'id' property of each 138 // request must match the membership id, not the ID of 139 // the user (as it's returned by BP_Group_Member_Query). 140 $this->requests[ $rk ]->user_id = $rv->ID; 141 $this->requests[ $rk ]->id = $rv->membership_id; 142 143 // Miscellaneous values. 144 $this->requests[ $rk ]->group_id = $r['group_id']; 145 } 146 147 if ( empty( $r['max'] ) || ( $r['max'] >= (int) $mquery->total_users ) ) { 148 $this->total_request_count = (int) $mquery->total_users; 149 } else { 150 $this->total_request_count = (int) $r['max']; 151 } 152 153 if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->requests ) ) ) { 154 $this->request_count = count( $this->requests ); 155 } else { 156 $this->request_count = (int) $r['max']; 157 } 158 159 $this->pag_links = paginate_links( array( 160 'base' => add_query_arg( $this->pag_arg, '%#%' ), 161 'format' => '', 162 'total' => ceil( $this->total_request_count / $this->pag_num ), 163 'current' => $this->pag_page, 164 'prev_text' => '←', 165 'next_text' => '→', 166 'mid_size' => 1, 167 'add_args' => array(), 168 ) ); 169 } 170 171 /** 172 * Whether or not there are requests to show. 173 * 174 * @since 1.0.0 175 * 176 * @return bool 177 */ 178 public function has_requests() { 179 if ( ! empty( $this->request_count ) ) { 180 return true; 181 } 182 183 return false; 184 } 185 186 /** 187 * Moves up to the next request. 188 * 189 * @since 1.0.0 190 * 191 * @return object 192 */ 193 public function next_request() { 194 $this->current_request++; 195 $this->request = $this->requests[ $this->current_request ]; 196 197 return $this->request; 198 } 199 200 /** 201 * Rewinds the requests to the first in the list. 202 * 203 * @since 1.0.0 204 */ 205 public function rewind_requests() { 206 $this->current_request = -1; 207 208 if ( $this->request_count > 0 ) { 209 $this->request = $this->requests[0]; 210 } 211 } 212 213 /** 214 * Finishes up the requests to display. 215 * 216 * @since 1.0.0 217 * 218 * @return bool 219 */ 220 public function requests() { 221 $tick = intval( $this->current_request + 1 ); 222 if ( $tick < $this->request_count ) { 223 return true; 224 } elseif ( $tick == $this->request_count ) { 225 226 /** 227 * Fires right before the rewinding of group membership requests list. 228 * 229 * @since 1.5.0 230 */ 231 do_action( 'group_request_loop_end' ); 232 // Do some cleaning up after the loop. 233 $this->rewind_requests(); 234 } 235 236 $this->in_the_loop = false; 237 return false; 238 } 239 240 /** 241 * Sets up the request to display. 242 * 243 * @since 1.0.0 244 */ 245 public function the_request() { 246 $this->in_the_loop = true; 247 $this->request = $this->next_request(); 248 249 // Loop has just started. 250 if ( 0 == $this->current_request ) { 251 252 /** 253 * Fires if the current group membership request item is the first in the loop. 254 * 255 * @since 1.1.0 256 */ 257 do_action( 'group_request_loop_start' ); 258 } 259 } 260 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 15 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |