- Timestamp:
- 10/22/2015 06:12:16 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/classes/class-bp-messages-thread.php
r10139 r10304 112 112 * @see BP_Messages_Thread::populate() for full description of parameters. 113 113 * 114 * @param bool $thread_id 115 * @param string $order 116 * @param array $args 114 * @param bool $thread_id ID for the message thread. 115 * @param string $order Order to display the messages in. 116 * @param array $args Array of arguments for thread querying. 117 117 */ 118 118 public function __construct( $thread_id = false, $order = 'ASC', $args = array() ) { … … 131 131 * @param int $thread_id The message thread ID. 132 132 * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'. 133 * @param array $args {133 * @param array $args { 134 134 * Array of arguments. 135 135 * @type bool $update_meta_cache Whether to pre-fetch metadata for … … 144 144 } 145 145 146 // merge $args with our defaults146 // Merge $args with our defaults. 147 147 $r = wp_parse_args( $args, array( 148 148 'user_id' => bp_loggedin_user_id(), … … 153 153 $this->thread_id = (int) $thread_id; 154 154 155 // get messages for thread155 // Get messages for thread. 156 156 $this->messages = self::get_messages( $this->thread_id ); 157 157 … … 160 160 } 161 161 162 // flip if order is DESC162 // Flip if order is DESC. 163 163 if ( 'DESC' === $order ) { 164 164 $this->messages = array_reverse( $this->messages ); … … 176 176 } 177 177 178 // Fetch the recipients 178 // Fetch the recipients. 179 179 $this->recipients = $this->get_recipients(); 180 180 181 // Get the unread count for the logged in user 181 // Get the unread count for the logged in user. 182 182 if ( isset( $this->recipients[ $r['user_id'] ] ) ) { 183 183 $this->unread_count = $this->recipients[ $r['user_id'] ]->unread_count; 184 184 } 185 185 186 // Grab all message meta 186 // Grab all message meta. 187 187 if ( true === (bool) $r['update_meta_cache'] ) { 188 188 bp_messages_update_meta_cache( wp_list_pluck( $this->messages, 'id' ) ); … … 228 228 * 229 229 * @param int $thread_id The thread ID. 230 *231 230 * @return array 232 231 */ … … 275 274 * @param int $thread_id The message thread ID. 276 275 * 277 * @return array276 * @return object List of messages associated with a thread. 278 277 */ 279 278 public static function get_messages( $thread_id = 0 ) { … … 286 285 $bp = buddypress(); 287 286 288 // always sort by ASC by default287 // Always sort by ASC by default. 289 288 $messages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE thread_id = %d ORDER BY date_sent ASC", $thread_id ) ); 290 289 … … 300 299 * @since 2.3.0 301 300 * 302 * @param int $thread_id The thread ID. 303 * 301 * @param int $thread_id The thread ID. 304 302 * @return array 305 303 */ … … 318 316 * 319 317 * @param int $thread_id The message thread ID. 320 *321 318 * @return bool 322 319 */ … … 340 337 // 341 338 // @todo the reliance on bp_loggedin_user_id() sucks for plugins 342 // refactor this method to accept a $user_id parameter339 // refactor this method to accept a $user_id parameter. 343 340 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, bp_loggedin_user_id() ) ); 344 341 345 // Get the message ids in order to pass to the action 342 // Get the message ids in order to pass to the action. 346 343 $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 347 344 348 // Check to see if any more recipients remain for this message 345 // Check to see if any more recipients remain for this message. 349 346 $recipients = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0", $thread_id ) ); 350 347 351 // No more recipients so delete all messages associated with the thread 348 // No more recipients so delete all messages associated with the thread. 352 349 if ( empty( $recipients ) ) { 353 350 … … 362 359 do_action( 'bp_messages_thread_before_delete', $thread_id, $message_ids ); 363 360 364 // Delete all the messages 361 // Delete all the messages. 365 362 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 366 363 367 // Do something for each message ID 364 // Do something for each message ID. 368 365 foreach ( $message_ids as $message_id ) { 369 366 370 // Delete message meta 367 // Delete message meta. 371 368 bp_messages_delete_meta( $message_id ); 372 369 … … 381 378 } 382 379 383 // Delete all the recipients 380 // Delete all the recipients. 384 381 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) ); 385 382 } … … 420 417 global $wpdb; 421 418 422 // Backward compatibility with old method of passing arguments 419 // Backward compatibility with old method of passing arguments. 423 420 if ( ! is_array( $args ) || func_num_args() > 1 ) { 424 421 _deprecated_argument( __METHOD__, '2.2.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__ ) ); … … 470 467 $r['user_id'] = (int) $r['user_id']; 471 468 472 // Default deleted SQL 469 // Default deleted SQL. 473 470 $deleted_sql = 'r.is_deleted = 0'; 474 471 … … 485 482 486 483 default : 487 // Omit user-deleted threads from all other custom message boxes 484 // Omit user-deleted threads from all other custom message boxes. 488 485 $deleted_sql = $wpdb->prepare( '( r.user_id = %d AND r.is_deleted = 0 )', $r['user_id'] ); 489 486 break; 490 487 } 491 488 492 // Process meta query into SQL 489 // Process meta query into SQL. 493 490 $meta_query = self::get_meta_query_sql( $r['meta_query'] ); 494 491 if ( ! empty( $meta_query['join'] ) ) { … … 501 498 $bp = buddypress(); 502 499 503 // set up SQL array500 // Set up SQL array. 504 501 $sql = array(); 505 502 $sql['select'] = 'SELECT m.thread_id, MAX(m.date_sent) AS date_sent'; … … 508 505 $sql['misc'] = "GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}"; 509 506 510 // get thread IDs507 // Get thread IDs. 511 508 $thread_ids = $wpdb->get_results( implode( ' ', $sql ) ); 512 509 if ( empty( $thread_ids ) ) { … … 514 511 } 515 512 516 // adjust $sql to work for thread total513 // Adjust $sql to work for thread total. 517 514 $sql['select'] = 'SELECT COUNT( DISTINCT m.thread_id )'; 518 515 unset( $sql['misc'] ); 519 516 $total_threads = $wpdb->get_var( implode( ' ', $sql ) ); 520 517 521 // Sort threads by date_sent 518 // Sort threads by date_sent. 522 519 foreach( (array) $thread_ids as $thread ) { 523 520 $sorted_threads[ $thread->thread_id ] = strtotime( $thread->date_sent ); … … 559 556 * @param array $meta_query An array of meta_query filters. See the 560 557 * documentation for WP_Meta_Query for details. 561 *562 558 * @return array $sql_array 'join' and 'where' clauses. 563 559 */ … … 574 570 575 571 // WP_Meta_Query expects the table name at 576 // $wpdb->messagemeta 572 // $wpdb->messagemeta. 577 573 $wpdb->messagemeta = buddypress()->messages->table_name_meta; 578 574 … … 629 625 * @param string $type The type of messages to get. Either 'all' or 'unread'. 630 626 * or 'read'. Defaults to 'all'. 631 * @return int 627 * @return int $value Total thread count for the provided user. 632 628 */ 633 629 public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) { … … 656 652 * 657 653 * @param int $thread_id The message thread ID. 658 *659 654 * @return bool 660 655 */ … … 679 674 * 680 675 * @param int $thread_id The message thread ID. 681 *682 676 * @return string|bool The user link on success. Boolean false on failure. 683 677 */ … … 700 694 * 701 695 * @param int $user_id The user ID. 702 * 703 * @return int 696 * @return int $unread_count Total inbox unread count for user. 704 697 */ 705 698 public static function get_inbox_count( $user_id = 0 ) { … … 738 731 * @param int $thread_id The message thread ID. 739 732 * @param int $user_id The user ID. 740 *741 733 * @return int|null The recorded recipient ID on success, null on failure. 742 734 */ … … 762 754 * 763 755 * @param int $thread_id The message thread ID. 764 *765 756 * @return int|null The message thread ID on success, null on failure. 766 757 */ 767 758 public static function is_valid( $thread_id = 0 ) { 768 759 769 // Bail if no thread ID is passed 760 // Bail if no thread ID is passed. 770 761 if ( empty( $thread_id ) ) { 771 762 return false; … … 792 783 * 793 784 * @param array $recipients Array containing the message recipients (array of objects). 794 * 795 * @return string 785 * @return string $value String of message recipent userlinks. 796 786 */ 797 787 public static function get_recipient_links( $recipients ) { … … 831 821 $threads = $wpdb->get_results( "SELECT * FROM {$bp_prefix}bp_messages_threads" ); 832 822 833 // Nothing to update, just return true to remove the table 823 // Nothing to update, just return true to remove the table. 834 824 if ( empty( $threads ) ) { 835 825 return true; … … 844 834 $message_ids = implode( ',', $message_ids ); 845 835 846 // Add the thread_id to the messages table 836 // Add the thread_id to the messages table. 847 837 if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_messages} SET thread_id = %d WHERE id IN ({$message_ids})", $thread->id ) ) ) { 848 838 $errors = true;
Note: See TracChangeset
for help on using the changeset viewer.