Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/22/2015 06:02:55 AM (11 years ago)
Author:
tw2113
Message:

More docs cleanup for Notifications component.

See #6404.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/classes/class-bp-notifications-notification.php

    r10248 r10303  
    77 * @package BuddyPress
    88 * @subpackage NotificationsClasses
    9  *
    109 * @since 1.9.0
    1110 */
    … …  
    115114        public function save() {
    116115
    117                 // Return value
     116                // Return value.
    118117                $retval = false;
    119118
    120                 // Default data and format
     119                // Default data and format.
    121120                $data = array(
    122121                        'user_id'           => $this->user_id,
    … …  
    141140                do_action_ref_array( 'bp_notification_before_save', array( &$this ) );
    142141
    143                 // Update
     142                // Update.
    144143                if ( ! empty( $this->id ) ) {
    145144                        $result = self::_update( $data, array( 'ID' => $this->id ), $data_format, array( '%d' ) );
    146145
    147                 // Insert
     146                // Insert.
    148147                } else {
    149148                        $result = self::_insert( $data, $data_format );
    150149                }
    151150
    152                 // Set the notification ID if successful
     151                // Set the notification ID if successful.
    153152                if ( ! empty( $result ) && ! is_wp_error( $result ) ) {
    154153                        global $wpdb;
    … …  
    163162                 * @since 2.0.0
    164163                 *
    165                  * @param BP_Notifications_Notification $value Current instance of the notification item being saved. Passed by reference.
     164                 * @param BP_Notifications_Notification $value Current instance of the notification item being saved.
     165                 *                                             Passed by reference.
    166166                 */
    167167                do_action_ref_array( 'bp_notification_after_save', array( &$this ) );
    168168
    169                 // Return the result
     169                // Return the result.
    170170                return $retval;
    171171        }
    … …  
    184184                $bp = buddypress();
    185185
    186                 // Look for a notification
     186                // Look for a notification.
    187187                $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->notifications->table_name} WHERE id = %d", $this->id ) );
    188188
    189                 // Setup the notification data
     189                // Setup the notification data.
    190190                if ( ! empty( $notification ) && ! is_wp_error( $notification ) ) {
    191191                        $this->item_id           = $notification->item_id;
    … …  
    240240         * @param array $data_format  See {@link wpdb::insert()}.
    241241         * @param array $where_format See {@link wpdb::insert()}.
    242          *
    243242         * @return int|false The number of rows updated, or false on error.
    244243         */
    … …  
    259258         *                            BP_Notification_Notification object.
    260259         * @param array $where_format See {@link wpdb::insert()}.
    261          *
    262260         * @return int|false The number of rows updated, or false on error.
    263261         */
    … …  
    281279         * @param string $join_sql       SQL JOIN fragment.
    282280         * @param string $meta_query_sql SQL meta query fragment.
    283          *
    284281         * @return string WHERE clause.
    285282         */
    … …  
    290287                $where            = '';
    291288
    292                 // id
     289                // The id.
    293290                if ( ! empty( $args['id'] ) ) {
    294291                        $id_in = implode( ',', wp_parse_id_list( $args['id'] ) );
    … …  
    296293                }
    297294
    298                 // user_id
     295                // The user_id.
    299296                if ( ! empty( $args['user_id'] ) ) {
    300297                        $user_id_in = implode( ',', wp_parse_id_list( $args['user_id'] ) );
    … …  
    302299                }
    303300
    304                 // item_id
     301                // The item_id.
    305302                if ( ! empty( $args['item_id'] ) ) {
    306303                        $item_id_in = implode( ',', wp_parse_id_list( $args['item_id'] ) );
    … …  
    308305                }
    309306
    310                 // secondary_item_id
     307                // The secondary_item_id.
    311308                if ( ! empty( $args['secondary_item_id'] ) ) {
    312309                        $secondary_item_id_in = implode( ',', wp_parse_id_list( $args['secondary_item_id'] ) );
    … …  
    314311                }
    315312
    316                 // component_name
     313                // The component_name.
    317314                if ( ! empty( $args['component_name'] ) ) {
    318315                        if ( ! is_array( $args['component_name'] ) ) {
    … …  
    331328                }
    332329
    333                 // component_action
     330                // The component_action.
    334331                if ( ! empty( $args['component_action'] ) ) {
    335332                        if ( ! is_array( $args['component_action'] ) ) {
    … …  
    348345                }
    349346
    350                 // is_new
     347                // If is_new.
    351348                if ( ! empty( $args['is_new'] ) && 'both' !== $args['is_new'] ) {
    352349                        $where_conditions['is_new'] = "is_new = 1";
    … …  
    355352                }
    356353
    357                 // search_terms
     354                // The search_terms.
    358355                if ( ! empty( $args['search_terms'] ) ) {
    359356                        $search_terms_like = '%' . bp_esc_like( $args['search_terms'] ) . '%';
    … …  
    361358                }
    362359
    363                 // date query
     360                // The date query.
    364361                if ( ! empty( $args['date_query'] ) ) {
    365362                        $where_conditions['date_query'] = self::get_date_query_sql( $args['date_query'] );
    366363                }
    367364
    368                 // meta query
     365                // The meta query.
    369366                if ( ! empty( $meta_query_sql['where'] ) ) {
    370367                        $where_conditions['meta_query'] = $meta_query_sql['where'];
    … …  
    385382                $where_conditions = apply_filters( 'bp_notifications_get_where_conditions', $where_conditions, $args, $select_sql, $from_sql, $join_sql, $meta_query_sql );
    386383
    387                 // Custom WHERE
     384                // Custom WHERE.
    388385                if ( ! empty( $where_conditions ) ) {
    389386                        $where = 'WHERE ' . implode( ' AND ', $where_conditions );
    … …  
    403400         * @param array $args See {@link BP_Notifications_Notification::get()}
    404401         *                    for more details.
    405          *
    406402         * @return string ORDER BY clause.
    407403         */
    408404        protected static function get_order_by_sql( $args = array() ) {
    409405
    410                 // Setup local variable
     406                // Setup local variable.
    411407                $conditions = array();
    412408                $retval     = '';
    413409
    414                 // Order by
     410                // Order by.
    415411                if ( ! empty( $args['order_by'] ) ) {
    416412                        $order_by               = implode( ', ', (array) $args['order_by'] );
    … …  
    418414                }
    419415
    420                 // Sort order direction
     416                // Sort order direction.
    421417                if ( ! empty( $args['sort_order'] ) && in_array( $args['sort_order'], array( 'ASC', 'DESC' ) ) ) {
    422418                        $sort_order               = $args['sort_order'];
    … …  
    424420                }
    425421
    426                 // Custom ORDER BY
     422                // Custom ORDER BY.
    427423                if ( ! empty( $conditions ) ) {
    428424                        $retval = 'ORDER BY ' . implode( ' ', $conditions );
    … …  
    441437         * @param array $args See {@link BP_Notifications_Notification::get()}
    442438         *                    for more details.
    443          *
    444          * @return string LIMIT clause.
     439         * @return string $retval LIMIT clause.
    445440         */
    446441        protected static function get_paged_sql( $args = array() ) {
    447442                global $wpdb;
    448443
    449                 // Setup local variable
     444                // Setup local variable.
    450445                $retval = '';
    451446
    452                 // Custom LIMIT
     447                // Custom LIMIT.
    453448                if ( ! empty( $args['page'] ) && ! empty( $args['per_page'] ) ) {
    454449                        $page     = absint( $args['page']     );
    … …  
    500495         *                    See {@BP_Notifications_Notification::get()}
    501496         *                    for a breakdown.
    502          *
    503497         * @return array Associative array of 'data' and 'format' args.
    504498         */
    … …  
    509503                );
    510504
    511                 // id
     505                // The id.
    512506                if ( ! empty( $args['id'] ) ) {
    513507                        $where_clauses['data']['id'] = absint( $args['id'] );
    … …  
    515509                }
    516510
    517                 // user_id
     511                // The user_id.
    518512                if ( ! empty( $args['user_id'] ) ) {
    519513                        $where_clauses['data']['user_id'] = absint( $args['user_id'] );
    … …  
    521515                }
    522516
    523                 // item_id
     517                // The item_id.
    524518                if ( ! empty( $args['item_id'] ) ) {
    525519                        $where_clauses['data']['item_id'] = absint( $args['item_id'] );
    … …  
    527521                }
    528522
    529                 // secondary_item_id
     523                // The secondary_item_id.
    530524                if ( ! empty( $args['secondary_item_id'] ) ) {
    531525                        $where_clauses['data']['secondary_item_id'] = absint( $args['secondary_item_id'] );
    … …  
    533527                }
    534528
    535                 // component_name
     529                // The component_name.
    536530                if ( ! empty( $args['component_name'] ) ) {
    537531                        $where_clauses['data']['component_name'] = $args['component_name'];
    … …  
    539533                }
    540534
    541                 // component_action
     535                // The component_action.
    542536                if ( ! empty( $args['component_action'] ) ) {
    543537                        $where_clauses['data']['component_action'] = $args['component_action'];
    … …  
    545539                }
    546540
    547                 // is_new
     541                // If is_new.
    548542                if ( isset( $args['is_new'] ) ) {
    549543                        $where_clauses['data']['is_new'] = ! empty( $args['is_new'] ) ? 1 : 0;
    … …  
    563557         * @param int $user_id         ID of the user being checked.
    564558         * @param int $notification_id ID of the notification being checked.
    565          *
    566559         * @return bool True if the notification belongs to the user, otherwise
    567560         *              false.
    … …  
    580573         * @since 2.3.0
    581574         *
    582          * @param  mixed $args
     575         * @param mixed $args Args to parse.
    583576         * @return array
    584577         */
    … …  
    643636                global $wpdb;
    644637
    645                 // Parse the arguments
     638                // Parse the arguments.
    646639                $r = self::parse_args( $args );
    647640
    648                 // Get BuddyPress
     641                // Get BuddyPress.
    649642                $bp = buddypress();
    650643
    651                 // METADATA
     644                // METADATA.
    652645                $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
    653646
    654                 // SELECT
     647                // SELECT.
    655648                $select_sql = "SELECT *";
    656649
    657                 // FROM
     650                // FROM.
    658651                $from_sql   = "FROM {$bp->notifications->table_name} n ";
    659652
    660                 // JOIN
     653                // JOIN.
    661654                $join_sql   = $meta_query_sql['join'];
    662655
    663                 // WHERE
     656                // WHERE.
    664657                $where_sql  = self::get_where_sql( array(
    665658                        'id'                => $r['id'],
    … …  
    674667                ), $select_sql, $from_sql, $join_sql, $meta_query_sql );
    675668
    676                 // ORDER BY
     669                // ORDER BY.
    677670                $order_sql  = self::get_order_by_sql( array(
    678671                        'order_by'   => $r['order_by'],
    … …  
    680673                ) );
    681674
    682                 // LIMIT %d, %d
     675                // LIMIT %d, %d.
    683676                $pag_sql    = self::get_paged_sql( array(
    684677                        'page'     => $r['page'],
    … …  
    686679                ) );
    687680
    688                 // Concatenate query parts
     681                // Concatenate query parts.
    689682                $sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} {$order_sql} {$pag_sql}";
    690683
    … …  
    697690         * @since 1.9.0
    698691         *
    699          * @see BP_Notifications_Notification::get() for a description of
    700          *      arguments.
     692         * @see BP_Notifications_Notification::get() for a description of arguments.
    701693         *
    702694         * @param array $args See {@link BP_Notifications_Notification::get()}.
    703          *
    704695         * @return int Count of located items.
    705696         */
    … …  
    707698                global $wpdb;
    708699
    709                 // Parse the arguments
     700                // Parse the arguments.
    710701                $r = self::parse_args( $args );
    711702
    712                 // Load BuddyPress
     703                // Load BuddyPress.
    713704                $bp = buddypress();
    714705
    715                 // METADATA
     706                // METADATA.
    716707                $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
    717708
    718                 // SELECT
     709                // SELECT.
    719710                $select_sql = "SELECT COUNT(*)";
    720711
    721                 // FROM
     712                // FROM.
    722713                $from_sql   = "FROM {$bp->notifications->table_name} n ";
    723714
    724                 // JOIN
     715                // JOIN.
    725716                $join_sql   = $meta_query_sql['join'];
    726717
    727                 // WHERE
     718                // WHERE.
    728719                $where_sql  = self::get_where_sql( array(
    729720                        'id'                => $r['id'],
    … …  
    738729                ), $select_sql, $from_sql, $join_sql, $meta_query_sql );
    739730
    740                 // Concatenate query parts
     731                // Concatenate query parts.
    741732                $sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql}";
    742733
    743                 // Return the queried results
     734                // Return the queried results.
    744735                return $wpdb->get_var( $sql );
    745736        }
    … …  
    758749         * @param  array $meta_query An array of meta_query filters. See the
    759750         *                           documentation for WP_Meta_Query for details.
    760          *
    761751         * @return array $sql_array 'join' and 'where' clauses.
    762752         */
    763753        public static function get_meta_query_sql( $meta_query = array() ) {
    764754
    765                 // Default array keys & empty values
     755                // Default array keys & empty values.
    766756                $sql_array = array(
    767757                        'join'  => '',
    … …  
    769759                );
    770760
    771                 // Bail if no meta query
     761                // Bail if no meta query.
    772762                if ( empty( $meta_query ) ) {
    773763                        return $sql_array;
    774764                }
    775765
    776                 // WP_Meta_Query expects the table name at $wpdb->notificationmeta
     766                // WP_Meta_Query expects the table name at $wpdb->notificationmeta.
    777767                $GLOBALS['wpdb']->notificationmeta = buddypress()->notifications->table_name_meta;
    778768
    … …  
    780770                $meta_sql     = $n_meta_query->get_sql( 'notification', 'n', 'id' );
    781771
    782                 // Strip the leading AND - it's handled in get()
     772                // Strip the leading AND - it's handled in get().
    783773                $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] );
    784774                $sql_array['join']  = $meta_sql['join'];
    … …  
    800790         * @param array $date_query An array of date_query parameters. See the
    801791         *                          documentation for the first parameter of WP_Date_Query.
    802          *
    803792         * @return string
    804793         */
    805794        public static function get_date_query_sql( $date_query = array() ) {
    806795
    807                 // Bail if not a proper date query format
     796                // Bail if not a proper date query format.
    808797                if ( empty( $date_query ) || ! is_array( $date_query ) ) {
    809798                        return '';
    810799                }
    811800
    812                 // Date query
     801                // Date query.
    813802                $date_query = new BP_Date_Query( $date_query, 'date_recorded' );
    814803
    815                 // Strip the leading AND - it's handled in get()
     804                // Strip the leading AND - it's handled in get().
    816805                return preg_replace( '/^\sAND/', '', $date_query->get_sql() );
    817806        }
    … …  
    827816         * @param array $update_args Associative array of fields to update,
    828817         *                           and the values to update them to. Of the format
    829          *                           array( 'user_id' => 4, 'component_name' => 'groups', )
     818         *                           array( 'user_id' => 4, 'component_name' => 'groups', ).
    830819         * @param array $where_args  Associative array of columns/values, to
    831820         *                           determine which rows should be updated. Of the format
    832          *                           array( 'item_id' => 7, 'component_action' => 'members', )
    833          *
     821         *                           array( 'item_id' => 7, 'component_action' => 'members', ).
    834822         * @return int|bool Number of rows updated on success, false on failure.
    835823         */
    … …  
    866854         * @param array $args Associative array of columns/values, to determine
    867855         *                    which rows should be deleted.  Of the format
    868          *                    array( 'item_id' => 7, 'component_action' => 'members', )
    869          *
     856         *                    array( 'item_id' => 7, 'component_action' => 'members', ).
    870857         * @return int|bool Number of rows deleted on success, false on failure.
    871858         */
    … …  
    898885         *
    899886         * @param int $id ID of the notification item to be deleted.
    900          *
    901887         * @return bool True on success, false on failure.
    902888         */
    … …  
    916902         * @param string $status  Optional. Status of notifications to fetch.
    917903         *                        'is_new' to get only unread items, 'all' to get all.
    918          *
    919904         * @return array Associative array of notification items.
    920905         */
    … …  
    933918         * @param int $user_id ID of the user whose notifications are being
    934919         *                     fetched.
    935          *
    936920         * @return array Associative array of unread notification items.
    937921         */
    … …  
    950934         * @param int $user_id ID of the user whose notifications are being
    951935         *                     fetched.
    952          *
    953936         * @return array Associative array of unread notification items.
    954937         */
    … …  
    994977                $notifications = self::get( $r );
    995978
    996                 // Bail if no notifications
     979                // Bail if no notifications.
    997980                if ( empty( $notifications ) ) {
    998981                        return false;
    … …  
    10171000         * @param string $component_action  Name of the component action.
    10181001         * @param int    $secondary_item_id The ID of the secondary item.
    1019          *
    10201002         * @return bool|int False on failure to update. ID on success.
    10211003         */
    10221004        public static function mark_all_for_user( $user_id, $is_new = 0, $item_id = 0, $component_name = '', $component_action = '', $secondary_item_id = 0 ) {
    10231005
    1024                 // Values to be updated
     1006                // Values to be updated.
    10251007                $update_args = array(
    10261008                        'is_new' => $is_new,
    10271009                );
    10281010
    1029                 // WHERE clauses
     1011                // WHERE clauses.
    10301012                $where_args = array(
    10311013                        'user_id' => $user_id,
    … …  
    10611043         * @param string $component_action  Name of the component action.
    10621044         * @param int    $secondary_item_id The ID of the secondary item.
    1063          *
    10641045         * @return bool|int
    10651046         */
    10661047        public static function mark_all_from_user( $user_id, $is_new = 0, $component_name = '', $component_action = '', $secondary_item_id = 0 ) {
    10671048
    1068                 // Values to be updated
     1049                // Values to be updated.
    10691050                $update_args = array(
    10701051                        'is_new' => $is_new,
    10711052                );
    10721053
    1073                 // WHERE clauses
     1054                // WHERE clauses.
    10741055                $where_args = array(
    10751056                        'item_id' => $user_id,
    … …  
    11061087         * @param int    $secondary_item_id Optional. ID of the secondary
    11071088         *                                  associated item.
    1108          *
    11091089         * @return bool|int
    11101090         */
    11111091        public static function mark_all_by_type( $item_id, $is_new = 0, $component_name = '', $component_action = '', $secondary_item_id = 0 ) {
    11121092
    1113                 // Values to be updated
     1093                // Values to be updated.
    11141094                $update_args = array(
    11151095                        'is_new' => $is_new,
    11161096                );
    11171097
    1118                 // WHERE clauses
     1098                // WHERE clauses.
    11191099                $where_args = array(
    11201100                        'item_id' => $item_id,
Note: See TracChangeset for help on using the changeset viewer.