/**
  * Update tournament schedule with qualified teams
  * @param $tournamentid
  * @return array
  */
 public function updateTournamentSchedule($tournamentid)
 {
     $groups = $this->map($this->logic->listGroupsByTournament($tournamentid));
     $playgrounds = $this->map($this->logic->listPlaygroundsByTournament($tournamentid));
     $settledGroups = array();
     /* @var $group Group */
     foreach ($groups as $group) {
         $settledGroups[$group->getId()] = $this->order->sortCompletedGroup($group->getId());
     }
     $matches = array();
     $matchList = $this->match->listOpenQMatchesByTournament($tournamentid);
     /* @var $qmatch QMatch */
     foreach ($matchList as $qmatch) {
         $sortedGrpA = $settledGroups[$qmatch->getGroupA()];
         $sortedGrpB = $settledGroups[$qmatch->getGroupB()];
         if ($sortedGrpA && $sortedGrpB) {
             $match = new MatchPlan();
             $match->setMatchno($qmatch->getMatchno());
             $match->setDate($qmatch->getDate());
             $match->setTime($qmatch->getTime());
             $match->setGroup($groups[$qmatch->getPid()]);
             $match->setCategory($match->getGroup()->getCategory());
             $match->setPlayground($playgrounds[$qmatch->getPlayground()]);
             $match->setTeamA($this->getTeam($sortedGrpA[$qmatch->getRankA()]));
             $match->setTeamB($this->getTeam($sortedGrpB[$qmatch->getRankB()]));
             $matches[] = array('Q' => $qmatch, 'M' => $match);
         } else {
             $matches[] = array('Q' => $qmatch, 'M' => null);
         }
     }
     return $matches;
 }
예제 #2
0
 private function prepareUnassignedMatch(MatchPlan $match, $msid, &$ts, &$catcnt)
 {
     $match->setTime('');
     $match->setPlayground(null);
     $match->setDate('');
     $match->setFixed(false);
     $category = $match->getCategory();
     if (isset($catcnt[$category->getId()])) {
         $catcnt[$category->getId()]['matchcount']++;
     } else {
         $catcnt[$category->getId()] = array('category' => $category, 'matchcount' => 1);
     }
     $malts = array();
     /* @var $ma MatchAlternative */
     foreach ($this->logic->listMatchAlternatives($msid) as $ma) {
         $pattr = $ma->getPlaygroundAttribute();
         if (isset($ts[$pattr->getId()])) {
             $malts[] = $ts[$pattr->getId()];
         }
     }
     usort($malts, function (PA $ats1, PA $ats2) {
         $p1 = $ats2->getTimeleft() - $ats1->getTimeleft();
         $p2 = $ats1->getPlayground()->getNo() - $ats2->getPlayground()->getNo();
         $p3 = $ats1->getTimeslot()->getId() - $ats2->getTimeslot()->getId();
         $test = min(1, max(-1, $p1)) * 4 + min(1, max(-1, $p2)) * 2 + min(1, max(-1, $p3));
         return min(1, max(-1, $test));
     });
     $alternatives = array();
     /* @var $alt PA */
     foreach ($malts as $alt) {
         $alternatives[date_format($alt->getSchedule(), "Y/m/d")][] = $alt;
     }
     return array('id' => $msid, 'match' => $match, 'alternatives' => $alternatives);
 }