[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/classes/ -> class-bp-members-invitations-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Members Invitation Template Loop Class.
   4   *
   5   * @package BuddyPress
   6   * @subpackage TonificationsTemplate
   7   * @since 8.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * The main membership invitations template loop class.
  15   *
  16   * Responsible for loading a group of membership invitations into a loop for display.
  17   *
  18   * @since 8.0.0
  19   */
  20  class BP_Members_Invitations_Template {
  21  
  22      /**
  23       * The loop iterator.
  24       *
  25       * @since 8.0.0
  26       * @var int
  27       */
  28      public $current_invitation = -1;
  29  
  30      /**
  31       * The number of invitations returned by the paged query.
  32       *
  33       * @since 8.0.0
  34       * @var int
  35       */
  36      public $current_invitation_count;
  37  
  38      /**
  39       * Total number of invitations matching the query.
  40       *
  41       * @since 8.0.0
  42       * @var int
  43       */
  44      public $total_invitation_count;
  45  
  46      /**
  47       * Array of network invitations located by the query.
  48       *
  49       * @since 8.0.0
  50       * @var array
  51       */
  52      public $invitations;
  53  
  54      /**
  55       * The invitation object currently being iterated on.
  56       *
  57       * @since 8.0.0
  58       * @var object
  59       */
  60      public $invitation;
  61  
  62      /**
  63       * A flag for whether the loop is currently being iterated.
  64       *
  65       * @since 8.0.0
  66       * @var bool
  67       */
  68      public $in_the_loop;
  69  
  70      /**
  71       * The ID of the user to whom the displayed invitations were sent.
  72       *
  73       * @since 8.0.0
  74       * @var int
  75       */
  76      public $user_id;
  77  
  78      /**
  79       * The ID of the user to whom the displayed invitations belong.
  80       *
  81       * @since 8.0.0
  82       * @var int
  83       */
  84      public $inviter_id;
  85  
  86      /**
  87       * The page number being requested.
  88       *
  89       * @since 8.0.0
  90       * @var int
  91       */
  92      public $pag_page;
  93  
  94      /**
  95       * The $_GET argument used in URLs for determining pagination.
  96       *
  97       * @since 8.0.0
  98       * @var int
  99       */
 100      public $pag_arg;
 101  
 102      /**
 103       * The number of items to display per page of results.
 104       *
 105       * @since 8.0.0
 106       * @var int
 107       */
 108      public $pag_num;
 109  
 110      /**
 111       * An HTML string containing pagination links.
 112       *
 113       * @since 8.0.0
 114       * @var string
 115       */
 116      public $pag_links;
 117  
 118      /**
 119       * A string to match against.
 120       *
 121       * @since 8.0.0
 122       * @var string
 123       */
 124      public $search_terms;
 125  
 126      /**
 127       * A database column to order the results by.
 128       *
 129       * @since 8.0.0
 130       * @var string
 131       */
 132      public $order_by;
 133  
 134      /**
 135       * The direction to sort the results (ASC or DESC).
 136       *
 137       * @since 8.0.0
 138       * @var string
 139       */
 140      public $sort_order;
 141  
 142      /**
 143       * Array of variables used in this invitation query.
 144       *
 145       * @since 8.0.0
 146       * @var array
 147       */
 148      public $query_vars;
 149  
 150      /**
 151       * Constructor method.
 152       *
 153       * @see bp_has_members_invitations() For information on the array format.
 154       *
 155       * @since 8.0.0
 156       *
 157       * @param array $args {
 158       *     An array of arguments. See {@link bp_has_members_invitations()}
 159       *     for more details.
 160       * }
 161       */
 162  	public function __construct( $args = array() ) {
 163  
 164          // Parse arguments.
 165          $r = bp_parse_args(
 166              $args,
 167              array(
 168                  'id'            => false,
 169                  'user_id'       => false,
 170                  'inviter_id'    => false,
 171                  'invitee_email' => false,
 172                  'item_id'       => false,
 173                  'type'          => 'invite',
 174                  'invite_sent'   => 'all',
 175                  'accepted'      => 'all',
 176                  'search_terms'  => '',
 177                  'order_by'      => 'date_modified',
 178                  'sort_order'    => 'DESC',
 179                  'page'          => 1,
 180                  'per_page'      => 25,
 181                  'fields'        => 'all',
 182                  'page_arg'      => 'ipage',
 183              )
 184          );
 185  
 186          // Sort order direction.
 187          if ( ! empty( $_GET['sort_order'] ) ) {
 188              $r['sort_order'] = $_GET['sort_order'];
 189          }
 190  
 191          // Setup variables.
 192          $this->pag_arg      = sanitize_key( $r['page_arg'] );
 193          $this->pag_page     = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] );
 194          $this->pag_num      = bp_sanitize_pagination_arg( 'num', $r['per_page'] );
 195          $this->sort_order   = bp_esc_sql_order( $r['sort_order'] );
 196          $this->user_id      = $r['user_id'];
 197          $this->search_terms = $r['search_terms'];
 198          $this->order_by     = $r['order_by'];
 199          $this->query_vars   = array(
 200              'id'            => $r['id'],
 201              'user_id'       => $r['user_id'],
 202              'inviter_id'    => $r['inviter_id'],
 203              'invitee_email' => $r['invitee_email'],
 204              'item_id'       => $r['item_id'],
 205              'type'          => $r['type'],
 206              'invite_sent'   => $r['invite_sent'],
 207              'accepted'      => $r['accepted'],
 208              'search_terms'  => $this->search_terms,
 209              'order_by'      => $this->order_by,
 210              'sort_order'    => $this->sort_order,
 211              'page'          => $this->pag_page,
 212              'per_page'      => $this->pag_num,
 213          );
 214  
 215          // Setup the invitations to loop through.
 216          $invites_class = new BP_Members_Invitation_Manager();
 217  
 218          $this->invitations              = $invites_class->get_invitations( $this->query_vars );
 219          $this->current_invitation_count = count( $this->invitations );
 220          $this->total_invitation_count   = $invites_class->get_invitations_total_count( $this->query_vars );
 221  
 222          if ( (int) $this->total_invitation_count && (int) $this->pag_num ) {
 223              $add_args = array(
 224                  'sort_order' => $this->sort_order,
 225              );
 226  
 227              $this->pag_links = paginate_links(
 228                  array(
 229                      'base'      => add_query_arg( $this->pag_arg, '%#%' ),
 230                      'format'    => '',
 231                      'total'     => ceil( (int) $this->total_invitation_count / (int) $this->pag_num ),
 232                      'current'   => $this->pag_page,
 233                      'prev_text' => _x( '&larr;', 'Network invitation pagination previous text', 'buddypress' ),
 234                      'next_text' => _x( '&rarr;', 'Network invitation pagination next text', 'buddypress' ),
 235                      'mid_size'  => 1,
 236                      'add_args'  => $add_args,
 237                  )
 238              );
 239          }
 240      }
 241  
 242      /**
 243       * Whether there are invitations available in the loop.
 244       *
 245       * @since 8.0.0
 246       *
 247       * @see bp_has_members_invitations()
 248       *
 249       * @return bool True if there are items in the loop, otherwise false.
 250       */
 251  	public function has_invitations() {
 252          return ! empty( $this->current_invitation_count );
 253      }
 254  
 255      /**
 256       * Set up the next invitation and iterate index.
 257       *
 258       * @since 8.0.0
 259       *
 260       * @return object The next invitation to iterate over.
 261       */
 262  	public function next_invitation() {
 263  
 264          $this->current_invitation++;
 265  
 266          $this->invitation = $this->invitations[ $this->current_invitation ];
 267  
 268          return $this->invitation;
 269      }
 270  
 271      /**
 272       * Rewind the blogs and reset blog index.
 273       *
 274       * @since 8.0.0
 275       */
 276  	public function rewind_invitations() {
 277  
 278          $this->current_invitation = -1;
 279  
 280          if ( $this->current_invitation_count > 0 ) {
 281              $this->invitation = $this->invitations[0];
 282          }
 283      }
 284  
 285      /**
 286       * Whether there are invitations left in the loop to iterate over.
 287       *
 288       * This method is used by {@link bp_members_invitations()} as part of the
 289       * while loop that controls iteration inside the invitations loop, eg:
 290       *     while ( bp_members_invitations() ) { ...
 291       *
 292       * @since 8.0.0
 293       *
 294       * @see bp_members_invitations()
 295       *
 296       * @return bool True if there are more invitations to show,
 297       *              otherwise false.
 298       */
 299  	public function invitations() {
 300  
 301          if ( $this->current_invitation + 1 < $this->current_invitation_count ) {
 302              return true;
 303  
 304          } elseif ( $this->current_invitation + 1 === $this->current_invitation_count ) {
 305  
 306              /**
 307               * Fires right before the rewinding of invitation posts.
 308               *
 309               * @since 8.0.0
 310               */
 311              do_action( 'members_invitations_loop_end' );
 312  
 313              $this->rewind_invitations();
 314          }
 315  
 316          $this->in_the_loop = false;
 317          return false;
 318      }
 319  
 320      /**
 321       * Set up the current invitation inside the loop.
 322       *
 323       * Used by {@link bp_the_invitation()} to set up the current
 324       * invitation data while looping, so that template tags used during
 325       * that iteration make reference to the current invitation.
 326       *
 327       * @since 8.0.0
 328       *
 329       * @see bp_the_invitation()
 330       */
 331  	public function the_invitation() {
 332          $this->in_the_loop = true;
 333          $this->invitation  = $this->next_invitation();
 334  
 335          // Loop has just started.
 336          if ( 0 === $this->current_invitation ) {
 337  
 338              /**
 339               * Fires if the current invitation item is the first in the invitation loop.
 340               *
 341               * @since 8.0.0
 342               */
 343              do_action( 'members_invitations_loop_start' );
 344          }
 345      }
 346  }


Generated: Wed May 18 01:00:56 2022 Cross-referenced by PHPXref 0.7.1