function rebuild_activity_comment_tree($parent_id, $left = 1)
 {
     global $nxtdb, $bp;
     // The right value of this node is the left value + 1
     $right = $left + 1;
     // Get all descendants of this node
     $descendants = BP_Activity_Activity::get_child_comments($parent_id);
     // Loop the descendants and recalculate the left and right values
     foreach ((array) $descendants as $descendant) {
         $right = BP_Activity_Activity::rebuild_activity_comment_tree($descendant->id, $right);
     }
     // We've got the left value, and now that we've processed the children
     // of this node we also know the right value
     if (1 == $left) {
         $nxtdb->query($nxtdb->prepare("UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id));
     } else {
         $nxtdb->query($nxtdb->prepare("UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id));
     }
     // Return the right value of this node + 1
     return $right + 1;
 }
 /**
  * Rebuild nested comment tree under an activity or activity comment.
  *
  * @since 1.2.0
  *
  * @global wpdb $wpdb WordPress database object.
  *
  * @param  int $parent_id ID of an activity or activity comment.
  * @param  int $left      Node boundary start for activity or activity comment.
  * @return int Right      Node boundary of activity or activity comment.
  */
 public static function rebuild_activity_comment_tree($parent_id, $left = 1)
 {
     global $wpdb;
     $bp = buddypress();
     // The right value of this node is the left value + 1.
     $right = intval($left + 1);
     // Get all descendants of this node.
     $comments = BP_Activity_Activity::get_child_comments($parent_id);
     $descendants = wp_list_pluck($comments, 'id');
     // Loop the descendants and recalculate the left and right values.
     foreach ((array) $descendants as $descendant_id) {
         $right = BP_Activity_Activity::rebuild_activity_comment_tree($descendant_id, $right);
     }
     // We've got the left value, and now that we've processed the children
     // of this node we also know the right value.
     if (1 === $left) {
         $wpdb->query($wpdb->prepare("UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id));
     } else {
         $wpdb->query($wpdb->prepare("UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id));
     }
     // Return the right value of this node + 1.
     return intval($right + 1);
 }
Ejemplo n.º 3
0
/**
 * Delete an activity comment's children.
 *
 * @since BuddyPress (1.2.0)
 *
 * @uses BP_Activity_Activity::get_child_comments() {@link BP_Activity_Activity}
 * @uses bp_activity_delete_children()
 * @uses bp_activity_delete()
 *
 * @param int $activity_id The ID of the "root" activity, ie the
 *        comment's oldest ancestor.
 * @param int $comment_id The ID of the comment to be deleted.
 */
function bp_activity_delete_children($activity_id, $comment_id)
{
    // Get activity children to delete
    $children = BP_Activity_Activity::get_child_comments($comment_id);
    // Recursively delete all children of this comment.
    if (!empty($children)) {
        foreach ((array) $children as $child) {
            bp_activity_delete_children($activity_id, $child->id);
        }
    }
    // Delete the comment itself
    bp_activity_delete(array('secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id));
}
Ejemplo n.º 4
0
	function bp_activity_delete_children( $activity_id, $comment_id) {
		/* Recursively delete all children of this comment. */
		if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
			foreach( (array)$children as $child )
				bp_activity_delete_children( $activity_id, $child->id );
		}
		bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
	}