public function actionRazzVote() { $request = Yii::$app->request; $token = Token::checkToken($request->get('token')); if (!is_array($token)) { throw new HttpException(401, $token); } $model = new Razz(); $razz = $model->getRazz($request->get('id')); if (!$razz) { throw new HttpException(404, 'Razzd not found.'); } if (!$razz['responder_stream']) { throw new HttpException(422, 'Razzd is not started.'); } if ($razz['created_at'] + Razz::DAYS < time()) { throw new HttpException(422, 'Razzd is ended.'); } $ratingModel = Yii::createObject(['class' => \frontend\widgets\rating\models\Rating::className(), 'nid' => $request->get('id'), 'model' => 'Razz', 'vote' => $request->get('vote') == 'my' ? ['my' => 1] : ['responder' => 1], 'uid' => $token['user_id']]); if ($ratingModel->save()) { return RestApi::response($ratingModel->return); } return RestApi::response($ratingModel->return); }