예제 #1
0
 /**
  * @param Group $group
  * @param PlanningOptions $options
  * @return array
  */
 private function populateGroup(Group $group, PlanningOptions $options)
 {
     $matches = array();
     $teams = $group->getTeams();
     $check = array();
     /* @var $teamA Team */
     foreach ($teams as $teamA) {
         $idx = 0;
         /* @var $teamB Team */
         foreach ($teams as $teamB) {
             if ($teamA->getId() != $teamB->getId() && !isset($check[$teamB->getId()])) {
                 $switch = $idx % 2 == 0 || $options->isDoublematch();
                 $match = new MatchPlan();
                 $match->setTeamA($switch ? $teamA : $teamB);
                 $match->setTeamB($switch ? $teamB : $teamA);
                 $match->setFixed(false);
                 $matches[] = $match;
                 $idx++;
             }
         }
         if (!$options->isDoublematch()) {
             $check[$teamA->getId()] = $teamA;
         }
     }
     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);
 }