public static function likePhoto() { $post = Yii::$app->request->post(); $response = []; if (Yii::$app->user->isGuest) { $response['error'] = 'Ви не авторизовані!'; } else { if (!Photo::checkLikePhoto($post['photo_id'], Yii::$app->user->getId())) { Photo::likePhoto($post['photo_id'], Yii::$app->user->getId()); $response['success'] = '+'; Rating::like($post['photo_id'], Rating::PHOTO, 1); } else { Photo::disLikePhoto($post['photo_id'], Yii::$app->user->getId()); $response['success'] = '-'; Rating::like($post['photo_id'], Rating::PHOTO, -1); } $response['cnt_likes'] = Photo::getCountLikes($post['photo_id']); } echo json_encode($response); }