Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/20/2010 04:21:20 PM (16 years ago)
Author:
apeatling
Message:

Standardizing activity stream fields and splitting the action from the content for better manageability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r2369 r2381  
    77    var $user_id;
    88    var $primary_link;
    9     var $component_name;
    10     var $component_action;
     9    var $component;
     10    var $type;
     11    var $action;
     12    var $content;
    1113    var $date_recorded;
    1214    var $hide_sitewide = false;
     
    2426        global $wpdb, $bp;
    2527
    26         $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
     28        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
    2729
    2830        if ( $activity ) {
    29             $this->id = $activity->id;
    30             $this->item_id = $activity->item_id;
    31             $this->secondary_item_id = $activity->secondary_item_id;
    32             $this->user_id = $activity->user_id;
    33             $this->content = $activity->content;
    34             $this->primary_link = $activity->primary_link;
    35             $this->component_name = $activity->component_name;
    36             $this->component_action = $activity->component_action;
    37             $this->date_recorded = $activity->date_recorded;
    38             $this->hide_sitewide = $activity->hide_sitewide;
     31            $this->id = $row->id;
     32            $this->item_id = $row->item_id;
     33            $this->secondary_item_id = $row->secondary_item_id;
     34            $this->user_id = $row->user_id;
     35            $this->primary_link = $row->primary_link;
     36            $this->component = $row->component;
     37            $this->type = $row->type;
     38            $this->action = $row->type;
     39            $this->content = $row->content;
     40            $this->date_recorded = $row->date_recorded;
     41            $this->hide_sitewide = $row->hide_sitewide;
    3942        }
    4043    }
     
    4548        do_action( 'bp_activity_before_save', $this );
    4649
    47         if ( !$this->component_name || !$this->component_action )
     50        if ( !$this->component || !$this->type )
    4851            return false;
    4952
     
    5356        /* If we have an existing ID, update the activity item, otherwise insert it. */
    5457        if ( $this->id )
    55             $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component_name = %s, component_action = %s, content = %s, primary_link = %s, date_recorded = FROM_UNIXTIME(%d), item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
     58            $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = FROM_UNIXTIME(%d), item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
    5659        else
    57             $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component_name, component_action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s, %s, %d )", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
     60            $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s, %s, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
    5861
    5962        if ( !$wpdb->query( $q ) )
     
    6871    /* Static Functions */
    6972
    70     function delete( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
     73    function delete( $item_id, $component, $type, $user_id = false, $secondary_item_id = false ) {
    7174        global $wpdb, $bp;
    7275
     
    7477            $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id );
    7578
    76         if ( $component_action )
    77             $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
     79        if ( $type )
     80            $type_sql = $wpdb->prepare( "AND type = %s", $type );
    7881
    7982        if ( $user_id )
     
    8184
    8285        /* Fetch the activity IDs so we can delete any comments for this activity item */
    83         $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) );
    84 
    85         error_log( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) );
    86 
    87         if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) ) )
     86        $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) );
     87
     88        error_log( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) );
     89
     90        if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) ) )
    8891            return false;
    8992
     
    98101    }
    99102
    100     function delete_by_item_id( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
    101         return BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
     103    function delete_by_item_id( $item_id, $component, $type, $user_id = false, $secondary_item_id = false ) {
     104        return BP_Activity_Activity::delete( $item_id, $component, $type, $user_id, $secondary_item_id );
    102105    }
    103106
     
    115118    }
    116119
    117     function delete_by_content( $user_id, $content, $component_name, $component_action ) {
     120    function delete_by_content( $user_id, $content, $component, $type ) {
    118121        global $bp, $wpdb;
    119122
    120123        /* Fetch the activity ID so we can delete any comments for this activity item */
    121         $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) );
    122 
    123         if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) ) )
     124        $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component = %s AND type = %s", $user_id, $content, $component, $type ) );
     125
     126        if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component = %s AND type = %s", $user_id, $content, $component, $type ) ) )
    124127            return false;
    125128
     
    134137    }
    135138
    136     function delete_for_user_by_component( $user_id, $component_name ) {
     139    function delete_for_user_by_component( $user_id, $component ) {
    137140        global $bp, $wpdb;
    138141
    139142        /* Fetch the activity IDs so we can delete any comments for this activity item */
    140         $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) );
    141 
    142         if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) ) )
     143        $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND component = %s", $user_id, $component ) );
     144
     145        if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component = %s", $user_id, $component ) ) )
    143146            return false;
    144147
     
    178181        $activity_ids = $wpdb->escape( $activity_ids );
    179182
    180         return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE component_action = 'activity_comment' AND item_id IN ({$activity_ids})" ) );
     183        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) );
    181184    }
    182185
     
    238241        /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
    239242        if ( !$display_comments || 'threaded' == $display_comments ) {
    240             $where_conditions[] = "a.component_action != 'activity_comment'";
     243            $where_conditions[] = "a.type != 'activity_comment'";
    241244        }
    242245
     
    268271        $activity_ids = $wpdb->escape( $activity_ids );
    269272
     273        if ( empty( $activity_ids ) )
     274            return false;
     275
    270276        if ( $per_page && $page )
    271277            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
     
    294300        /* Now fetch the activity comments and parse them into the correct position in the activities array. */
    295301        foreach( $activities as $activity ) {
    296             if ( 'activity_comment' != $activity->component_action && $activity->mptt_left && $activity->mptt_right )
     302            if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
    297303                $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
    298304        }
     
    320326        }
    321327
    322         $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.component_action = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ) );
     328        $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ) );
    323329
    324330        /* Loop descendants and build an assoc array */
     
    348354
    349355        /* Get all descendants of this node */
    350         $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE component_action = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
     356        $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
    351357
    352358        /* Loop the descendants and recalculate the left and right values */
     
    358364            $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
    359365        else
    360             $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE component_action = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
     366            $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 ) );
    361367
    362368        /* Return the right value of this node + 1 */
     
    364370    }
    365371
    366     function get_recorded_component_names() {
    367         global $wpdb, $bp;
    368 
    369         return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component_name FROM {$bp->activity->table_name} ORDER BY component_name ASC" ) );
     372    function get_recorded_components() {
     373        global $wpdb, $bp;
     374
     375        return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" ) );
    370376    }
    371377
     
    414420            $counter = 1;
    415421            foreach( (array) $object_filter as $object ) {
    416                 $object_sql .= $wpdb->prepare( "a.component_name = %s", trim( $object ) );
     422                $object_sql .= $wpdb->prepare( "a.component = %s", trim( $object ) );
    417423
    418424                if ( $counter != count( $object_filter ) )
     
    432438            $counter = 1;
    433439            foreach( (array) $action_filter as $action ) {
    434                 $action_sql .= $wpdb->prepare( "a.component_action = %s", trim( $action ) );
     440                $action_sql .= $wpdb->prepare( "a.type = %s", trim( $action ) );
    435441
    436442                if ( $counter != count( $action_filter ) )
Note: See TracChangeset for help on using the changeset viewer.