public function actionFavorit() { $post = Yii::$app->request->post(); $response = []; if (Yii::$app->user->isGuest) { $response['error'] = Yii::t('yii', 'Вы не авторизованы!'); } else { if (!Photo::checkFavoritPhoto($post['photo_id'], Yii::$app->user->getId())) { Photo::favoritPhoto($post['photo_id'], Yii::$app->user->getId()); Rating::favor($post['photo_id'], Rating::PHOTO, 1); $response['success'] = '+'; } else { Photo::disFavoritPhoto($post['photo_id'], Yii::$app->user->getId()); Rating::favor($post['photo_id'], Rating::PHOTO, -1); $response['success'] = '-'; } $response['cnt_favorite'] = Photo::getCountFavorite($post['photo_id']); echo json_encode($response); } }
public function actionFavor() { $request = Yii::$app->request; $articaleId = $request->post('article_id'); $response = []; if (!Yii::$app->user->isGuest && Blog::isClosed($articaleId)) { if (Blog::ifAvailableArticle($articaleId)) { $response['response'] = 1; if (Blog::favorArticle($articaleId, Yii::$app->user->getId())) { $response['favorite'] = 1; Rating::favor($articaleId, Rating::ARTICLE, 1); } else { $response['favorite'] = 0; Rating::favor($articaleId, Rating::ARTICLE, -1); } } else { $response['response'] = 0; } } else { $response['response'] = 0; } echo json_encode($response); }