Skip to:
Content

BuddyPress.org

Changeset 7969


Ignore:
Timestamp:
02/22/2014 10:49:31 PM (12 years ago)
Author:
r-a-y
Message:

Add phpDoc for BP_Messages_Notice class.

File:
1 edited

Legend:

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

    r7968 r7969  
    430430}
    431431
     432/**
     433 * BuddyPress Notices class.
     434 *
     435 * Use this class to create, activate, deactivate or delete notices.
     436 *
     437 * @since BuddyPress (1.0.0)
     438 */
    432439class BP_Messages_Notice {
     440    /**
     441     * The notice ID.
     442     *
     443     * @var int
     444     */
    433445    public $id = null;
     446
     447    /**
     448     * The subject line for the notice.
     449     *
     450     * @var string
     451     */
    434452    public $subject;
     453
     454    /**
     455     * The content of the notice.
     456     *
     457     * @var string
     458     */
    435459    public $message;
     460
     461    /**
     462     * The date the notice was created.
     463     *
     464     * @var string
     465     */
    436466    public $date_sent;
     467
     468    /**
     469     * Whether the notice is active or not.
     470     *
     471     * @var int
     472     */
    437473    public $is_active;
    438474
     475    /**
     476     * Constructor.
     477     *
     478     * @since BuddyPress (1.0.0)
     479     */
    439480    public function __construct( $id = null ) {
    440481        if ( $id ) {
    441482            $this->id = $id;
    442             $this->populate($id);
    443         }
    444     }
    445 
     483            $this->populate();
     484        }
     485    }
     486
     487    /**
     488     * Populate method.
     489     *
     490     * Runs during constructor.
     491     *
     492     * @since BuddyPress (1.0.0)
     493     */
    446494    public function populate() {
    447495        global $wpdb, $bp;
     
    457505    }
    458506
     507    /**
     508     * Saves a notice.
     509     *
     510     * @since BuddyPress (1.0.0)
     511     *
     512     * @return bool
     513     */
    459514    public function save() {
    460515        global $wpdb, $bp;
     
    465520        do_action_ref_array( 'messages_notice_before_save', array( &$this ) );
    466521
    467         if ( empty( $this->id ) )
     522        if ( empty( $this->id ) ) {
    468523            $sql = $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_notices} (subject, message, date_sent, is_active) VALUES (%s, %s, %s, %d)", $this->subject, $this->message, $this->date_sent, $this->is_active );
    469         else
     524        } else {
    470525            $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_notices} SET subject = %s, message = %s, is_active = %d WHERE id = %d", $this->subject, $this->message, $this->is_active, $this->id );
    471 
    472         if ( !$wpdb->query( $sql ) )
    473             return false;
    474 
    475         if ( !$id = $this->id )
     526        }
     527
     528        if ( ! $wpdb->query( $sql ) ) {
     529            return false;
     530        }
     531
     532        if ( ! $id = $this->id ) {
    476533            $id = $wpdb->insert_id;
     534        }
    477535
    478536        // Now deactivate all notices apart from the new one.
     
    486544    }
    487545
     546    /**
     547     * Activates a notice.
     548     *
     549     * @since BuddyPress (1.0.0)
     550     *
     551     * @return bool
     552     */
    488553    public function activate() {
    489554        $this->is_active = 1;
     
    491556    }
    492557
     558    /**
     559     * Deactivates a notice.
     560     *
     561     * @since BuddyPress (1.0.0)
     562     *
     563     * @return bool
     564     */
    493565    public function deactivate() {
    494566        $this->is_active = 0;
     
    496568    }
    497569
     570    /**
     571     * Deletes a notice.
     572     *
     573     * @since BuddyPress (1.0.0)
     574     *
     575     * @return bool
     576     */
    498577    public function delete() {
    499578        global $wpdb, $bp;
     
    501580        $sql = $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id );
    502581
    503         if ( !$wpdb->query( $sql ) )
    504             return false;
     582        if ( ! $wpdb->query( $sql ) ) {
     583            return false;
     584        }
    505585
    506586        return true;
     
    510590
    511591    /**
    512      * Pulls up a list of notices
     592     * Pulls up a list of notices.
    513593     *
    514594     * To get all notices, pass a value of -1 to pag_num
    515595     *
    516      * @param array $args See $defaults for explanation of accepted arguments
    517      * @return array $notices
     596     * @since BuddyPress (1.0.0)
     597     *
     598     * @param array $data {
     599     *     Array of parameters.
     600     *     @type int $pag_num Number of notices per page. Defaults to 20.
     601     *     @type int $pag_page The page number.  Defaults to 1.
     602     * }
     603     * @return array
    518604     */
    519605    public static function get_notices( $args = array() ) {
     
    535621    }
    536622
     623    /**
     624     * Returns the total number of recorded notices.
     625     *
     626     * @since BuddyPress (1.0.0)
     627     *
     628     * @return int
     629     */
    537630    public static function get_total_notice_count() {
    538631        global $wpdb, $bp;
     
    543636    }
    544637
     638    /**
     639     * Returns the active notice that should be displayed on the frontend.
     640     *
     641     * @since BuddyPress (1.0.0)
     642     *
     643     * @return object The BP_Messages_Notice object
     644     */
    545645    public static function get_active() {
    546646        global $wpdb, $bp;
Note: See TracChangeset for help on using the changeset viewer.