[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/classes/ -> class-bp-messages-thread-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Messages Thread Template Class.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MessagesTemplate
   7   * @since 1.5.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Message Thread Template Class
  15   */
  16  class BP_Messages_Thread_Template {
  17  
  18      /**
  19       * The loop iterator.
  20       *
  21       * @var int
  22       */
  23      public $current_message = -1;
  24  
  25      /**
  26       * Number of messages returned by the paged query.
  27       *
  28       * @var int
  29       */
  30      public $message_count = 0;
  31  
  32      /**
  33       * The message object currently being iterated on.
  34       *
  35       * @var object
  36       */
  37      public $message;
  38  
  39      /**
  40       * Thread that the current messages belong to.
  41       *
  42       * @var BP_Messages_Thread
  43       */
  44      public $thread;
  45  
  46      /**
  47       * A flag for whether the loop is currently being iterated.
  48       *
  49       * @var bool
  50       */
  51      public $in_the_loop = false;
  52  
  53      /**
  54       * The page number being requested.
  55       *
  56       * @var int
  57       */
  58      public $pag_page = 1;
  59  
  60      /**
  61       * The number of items being requested per page.
  62       *
  63       * @var int
  64       */
  65      public $pag_num = 10;
  66  
  67      /**
  68       * An HTML string containing pagination links.
  69       *
  70       * @var string
  71       */
  72      public $pag_links = '';
  73  
  74      /**
  75       * The total number of messages matching the query.
  76       *
  77       * @var int
  78       */
  79      public $total_message_count = 0;
  80  
  81      /**
  82       * Constructor method.
  83       *
  84       * @see BP_Messages_Thread::populate() for full parameter info.
  85       *
  86       * @param int    $thread_id ID of the message thread to display.
  87       * @param string $order     Order to show the thread's messages in.
  88       * @param array  $args      Array of arguments for the query.
  89       */
  90  	public function __construct( $thread_id = 0, $order = 'ASC', $args = array() ) {
  91          $this->thread        = new BP_Messages_Thread( $thread_id, $order, $args );
  92          $this->message_count = count( $this->thread->messages );
  93      }
  94  
  95      /**
  96       * Whether there are messages available in the loop.
  97       *
  98       * @see bp_thread_has_messages()
  99       *
 100       * @return bool True if there are items in the loop, otherwise false.
 101       */
 102  	public function has_messages() {
 103          if ( ! empty( $this->message_count ) ) {
 104              return true;
 105          }
 106  
 107          return false;
 108      }
 109  
 110      /**
 111       * Set up the next member and iterate index.
 112       *
 113       * @return object The next member to iterate over.
 114       */
 115  	public function next_message() {
 116          $this->current_message++;
 117          $this->message = $this->thread->messages[ $this->current_message ];
 118  
 119          return $this->message;
 120      }
 121  
 122      /**
 123       * Rewind the messages and reset message index.
 124       */
 125  	public function rewind_messages() {
 126          $this->current_message = -1;
 127          if ( $this->message_count > 0 ) {
 128              $this->message = $this->thread->messages[0];
 129          }
 130      }
 131  
 132      /**
 133       * Whether there are messages left in the loop to iterate over.
 134       *
 135       * This method is used by {@link bp_thread_messages()} as part of the
 136       * while loop that controls iteration inside the messages loop, eg:
 137       *     while ( bp_thread_messages() ) { ...
 138       *
 139       * @see bp_thread_messages()
 140       *
 141       * @return bool True if there are more messages to show, otherwise false.
 142       */
 143  	public function messages() {
 144          if ( ( $this->current_message + 1 ) < $this->message_count ) {
 145              return true;
 146          } elseif ( ( $this->current_message + 1 ) === $this->message_count ) {
 147  
 148              /**
 149               * Fires when at the end of messages to iterate over.
 150               *
 151               * @since 1.1.0
 152               */
 153              do_action( 'thread_loop_end' );
 154              // Do some cleaning up after the loop.
 155              $this->rewind_messages();
 156          }
 157  
 158          $this->in_the_loop = false;
 159          return false;
 160      }
 161  
 162      /**
 163       * Set up the current message inside the loop.
 164       *
 165       * Used by {@link bp_thread_the_message()} to set up the current
 166       * message data while looping, so that template tags used during
 167       * that iteration make reference to the current message.
 168       *
 169       * @see bp_thread_the_message()
 170       */
 171  	public function the_message() {
 172          $this->in_the_loop = true;
 173          $this->message     = $this->next_message();
 174  
 175          // Loop has just started.
 176          if ( 0 === $this->current_message ) {
 177  
 178              /**
 179               * Fires if at the start of the message loop.
 180               *
 181               * @since 1.1.0
 182               */
 183              do_action( 'thread_loop_start' );
 184          }
 185      }
 186  }


Generated: Sat Dec 14 01:01:40 2019 Cross-referenced by PHPXref 0.7.1