예제 #1
0
 /**
  * проверяем изменения в игроках
  */
 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();
                         }
                     }
                 }
             }
         }
     }
 }