Exemple #1
0
 public static function amIVoted($id, $type)
 {
     return \frontend\widgets\rating\models\Rating::amIVoted($id, $type);
 }
Exemple #2
0
 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);
 }