[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/classes/ -> class-bp-groups-invite-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Groups Invitation template loop class.
   4   *
   5   * @package BuddyPress
   6   * @since 1.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Group invitation template loop class.
  14   *
  15   * @since 1.1.0
  16   */
  17  class BP_Groups_Invite_Template {
  18  
  19      /**
  20       * @since 1.1.0
  21       * @var int
  22       */
  23      public $current_invite = -1;
  24  
  25      /**
  26       * @since 1.1.0
  27       * @var int
  28       */
  29      public $invite_count;
  30  
  31      /**
  32       * @since 1.1.0
  33       * @var array
  34       */
  35      public $invites;
  36  
  37      /**
  38       * @since 1.1.0
  39       * @var object
  40       */
  41      public $invite;
  42  
  43      /**
  44       * @since 1.1.0
  45       * @var bool
  46       */
  47      public $in_the_loop;
  48  
  49      /**
  50       * @since 1.1.0
  51       * @var int
  52       */
  53      public $pag_page;
  54  
  55      /**
  56       * @since 1.1.0
  57       * @var int
  58       */
  59      public $pag_num;
  60  
  61      /**
  62       * @since 1.1.0
  63       * @var string
  64       */
  65      public $pag_links;
  66  
  67      /**
  68       * @since 1.1.0
  69       * @var int
  70       */
  71      public $total_invite_count;
  72  
  73      /**
  74       * BP_Groups_Invite_Template constructor.
  75       *
  76       * @since 1.5.0
  77       *
  78       * @param array $args
  79       */
  80  	public function __construct( $args = array() ) {
  81          $function_args = func_get_args();
  82  
  83          // Backward compatibility with old method of passing arguments.
  84          if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
  85              _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__ ) );
  86  
  87              $old_args_keys = array(
  88                  0  => 'user_id',
  89                  1  => 'group_id',
  90              );
  91  
  92              $args = bp_core_parse_args_array( $old_args_keys, $function_args );
  93          }
  94  
  95          $r = bp_parse_args( $args, array(
  96              'page'     => 1,
  97              'per_page' => 10,
  98              'page_arg' => 'invitepage',
  99              'user_id'  => bp_loggedin_user_id(),
 100              'group_id' => bp_get_current_group_id(),
 101          ), 'groups_invite_template' );
 102  
 103          $this->pag_arg  = sanitize_key( $r['page_arg'] );
 104          $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
 105          $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
 106  
 107          $iquery = new BP_Group_Member_Query( array(
 108              'group_id' => $r['group_id'],
 109              'type'     => 'first_joined',
 110              'per_page' => $this->pag_num,
 111              'page'     => $this->pag_page,
 112  
 113              // These filters ensure we get only pending invites.
 114              'is_confirmed' => false,
 115              'inviter_id'   => $r['user_id'],
 116          ) );
 117  
 118          $this->invite_data        = $iquery->results;
 119          $this->total_invite_count = $iquery->total_users;
 120          $this->invites            = array_values( wp_list_pluck( $this->invite_data, 'ID' ) );
 121          $this->invite_count       = count( $this->invites );
 122  
 123          // If per_page is set to 0 (show all results), don't generate
 124          // pag_links.
 125          if ( ! empty( $this->pag_num ) ) {
 126              $this->pag_links = paginate_links( array(
 127                  'base'      => add_query_arg( $this->pag_arg, '%#%' ),
 128                  'format'    => '',
 129                  'total'     => ceil( $this->total_invite_count / $this->pag_num ),
 130                  'current'   => $this->pag_page,
 131                  'prev_text' => '&larr;',
 132                  'next_text' => '&rarr;',
 133                  'mid_size'  => 1,
 134                  'add_args'  => array(),
 135              ) );
 136          } else {
 137              $this->pag_links = '';
 138          }
 139      }
 140  
 141      /**
 142       * Whether or not there are invites to show.
 143       *
 144       * @since 1.1.0
 145       *
 146       * @return bool
 147       */
 148  	public function has_invites() {
 149          if ( ! empty( $this->invite_count ) ) {
 150              return true;
 151          }
 152  
 153          return false;
 154      }
 155  
 156      /**
 157       * Increments up to the next invite to show.
 158       *
 159       * @since 1.1.0
 160       *
 161       * @return object
 162       */
 163  	public function next_invite() {
 164          $this->current_invite++;
 165          $this->invite = $this->invites[ $this->current_invite ];
 166  
 167          return $this->invite;
 168      }
 169  
 170      /**
 171       * Rewinds to the first invite to show.
 172       *
 173       * @since 1.1.0
 174       */
 175  	public function rewind_invites() {
 176          $this->current_invite = -1;
 177          if ( $this->invite_count > 0 ) {
 178              $this->invite = $this->invites[0];
 179          }
 180      }
 181  
 182      /**
 183       * Finishes up the invites to show.
 184       *
 185       * @since 1.1.0
 186       *
 187       * @return bool
 188       */
 189  	public function invites() {
 190          $tick = intval( $this->current_invite + 1 );
 191          if ( $tick < $this->invite_count ) {
 192              return true;
 193          } elseif ( $tick == $this->invite_count ) {
 194  
 195              /**
 196               * Fires right before the rewinding of invites list.
 197               *
 198               * @since 1.1.0
 199               * @since 2.3.0 `$this` parameter added.
 200               * @since 2.7.0 Action renamed from `loop_start`.
 201               *
 202               * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
 203               */
 204              do_action( 'group_invitation_loop_end', $this );
 205  
 206              // Do some cleaning up after the loop
 207              $this->rewind_invites();
 208          }
 209  
 210          $this->in_the_loop = false;
 211          return false;
 212      }
 213  
 214      /**
 215       * Sets up the invite to show.
 216       *
 217       * @since 1.1.0
 218       */
 219  	public function the_invite() {
 220          global $group_id;
 221  
 222          $this->in_the_loop  = true;
 223          $user_id            = $this->next_invite();
 224  
 225          $this->invite       = new stdClass;
 226          $this->invite->user = $this->invite_data[ $user_id ];
 227  
 228          // This method previously populated the user object with
 229          // BP_Core_User. We manually configure BP_Core_User data for
 230          // backward compatibility.
 231          if ( bp_is_active( 'xprofile' ) ) {
 232              $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
 233          }
 234  
 235          $this->invite->user->avatar       = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full',  'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
 236          $this->invite->user->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
 237          $this->invite->user->avatar_mini  = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ), 'width' => 30, 'height' => 30 ) );
 238          $this->invite->user->email        = $this->invite->user->user_email;
 239          $this->invite->user->user_url     = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login );
 240          $this->invite->user->user_link    = "<a href='{$this->invite->user->user_url}'>{$this->invite->user->fullname}</a>";
 241          $this->invite->user->last_active  = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) );
 242  
 243          if ( bp_is_active( 'groups' ) ) {
 244              $total_groups = BP_Groups_Member::total_group_count( $user_id );
 245              $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups );
 246          }
 247  
 248          if ( bp_is_active( 'friends' ) ) {
 249              $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
 250          }
 251  
 252          $this->invite->user->total_blogs = null;
 253  
 254          // Global'ed in bp_group_has_invites()
 255          $this->invite->group_id = $group_id;
 256  
 257          // loop has just started
 258          if ( 0 == $this->current_invite ) {
 259  
 260              /**
 261               * Fires if the current invite item is the first in the loop.
 262               *
 263               * @since 1.1.0
 264               * @since 2.3.0 `$this` parameter added.
 265               * @since 2.7.0 Action renamed from `loop_start`.
 266               *
 267               * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
 268               */
 269              do_action( 'group_invitation_loop_start', $this );
 270          }
 271      }
 272  }


Generated: Fri Oct 18 01:01:36 2019 Cross-referenced by PHPXref 0.7.1