Beispiel #1
1
 public function recalculateTable()
 {
     $teamList = team::getAllTeams();
     foreach ($teamList as $team) {
         $this->teams[$team->id]['name'] = $team->name;
         $this->teams[$team->id]['point'] = 0;
         $this->teams[$team->id]['played'] = 0;
         $this->teams[$team->id]['win'] = 0;
         $this->teams[$team->id]['draw'] = 0;
         $this->teams[$team->id]['loose'] = 0;
         $this->teams[$team->id]['average'] = 0;
     }
     $matches = match::getAllMatchs();
     foreach ($matches as $match) {
         if ($match->score->firstTeam == null || $match->score->secondTeam == null) {
             continue;
         }
         $this->teams[$match->team1]['played']++;
         $this->teams[$match->team2]['played']++;
         if ($match->score->winner === 1) {
             $this->teams[$match->team1]['win']++;
             $this->teams[$match->team2]['loose']++;
             $this->teams[$match->team1]['point'] += 3;
         } else {
             if ($match->score->winner === 2) {
                 $this->teams[$match->team1]['loose']++;
                 $this->teams[$match->team2]['win']++;
                 $this->teams[$match->team2]['point'] += 3;
             } else {
                 $this->teams[$match->team1]['draw']++;
                 $this->teams[$match->team2]['draw']++;
                 $this->teams[$match->team1]['point']++;
                 $this->teams[$match->team2]['point']++;
             }
         }
         $average = $match->score->firstTeam - $match->score->secondTeam;
         $this->teams[$match->team1]['average'] += $average;
         $this->teams[$match->team2]['average'] -= $average;
     }
 }
 protected function prepareFixture()
 {
     $teams = team::getAllTeams();
     $teamCount = count($teams);
     $matchs = array();
     // tüm maç olasılıklarını çıkarıyoruz
     for ($i = 0; $i < $teamCount; $i++) {
         for ($j = 0; $j < $i; $j++) {
             if ($i == $j) {
                 continue;
             }
             $matchs[] = new match($teams[$i], $teams[$j]);
         }
     }
     // maçlar rasgele gelsin diye karıştırıyoruz
     shuffle($matchs);
     // hafta sayısı kadar dönücez (takım sayısının yarısı)
     for ($week = 1; $week <= $teamCount - 1; $week++) {
         // her hafta maçlar belirlendikçe takımları buraya ekliyicem
         $weekTeams = array();
         $timeout = 0;
         //maçlara tek tek bakıyoruz tüm takımları kullanana kadar
         while (count($weekTeams) != $teamCount) {
             $timeout++;
             foreach ($matchs as $key => $thematch) {
                 //o hafta takımlar seçiliyse atla
                 if (!isset($weekTeams[$thematch->team1->id]) && !isset($weekTeams[$thematch->team2->id])) {
                     $weekTeams[$thematch->team1->id] = true;
                     $weekTeams[$thematch->team2->id] = true;
                     $thematch->insertMatch($week);
                     //maçlar listemden o maçı kaldırıyorum ki tekrar seçmeyelim
                     unset($matchs[$key]);
                 }
                 // o hafta için tüm takımlar seçildi mi
                 // if(count($weekTeams) == count($teams)) break;
             }
             if ($timeout > 50) {
                 break;
             }
         }
         unset($weekTeams);
     }
     // tüm maçları yerleştiremeyip döngüden çıkmak zorunda kalırsa false
     if (count($matchs) > 0) {
         return false;
     } else {
         return true;
     }
 }