[ 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 MessagesClasses
   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          return ( ! empty( $this->message_count ) );
 104      }
 105  
 106      /**
 107       * Set up the next message and iterate index.
 108       *
 109       * @return BP_Messages_Message The next message to iterate over.
 110       */
 111  	public function next_message() {
 112          $this->current_message++;
 113          $this->message = $this->thread->messages[ $this->current_message ];
 114  
 115          return $this->message;
 116      }
 117  
 118      /**
 119       * Rewind the messages and reset message index.
 120       */
 121  	public function rewind_messages() {
 122          $this->current_message = -1;
 123          if ( $this->message_count > 0 ) {
 124              $this->message = $this->thread->messages[0];
 125          }
 126      }
 127  
 128      /**
 129       * Whether there are messages left in the loop to iterate over.
 130       *
 131       * This method is used by {@link bp_thread_messages()} as part of the
 132       * while loop that controls iteration inside the messages loop, eg:
 133       *     while ( bp_thread_messages() ) { ...
 134       *
 135       * @see bp_thread_messages()
 136       *
 137       * @return bool True if there are more messages to show, otherwise false.
 138       */
 139  	public function messages() {
 140          if ( ( $this->current_message + 1 ) < $this->message_count ) {
 141              return true;
 142          } elseif ( ( $this->current_message + 1 ) === $this->message_count ) {
 143  
 144              /**
 145               * Fires when at the end of messages to iterate over.
 146               *
 147               * @since 1.1.0
 148               */
 149              do_action( 'thread_loop_end' );
 150              // Do some cleaning up after the loop.
 151              $this->rewind_messages();
 152          }
 153  
 154          $this->in_the_loop = false;
 155          return false;
 156      }
 157  
 158      /**
 159       * Set up the current message inside the loop.
 160       *
 161       * Used by {@link bp_thread_the_message()} to set up the current
 162       * message data while looping, so that template tags used during
 163       * that iteration make reference to the current message.
 164       *
 165       * @see bp_thread_the_message()
 166       */
 167  	public function the_message() {
 168          $this->in_the_loop = true;
 169          $this->message     = $this->next_message();
 170  
 171          // Loop has just started.
 172          if ( 0 === $this->current_message ) {
 173  
 174              /**
 175               * Fires if at the start of the message loop.
 176               *
 177               * @since 1.1.0
 178               */
 179              do_action( 'thread_loop_start' );
 180          }
 181      }
 182  }


Generated: Sat Oct 16 01:00:56 2021 Cross-referenced by PHPXref 0.7.1