Esempio n. 1
0
 public function listMatch()
 {
     if ($this->request->isAjax()) {
         $this->layout = 'ajax';
     }
     if (isset($this->request->data['championship'])) {
         $championship = $this->request->data['championship'];
         //All championship
         $allChampionship = getChampionships();
         //infos championship
         foreach ($allChampionship as $championships) {
             if ($championships['caption'] == $championship) {
                 $thisChampionship = $championships;
                 break;
             }
         }
         if (!isset($this->request->data['home']) && !isset($this->request->data['away']) && !isset($this->request->data['date'])) {
             //All matchs championship
             $matchs = getGamesNoPlay($thisChampionship['fixtures']);
             $homePennant = '';
             $awayPennant = '';
             $colorHomeTeam = '';
             $colorAwayTeam = '';
             $odds = '';
         } else {
             $home = $this->request->data['home'];
             $away = $this->request->data['away'];
             $date = $this->request->data['date'];
             $matchs = '';
             $allTeams = TableRegistry::get('Teams');
             $homeTeam = $allTeams->find()->where(['name' => $home])->first();
             $awayTeam = $allTeams->find()->where(['name' => $away])->first();
             if (!empty($homeTeam)) {
                 $colorHomeTeam = $homeTeam->color;
             } else {
                 $colorHomeTeam = '';
             }
             if (!empty($awayTeam)) {
                 $colorAwayTeam = $awayTeam->color;
             } else {
                 $colorAwayTeam = '';
             }
             //Odds match
             $odds = getOdds($date, $home, $away);
             if (!isset($odds) || empty($odds)) {
                 $odds = '';
             }
             //All teams championship
             $teams = getTeams($thisChampionship['teams']);
             //Pennants
             foreach ($teams as $team) {
                 if ($team['name'] == $home) {
                     $homePennant = $team['pennant'];
                 }
                 if ($team['name'] == $away) {
                     $awayPennant = $team['pennant'];
                 }
                 if (isset($homePennant) && isset($awayPennant)) {
                     break;
                 }
             }
         }
     }
     $output = array('matchs' => $matchs, 'homePennant' => $homePennant, 'awayPennant' => $awayPennant, 'colorHomeTeam' => $colorHomeTeam, 'colorAwayTeam' => $colorAwayTeam, 'odds' => $odds);
     return new Response(['status' => 200, 'body' => json_encode($output, JSON_FORCE_OBJECT)]);
 }
 public function ticket($id, $nbMatch)
 {
     $tickets = TableRegistry::get('Tickets');
     $prognostics = TableRegistry::get('Prognostics');
     //The ticket focus
     $ticket = $tickets->find()->where(['id' => $id])->first();
     if (!isset($ticket)) {
         return $this->redirect(['controller' => 'Pages', 'action' => 'page404']);
     }
     //List ticket's matchs today
     $matchs = $prognostics->find()->where(['n_ticket' => $ticket->id])->order(['date_match' => 'ASC']);
     $matchSelected = substr($nbMatch, 5);
     //Match Selected
     foreach ($matchs as $key => $ticketMatch) {
         if ($key == 0) {
             $firstMatch = $ticketMatch;
         }
         if ($key == $matchSelected - 1) {
             $match = $ticketMatch;
             break;
         }
     }
     if (!isset($match)) {
         return $this->redirect(['controller' => 'Pages', 'action' => 'page404']);
     }
     //All championship
     $allChampionship = getChampionships();
     //$championship of the match
     foreach ($allChampionship as $championship) {
         if ($championship['caption'] == $match['competition']) {
             $thisChampionship = $championship;
             break;
         }
     }
     //All matchs championship
     $allMatchsChampionship = getGames($thisChampionship['fixtures']);
     //Match's stats between the teams
     foreach ($allMatchsChampionship as $matchChampionship) {
         if ($matchChampionship['homeTeamName'] == $match['home_team'] && $matchChampionship['awayTeamName'] == $match['away_team']) {
             $matchStats = $matchChampionship['showdown'];
             break;
         }
     }
     //Last match between the teams
     $lastMatchs = getStatsMatch($matchStats);
     //All teams championship
     $allTeamsChampionship = getTeams($thisChampionship['teams']);
     //Team's stats
     foreach ($allTeamsChampionship as $teamChampionship) {
         if ($teamChampionship['name'] == $match['home_team']) {
             $homeTeamStats = $teamChampionship;
         }
         if ($teamChampionship['name'] == $match['away_team']) {
             $awayTeamStats = $teamChampionship;
         }
     }
     //Ranking of the match
     $ranking = getRanking($thisChampionship['leagueTable'], $thisChampionship['teams'], $thisChampionship['fixtures']);
     if (!empty($ranking)) {
         foreach ($ranking as $team) {
             if (!is_array($team)) {
                 if (!empty($homeTeamStats['fixtures'])) {
                     //Home last matchs
                     $homeLastMatchs = getLastMatchs($homeTeamStats['fixtures'], $thisChampionship['championship'], $team, $thisChampionship['teams']);
                     $this->set('homeLastMatchs', $homeLastMatchs);
                 }
                 if (!empty($awayTeamStats['fixtures'])) {
                     //Home last matchs
                     $awayLastMatchs = getLastMatchs($awayTeamStats['fixtures'], $thisChampionship['championship'], $team, $thisChampionship['teams']);
                     $this->set('awayLastMatchs', $awayLastMatchs);
                 }
                 break;
             }
         }
         $this->set('ranking', $ranking);
     }
     $this->set('firstMatch', $firstMatch);
     $this->set('match', $match);
     $this->set('lastMatchs', $lastMatchs);
     $this->set('homeTeamStats', $homeTeamStats);
     $this->set('awayTeamStats', $awayTeamStats);
     $this->set('matchs', $matchs);
     $this->set('ticket', $ticket);
 }