public static function likeArticle() { $post = Yii::$app->request->post(); $response = []; if (Yii::$app->user->isGuest) { $response['error'] = 'Ви не авторизовані!'; } else { if (!Blog::checkLikeArticle($post['article_id'], Yii::$app->user->getId())) { $response['success'] = '+'; $response['count-likes'] = Blog::likeArticle($post['article_id'], Yii::$app->user->getId()); Rating::like($post['article_id'], Rating::ARTICLE, 1); } else { $response['count-likes'] = Blog::disLikeArticle($post['article_id'], Yii::$app->user->getId()); $response['success'] = '-'; Rating::like($post['article_id'], Rating::ARTICLE, -1); } } echo json_encode($response); }