Пример #1
0
 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);
 }