[ 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  
  82          // Backward compatibility with old method of passing arguments.
  83          if ( ! is_array( $args ) || func_num_args() > 1 ) {
  84              _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__ ) );
  85  
  86              $old_args_keys = array(
  87                  0  => 'user_id',
  88                  1  => 'group_id',
  89              );
  90  
  91              $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
  92          }
  93  
  94          $r = bp_parse_args( $args, array(
  95              'page'     => 1,
  96              'per_page' => 10,
  97              'page_arg' => 'invitepage',
  98              'user_id'  => bp_loggedin_user_id(),
  99              'group_id' => bp_get_current_group_id(),
 100          ), 'groups_invite_template' );
 101  
 102          $this->pag_arg  = sanitize_key( $r['page_arg'] );
 103          $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
 104          $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
 105  
 106          $iquery = new BP_Group_Member_Query( array(
 107              'group_id' => $r['group_id'],
 108              'type'     => 'first_joined',
 109              'per_page' => $this->pag_num,
 110              'page'     => $this->pag_page,
 111  
 112              // These filters ensure we get only pending invites.
 113              'is_confirmed' => false,
 114              'inviter_id'   => $r['user_id'],
 115          ) );
 116  
 117          $this->invite_data        = $iquery->results;
 118          $this->total_invite_count = $iquery->total_users;
 119          $this->invites            = array_values( wp_list_pluck( $this->invite_data, 'ID' ) );
 120          $this->invite_count       = count( $this->invites );
 121  
 122          // If per_page is set to 0 (show all results), don't generate
 123          // pag_links.
 124          if ( ! empty( $this->pag_num ) ) {
 125              $this->pag_links = paginate_links( array(
 126                  'base'      => add_query_arg( $this->pag_arg, '%#%' ),
 127                  'format'    => '',
 128                  'total'     => ceil( $this->total_invite_count / $this->pag_num ),
 129                  'current'   => $this->pag_page,
 130                  'prev_text' => '&larr;',
 131                  'next_text' => '&rarr;',
 132                  'mid_size'  => 1,
 133                  'add_args'  => array(),
 134              ) );
 135          } else {
 136              $this->pag_links = '';
 137          }
 138      }
 139  
 140      /**
 141       * Whether or not there are invites to show.
 142       *
 143       * @since 1.1.0
 144       *
 145       * @return bool
 146       */
 147  	public function has_invites() {
 148          if ( ! empty( $this->invite_count ) ) {
 149              return true;
 150          }
 151  
 152          return false;
 153      }
 154  
 155      /**
 156       * Increments up to the next invite to show.
 157       *
 158       * @since 1.1.0
 159       *
 160       * @return object
 161       */
 162  	public function next_invite() {
 163          $this->current_invite++;
 164          $this->invite = $this->invites[ $this->current_invite ];
 165  
 166          return $this->invite;
 167      }
 168  
 169      /**
 170       * Rewinds to the first invite to show.
 171       *
 172       * @since 1.1.0
 173       */
 174  	public function rewind_invites() {
 175          $this->current_invite = -1;
 176          if ( $this->invite_count > 0 ) {
 177              $this->invite = $this->invites[0];
 178          }
 179      }
 180  
 181      /**
 182       * Finishes up the invites to show.
 183       *
 184       * @since 1.1.0
 185       *
 186       * @return bool
 187       */
 188  	public function invites() {
 189          $tick = intval( $this->current_invite + 1 );
 190          if ( $tick < $this->invite_count ) {
 191              return true;
 192          } elseif ( $tick == $this->invite_count ) {
 193  
 194              /**
 195               * Fires right before the rewinding of invites list.
 196               *
 197               * @since 1.1.0
 198               * @since 2.3.0 `$this` parameter added.
 199               * @since 2.7.0 Action renamed from `loop_start`.
 200               *
 201               * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
 202               */
 203              do_action( 'group_invitation_loop_end', $this );
 204  
 205              // Do some cleaning up after the loop
 206              $this->rewind_invites();
 207          }
 208  
 209          $this->in_the_loop = false;
 210          return false;
 211      }
 212  
 213      /**
 214       * Sets up the invite to show.
 215       *
 216       * @since 1.1.0
 217       */
 218  	public function the_invite() {
 219          global $group_id;
 220  
 221          $this->in_the_loop  = true;
 222          $user_id            = $this->next_invite();
 223  
 224          $this->invite       = new stdClass;
 225          $this->invite->user = $this->invite_data[ $user_id ];
 226  
 227          // This method previously populated the user object with
 228          // BP_Core_User. We manually configure BP_Core_User data for
 229          // backward compatibility.
 230          if ( bp_is_active( 'xprofile' ) ) {
 231              $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
 232          }
 233  
 234          $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 ) ) );
 235          $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 ) ) );
 236          $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 ) );
 237          $this->invite->user->email        = $this->invite->user->user_email;
 238          $this->invite->user->user_url     = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login );
 239          $this->invite->user->user_link    = "<a href='{$this->invite->user->user_url}'>{$this->invite->user->fullname}</a>";
 240          $this->invite->user->last_active  = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) );
 241  
 242          if ( bp_is_active( 'groups' ) ) {
 243              $total_groups = BP_Groups_Member::total_group_count( $user_id );
 244              $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups );
 245          }
 246  
 247          if ( bp_is_active( 'friends' ) ) {
 248              $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
 249          }
 250  
 251          $this->invite->user->total_blogs = null;
 252  
 253          // Global'ed in bp_group_has_invites()
 254          $this->invite->group_id = $group_id;
 255  
 256          // loop has just started
 257          if ( 0 == $this->current_invite ) {
 258  
 259              /**
 260               * Fires if the current invite item is the first in the loop.
 261               *
 262               * @since 1.1.0
 263               * @since 2.3.0 `$this` parameter added.
 264               * @since 2.7.0 Action renamed from `loop_start`.
 265               *
 266               * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
 267               */
 268              do_action( 'group_invitation_loop_start', $this );
 269          }
 270      }
 271  }


Generated: Wed Jul 24 01:01:43 2019 Cross-referenced by PHPXref 0.7.1