[ 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          $orders = array( 'ASC', 'DESC' );
 188          if ( ! empty( $_GET['sort_order'] ) && in_array( $_GET['sort_order'], $orders ) ) {
 189              $r['sort_order'] = $_GET['sort_order'];
 190          } else {
 191              $r['sort_order'] = in_array( $r['sort_order'], $orders ) ? $r['sort_order'] : 'DESC';
 192          }
 193  
 194          // Setup variables.
 195          $this->pag_arg      = sanitize_key( $r['page_arg'] );
 196          $this->pag_page     = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] );
 197          $this->pag_num      = bp_sanitize_pagination_arg( 'num', $r['per_page'] );
 198          $this->user_id      = $r['user_id'];
 199          $this->search_terms = $r['search_terms'];
 200          $this->order_by     = $r['order_by'];
 201          $this->sort_order   = $r['sort_order'];
 202          $this->query_vars   = array(
 203              'id'            => $r['id'],
 204              'user_id'       => $r['user_id'],
 205              'inviter_id'    => $r['inviter_id'],
 206              'invitee_email' => $r['invitee_email'],
 207              'item_id'       => $r['item_id'],
 208              'type'          => $r['type'],
 209              'invite_sent'   => $r['invite_sent'],
 210              'accepted'      => $r['accepted'],
 211              'search_terms'  => $this->search_terms,
 212              'order_by'      => $this->order_by,
 213              'sort_order'    => $this->sort_order,
 214              'page'          => $this->pag_page,
 215              'per_page'      => $this->pag_num,
 216          );
 217  
 218          // Setup the invitations to loop through.
 219          $invites_class = new BP_Members_Invitation_Manager();
 220  
 221          $this->invitations              = $invites_class->get_invitations( $this->query_vars );
 222          $this->current_invitation_count = count( $this->invitations );
 223          $this->total_invitation_count   = $invites_class->get_invitations_total_count( $this->query_vars );
 224  
 225          if ( (int) $this->total_invitation_count && (int) $this->pag_num ) {
 226              $add_args = array(
 227                  'sort_order' => $this->sort_order,
 228              );
 229  
 230              $this->pag_links = paginate_links(
 231                  array(
 232                      'base'      => add_query_arg( $this->pag_arg, '%#%' ),
 233                      'format'    => '',
 234                      'total'     => ceil( (int) $this->total_invitation_count / (int) $this->pag_num ),
 235                      'current'   => $this->pag_page,
 236                      'prev_text' => _x( '&larr;', 'Network invitation pagination previous text', 'buddypress' ),
 237                      'next_text' => _x( '&rarr;', 'Network invitation pagination next text', 'buddypress' ),
 238                      'mid_size'  => 1,
 239                      'add_args'  => $add_args,
 240                  )
 241              );
 242          }
 243      }
 244  
 245      /**
 246       * Whether there are invitations available in the loop.
 247       *
 248       * @since 8.0.0
 249       *
 250       * @see bp_has_members_invitations()
 251       *
 252       * @return bool True if there are items in the loop, otherwise false.
 253       */
 254  	public function has_invitations() {
 255          if ( $this->current_invitation_count ) {
 256              return true;
 257          }
 258  
 259          return false;
 260      }
 261  
 262      /**
 263       * Set up the next invitation and iterate index.
 264       *
 265       * @since 8.0.0
 266       *
 267       * @return object The next invitation to iterate over.
 268       */
 269  	public function next_invitation() {
 270  
 271          $this->current_invitation++;
 272  
 273          $this->invitation = $this->invitations[ $this->current_invitation ];
 274  
 275          return $this->invitation;
 276      }
 277  
 278      /**
 279       * Rewind the blogs and reset blog index.
 280       *
 281       * @since 8.0.0
 282       */
 283  	public function rewind_invitations() {
 284  
 285          $this->current_invitation = -1;
 286  
 287          if ( $this->current_invitation_count > 0 ) {
 288              $this->invitation = $this->invitations[0];
 289          }
 290      }
 291  
 292      /**
 293       * Whether there are invitations left in the loop to iterate over.
 294       *
 295       * This method is used by {@link bp_members_invitations()} as part of the
 296       * while loop that controls iteration inside the invitations loop, eg:
 297       *     while ( bp_members_invitations() ) { ...
 298       *
 299       * @since 8.0.0
 300       *
 301       * @see bp_members_invitations()
 302       *
 303       * @return bool True if there are more invitations to show,
 304       *              otherwise false.
 305       */
 306  	public function invitations() {
 307  
 308          if ( $this->current_invitation + 1 < $this->current_invitation_count ) {
 309              return true;
 310  
 311          } elseif ( $this->current_invitation + 1 === $this->current_invitation_count ) {
 312  
 313              /**
 314               * Fires right before the rewinding of invitation posts.
 315               *
 316               * @since 8.0.0
 317               */
 318              do_action( 'members_invitations_loop_end' );
 319  
 320              $this->rewind_invitations();
 321          }
 322  
 323          $this->in_the_loop = false;
 324          return false;
 325      }
 326  
 327      /**
 328       * Set up the current invitation inside the loop.
 329       *
 330       * Used by {@link bp_the_invitation()} to set up the current
 331       * invitation data while looping, so that template tags used during
 332       * that iteration make reference to the current invitation.
 333       *
 334       * @since 8.0.0
 335       *
 336       * @see bp_the_invitation()
 337       */
 338  	public function the_invitation() {
 339          $this->in_the_loop = true;
 340          $this->invitation  = $this->next_invitation();
 341  
 342          // Loop has just started.
 343          if ( 0 === $this->current_invitation ) {
 344  
 345              /**
 346               * Fires if the current invitation item is the first in the invitation loop.
 347               *
 348               * @since 8.0.0
 349               */
 350              do_action( 'members_invitations_loop_start' );
 351          }
 352      }
 353  }


Generated: Sun Sep 19 01:01:40 2021 Cross-referenced by PHPXref 0.7.1