public function addComment($comment)
    {
        if(Yii::$app->params['commentNeedApproval'])
            $comment->status = Comment::STATUS_PENDING;
        else
            $comment->status = Comment::STATUS_APPROVED;
        // set model and parent_id (parent model ID)
        $comment->model = self::COMMENT_FOR;
        $comment->parent_id = $this->id;
        $comment->user_id = \Yii::$app->user->id;
        if($comment->thread == '-')
            // set new thread
            $comment->thread = time() . uniqid();
        else
            // unmark previous comment
            Yii::$app->db->createCommand("UPDATE {{%comment}} SET last=0 WHERE thread='{$comment->thread}' AND last=1")->execute();
        // mark only last comment in a thread
        $comment->last = 1;
        if($comment->save()) {
            if(Yii::$app->params['notifyResponsibleAboutComment'])
                $comment->trigger(Comment::EVENT_JUST_ADDED);
            $comment->content = '';
            return true;
        } else
            return false;
    }
public function addComment($comment)
    {
        if(Yii::$app->params['commentNeedApproval'])
            $comment->status = Comment::STATUS_PENDING;
        else
            $comment->status = Comment::STATUS_APPROVED;
        // set model and parent_id (parent model ID)
        $comment->model = self::COMMENT_FOR;
        $comment->parent_id = $this->id;
        $comment->user_id = \Yii::$app->user->id;
        if($comment->thread == '-')
            // set new thread
            $comment->thread = time() . uniqid();
        else
            // unmark previous comment
            Yii::$app->db->createCommand("UPDATE {{%comment}} SET last=0 WHERE thread='{$comment->thread}' AND last=1")->execute();
        // mark only last comment in a thread
        $comment->last = 1;
        if($comment->save()) {
            if(Yii::$app->params['notifyResponsibleAboutComment'])
                $comment->trigger(Comment::EVENT_JUST_ADDED);
            $comment->content = '';
            return true;
        } else
            return false;
    }
public function addComment ( $ comment ) { if ( Yii :: $ app -> params [ 'commentNeedApproval' ] ) $ comment -> status = Comment :: STATUS_PENDING ; else $ comment -> status = Comment :: STATUS_APPROVED ; // set model and parent_id (parent model ID) $ comment -> model = self :: COMMENT_FOR ; $ comment -> parent_id = $ this -> id ; $ comment -> user_id = \ Yii :: $ app -> user -> id ; if ( $ comment -> thread == '-' ) // set new thread $ comment -> thread = time ( ) . uniqid ( ) ; else // unmark previous comment Yii :: $ app -> db -> createCommand ( "UPDATE {{%comment}} SET last=0 WHERE thread='{$comment->thread}' AND last=1" ) -> execute ( ) ; // mark only last comment in a thread $ comment -> last = 1 ; if ( $ comment -> save ( ) ) { if ( Yii :: $ app -> params [ 'notifyResponsibleAboutComment' ] ) $ comment -> trigger ( Comment :: EVENT_JUST_ADDED ) ; $ comment -> content = '' ; return true ; } else return false ; }
Adds a new comment for the model.
@param Comment the comment to be added
@return boolean whether the comment is saved successfully
Adds a new comment for the model .