BP_Messages_Thread_Template

Message Thread Template Class.

Defined (1)

The class is defined in the following location(s).

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