public function actionSendNewRate()
 {
     $response = [];
     if (Yii::$app->user->isGuest) {
         $html = $this->renderPartial('/common/new-rate-warning-for-guests', []);
         $response = ['res' => 'warning', 'msg' => $html];
         echo json_encode($response);
         return;
     }
     $model = new PokerDraftForm();
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         $fantasy = PokerFantasy::findOne($model->fantasy_id);
         if ($fantasy === null) {
             return;
         }
         //echo'<pre>1111';print_r($model);echo'</pre>';die;
         if ($model->validate()) {
             //echo'<pre>'; print_r($model);echo'</pre>';die;
             $model->addRate($fantasy);
             $response['res'] = 'ok';
             $response['msg'] = Yii::t('app', 'FANTASY_RATE_SENDED');
         } else {
             foreach ($model->getErrors() as $err) {
                 $response['res'] = 'err';
                 $response['msg'] = $err[0];
                 break;
             }
         }
     }
     echo json_encode($response);
     return;
 }
Beispiel #2
0
 /**
  * возвращает модель фантазии в зависимости от вида игры
  *
  * @param int $fantasy_id
  * @param int $game_id
  * @return mixed
  */
 private static function getFantasyModel($fantasy_id, $game_id)
 {
     switch ($game_id) {
         case Transaction::TR_GAME_DOTA:
             $fantasyModel = DotaFantasy::findOne($fantasy_id);
             break;
         case Transaction::TR_GAME_POKER:
             $fantasyModel = PokerFantasy::findOne($fantasy_id);
             break;
     }
     return $fantasyModel;
 }