예제 #1
0
 /**
  * Organize a list of matches into the correct match order for brackets.
  *
  * @param array $matches
  * @return array
  */
 public function organizeBrackets($matches)
 {
     $participants = $this->getParticipants(array(), true);
     $rounds = array();
     foreach ($matches as $match) {
         $round = (int) $match['Match']['round'];
         if (empty($rounds[$round])) {
             $rounds[$round] = array();
         }
         $rounds[$round][] = $match['Match']['id'];
     }
     // Loop through and sort matches
     foreach ($rounds as &$r) {
         sort($r, SORT_NUMERIC);
     }
     ksort($rounds);
     $bracket = new Bracket($this->_event);
     $bracket->setMatches($matches);
     $bracket->setParticipants($participants);
     $bracket->setRounds($rounds);
     return $bracket;
 }
예제 #2
0
 /**
  * Organize a list of matches into the correct match order for brackets.
  *
  * 	- Save a mapping of matches and participants for easy lookup
  * 	- Group all matches into an index of participants per pool
  *
  * @param array $matches
  * @return Bracket
  */
 public function organizeBrackets($matches)
 {
     $participants = $this->getParticipants(array(), true);
     $pools = array();
     $rounds = array();
     foreach ($matches as $match) {
         $home_id = $match['Match']['home_id'];
         $away_id = $match['Match']['away_id'];
         $round = (int) $match['Match']['round'];
         $pool = (int) $match['Match']['pool'];
         // Store match IDs into a pool and round indexed by the participant
         if (empty($pools[$pool][$round][$home_id])) {
             $pools[$pool][$round][$home_id] = array();
         }
         if (empty($pools[$pool][$round][$away_id])) {
             $pools[$pool][$round][$away_id] = array();
         }
         $pools[$pool][$round][$home_id][$match['Match']['order']] = $match['Match']['id'];
         $pools[$pool][$round][$away_id][$match['Match']['order']] = $match['Match']['id'];
         // Store the rounds as a reference
         if (empty($rounds[$round])) {
             $rounds[$round] = array();
         }
         $rounds[$round][] = $match['Match']['id'];
     }
     // Loop through and sort matches
     foreach ($pools as &$p) {
         ksort($p);
         foreach ($p as &$r) {
             foreach ($r as &$m) {
                 ksort($m);
             }
         }
     }
     $bracket = new Bracket($this->_event);
     $bracket->setMatches($matches);
     $bracket->setParticipants($participants);
     $bracket->setPools($pools);
     $bracket->setRounds($rounds, false);
     return $bracket;
 }