public function actionAddNewRate() { $fantasy_id = (int) Yii::$app->request->post('id', 0); $fantasy = PokerFantasy::findOne($fantasy_id); if ($fantasy === null) { return; } $params = PokerParams::loadParams(); $playersList = PokerEventPlayer::loadPlayersListOnFantasy($fantasy_id); $data = ['params' => $params, 'fantasy_id' => $fantasy_id, 'playersList' => $playersList, 'game_name' => GamesParams::GAME_POKER_NAME]; $view = 'add-new-rate-form-players'; return $this->renderPartial($view, $data); }
/** * @return \yii\db\ActiveQuery */ public function getPokerEventPlayers() { return $this->hasMany(PokerEventPlayer::className(), ['account_id' => 'account_id']); }
/** * проверяем изменения в игроках */ private function checkPlayers() { $player = new PokerPlayer(); $players_in_draft = $player->getPresentedPlayersInDrafts($this->id); //echo'<pre>';print_r($players_in_draft);echo'</pre>';die; //echo'<pre>';print_r($player->fantasyTableName);echo'</pre>';die; $array_identical = false; //echo'<pre>';print_r($this->pokerEventPlayerStats);echo'</pre>';//die; //echo'<pre>';print_r($this->player_id);echo'</pre>';die; if (count($this->eventPlayers) != count($this->player_id)) { $array_identical = false; } else { foreach ($this->eventPlayers as $model1) { $array_identical = false; foreach ($this->player_id as $value) { $array_identical = false; if ($model1->account_id == $value) { if ($this->price[$model1->account_id] == $model1->price) { $array_identical = true; } else { $array_identical = false; } } if ($array_identical === false) { break; } } if ($array_identical === false) { break; } } } if ($array_identical == false) { /* SELECT DISTINCT(pdp.`account_id`) FROM `0af_poker_draft_player` AS pdp INNER JOIN `0af_poker_draft` AS pd ON pd.id = pdp.draft_id WHERE pd.fantasy_id IN(2,3) */ foreach ($this->eventPlayers as $model1) { //echo'<pre>';print_r($model1);echo'</pre>';die; if (!isset($players_in_draft[$model1->account_id])) { $model1->delete(); } } foreach ($this->player_id as $player_id) { if (!isset($players_in_draft[$player_id])) { if ($this->price[$player_id] != 0) { $model_n = new PokerEventPlayer(); $model_n->event_id = $this->id; $model_n->account_id = $player_id; $model_n->price = $this->price[$player_id]; $model_n->save(); // проверяем игроков в статистике. Если такой отсутствует - добавляем. $present = false; foreach ($this->eventPlayerStats as $pokerEventPlayerStat) { if ($pokerEventPlayerStat->account_id == $player_id) { $present = true; } } if ($present === false) { $model_n = new PokerEventPlayerStat(); $model_n->account_id = $player_id; $model_n->event_id = $this->id; $model_n->scores = 0; $model_n->save(); } } else { // если игрока убрали из ивента - удаляем по нему запись о его статистике foreach ($this->eventPlayerStats as $pokerEventPlayerStat) { if ($pokerEventPlayerStat->account_id == $player_id) { $pokerEventPlayerStat->delete(); } } } } } } }
/** * @return \yii\db\ActiveQuery */ public function getEventPlayersList() { return $this->hasMany(PokerEventPlayer::className(), ['event_id' => 'id'])->with('player'); }