/**
  * 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;
 }