BP_Groups_Membership_Requests_Template

Membership request template loop class.

Defined (1)

The class is defined in the following location(s).

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