コード例 #1
0
 private function commitImport($parseObj, $date)
 {
     $matchdate = date_create_from_format($this->get('translator')->trans('FORMAT.DATE'), $date);
     $matchtime = date_create_from_format($this->get('translator')->trans('FORMAT.TIME'), $parseObj['time']);
     if ($matchdate === false || $matchtime === false) {
         throw new ValidationException("BADDATE", "date=" . $date . " time=" . $parseObj['time']);
     }
     $matchrec = new Match();
     $matchrec->setMatchno($parseObj['id']);
     $matchrec->setDate(Date::getDate($matchdate));
     $matchrec->setTime(Date::getTime($matchtime));
     $matchrec->setGroup($parseObj['group']);
     $matchrec->setPlayground($parseObj['playground']);
     $resultreqA = new MatchRelation();
     $resultreqA->setTeam($parseObj['teamA']);
     $resultreqA->setAwayteam(false);
     $resultreqA->setScorevalid(false);
     $resultreqA->setScore(0);
     $resultreqA->setPoints(0);
     $matchrec->addMatchRelation($resultreqA);
     $resultreqB = new MatchRelation();
     $resultreqB->setTeam($parseObj['teamB']);
     $resultreqB->setAwayteam(true);
     $resultreqB->setScorevalid(false);
     $resultreqB->setScore(0);
     $resultreqB->setPoints(0);
     $matchrec->addMatchRelation($resultreqB);
     $em = $this->getDoctrine()->getManager();
     $em->persist($matchrec);
     $em->flush();
 }
コード例 #2
0
 private function validateData(Tournament $tournament, $matchListRaw)
 {
     $matchList = array();
     foreach ($matchListRaw as $matchRaw) {
         /* @var $playground Playground */
         $playground = $this->get('logic')->getPlaygroundByNo($tournament->getId(), $matchRaw['playground']);
         if ($playground == null) {
             throw new ValidationException("BADPLAYGROUND", "tournament=" . $tournament->getId() . " no=" . $matchRaw['playground']);
         }
         $group = $this->get('logic')->getGroupByCategory($tournament->getId(), $matchRaw['category'], $matchRaw['group']);
         if ($group == null) {
             throw new ValidationException("BADGROUP", "tournament=" . $tournament->getId() . " category=" . $matchRaw['category'] . " group=" . $matchRaw['group']);
         }
         $matchdate = date_create_from_format($this->get('translator')->trans('FORMAT.DATE'), $matchRaw['date']);
         $matchtime = date_create_from_format($this->get('translator')->trans('FORMAT.TIME'), $matchRaw['time']);
         if ($matchdate === false || $matchtime === false) {
             throw new ValidationException("BADDATE", "date=" . $matchRaw['date'] . " time=" . $matchRaw['time']);
         }
         $date = Date::getDate($matchdate);
         $time = Date::getTime($matchtime);
         $paList = $playground->getPlaygroundAttributes();
         $pattr = null;
         foreach ($paList as $pa) {
             if ($pa->getDate() == $date && $pa->getStart() <= $time && $pa->getEnd() >= $time) {
                 $pattr = $pa;
                 break;
             }
         }
         if (!$pattr) {
             throw new ValidationException("BADDATE", "No playground attribute for date=" . $matchRaw['date']);
         }
         $teamA = $this->getTeam($group->getId(), $matchRaw['teamA']);
         $teamB = $this->getTeam($group->getId(), $matchRaw['teamB']);
         $match = array('matchno' => $matchRaw['matchno'], 'date' => $date, 'time' => $time, 'pa' => $pattr, 'category' => $matchRaw['category'], 'group' => $group, 'playground' => $playground, 'teamA' => $teamA, 'teamB' => $teamB);
         $matchList[] = $match;
     }
     return $matchList;
 }
コード例 #3
0
 private function updatePAttr(PAttrForm $pattrForm, PlaygroundAttribute &$pattr)
 {
     $timeslotid = $pattrForm->getTimeslot();
     $pattr->setTimeslot($this->get('entity')->getTimeslotById($timeslotid));
     $dateformat = $this->get('translator')->trans('FORMAT.DATE');
     $matchdate = date_create_from_format($dateformat, $pattrForm->getDate());
     $pattr->setDate(Date::getDate($matchdate));
     $timeformat = $this->get('translator')->trans('FORMAT.TIME');
     $starttime = date_create_from_format($timeformat, $pattrForm->getStart());
     $pattr->setStart(Date::getTime($starttime));
     $endtime = date_create_from_format($timeformat, $pattrForm->getEnd());
     $pattr->setEnd(Date::getTime($endtime));
     $pattr->setFinals($pattrForm->isFinals());
 }
コード例 #4
0
 /**
  * @param PlanningResults $result
  * @param MatchPlan $match
  * @return boolean
  */
 private function replanMatch_1run(PlanningResults $result, MatchPlan $match)
 {
     // Sort playground attributes and prepare for inspection
     $result->mark(function (PlaygroundAttribute $ats1, PlaygroundAttribute $ats2) {
         $p1 = $ats2->getTimeleft() - $ats1->getTimeleft();
         $p2 = $ats1->getPA()->getStartSchedule()->getTimestamp() - $ats2->getPA()->getStartSchedule()->getTimestamp();
         $test = min(1, max(-1, $p1)) * 2 + min(1, max(-1, $p2));
         return min(1, max(-1, $test));
     });
     $matchtime = $match->getCategory()->getMatchtime();
     while ($pa = $result->cycleTimeslot()) {
         /* @var $slotschedule DateTime */
         $slotschedule = $pa->getSchedule();
         $date = Date::getDate($slotschedule);
         $time = Date::getTime($slotschedule);
         $slot_time_left = $pa->getTimeleft();
         if ($matchtime <= $slot_time_left) {
             /* Both teams must be allowed to play now */
             if ($result->getTeamCheck()->isCapacity($match, $slotschedule, $pa->getPlayground(), $pa->getTimeslot())) {
                 $match->setDate($date);
                 $match->setTime($time);
                 $match->setPlayground($pa->getPlayground());
                 $slotschedule->add(new DateInterval('PT' . $matchtime . 'M'));
                 $pa->setSchedule($slotschedule);
                 $matchlist = $pa->getMatchlist();
                 $matchlist[] = $match;
                 $pa->setMatchlist($matchlist);
                 $result->getTeamCheck()->reserveCapacity($match, $pa->getTimeslot());
                 $result->rewind();
                 return true;
             }
         }
     }
     return false;
 }
コード例 #5
0
 public function setEndSchedule(DateTime $enddate)
 {
     $this->end = Date::getTime($enddate);
 }
コード例 #6
0
 /**
  * @param PlanningResults $result
  * @param QMatchPlan $match
  * @param bool $replan
  * @return bool
  */
 private function replanMatch_1run(PlanningResults $result, QMatchPlan $match)
 {
     $result->mark(function (PlaygroundAttribute $ats1, PlaygroundAttribute $ats2) {
         $p1 = $ats2->getTimeleft() - $ats1->getTimeleft();
         $p2 = $ats1->getPA()->getStartSchedule()->getTimestamp() - $ats2->getPA()->getStartSchedule()->getTimestamp();
         $test = min(1, max(-1, $p1)) * 2 + min(1, max(-1, $p2));
         return min(1, max(-1, $test));
     });
     /*
            // Sort by playground asc, match start asc, time left desc,
             function (PlaygroundAttribute $ats1, PlaygroundAttribute $ats2) {
                $p1 = $ats1->getPA()->getStartSchedule()->getTimestamp() - $ats2->getPA()->getStartSchedule()->getTimestamp();
                $p2 = $ats2->getTimeleft() - $ats1->getTimeleft();
                $p3 = $ats1->getPlayground()->getNo() - $ats2->getPlayground()->getNo();
                $test = min(1, max(-1, $p1))*4 + min(1, max(-1, $p2))*2 + min(1, max(-1, $p3));
                return min(1, max(-1, $test));
            }
     */
     $matchtime = $match->getCategory()->getMatchtime();
     /* @var $pa PA */
     while ($pa = $result->cycleTimeslot()) {
         $slotschedule = $pa->getSchedule();
         $slot_time_left = $pa->getTimeleft();
         while ($matchtime <= $slot_time_left) {
             if ($result->isQScheduleAvailable($match, $slotschedule, $pa->getTimeslot())) {
                 $match->setDate(Date::getDate($slotschedule));
                 $match->setTime(Date::getTime($slotschedule));
                 $match->setPlayground($pa->getPlayground());
                 $slotschedule->add(new DateInterval('PT' . $matchtime . 'M'));
                 $pa->setSchedule($slotschedule);
                 $matchlist = $pa->getMatchlist();
                 $matchlist[] = $match;
                 $pa->setMatchlist($matchlist);
                 $result->setQSchedule($match, $match->getSchedule());
                 $result->rewind();
                 return true;
             }
             $slotschedule->add(new DateInterval('PT' . $matchtime . 'M'));
             $slot_time_left -= $matchtime;
         }
     }
     return false;
 }
コード例 #7
0
 private function addSchedules(Tournament $tournament, Timeslot $timeslot, DateTime $start, DateTime $end, $final)
 {
     /* @var $site Site */
     foreach ($tournament->getSites() as $site) {
         /* @var $playground Playground */
         foreach ($site->getPlaygrounds() as $playground) {
             $pattr = new PlaygroundAttribute();
             $pattr->setTimeslot($timeslot);
             $pattr->setPlayground($playground);
             $pattr->setDate(Date::getDate($start));
             $pattr->setStart(Date::getTime($start));
             $pattr->setEnd(Date::getTime($end));
             $pattr->setFinals($final);
             $playground->getPlaygroundAttributes()->add($pattr);
             $timeslot->getPlaygroundattributes()->add($pattr);
         }
     }
 }
コード例 #8
0
 private function updateMatch(MatchForm $matchForm, Match &$match)
 {
     $match->setMatchno($matchForm->getMatchno());
     $dateformat = $this->get('translator')->trans('FORMAT.DATE');
     $matchdate = date_create_from_format($dateformat, $matchForm->getDate());
     $match->setDate(Date::getDate($matchdate));
     $timeformat = $this->get('translator')->trans('FORMAT.TIME');
     $matchtime = date_create_from_format($timeformat, $matchForm->getTime());
     $match->setTime(Date::getTime($matchtime));
     $match->setPlayground($matchForm->getPlayground());
 }
コード例 #9
0
ファイル: TeamCheck.php プロジェクト: armandomeeuwenoord/icup
 private function freeTeamCapacity(Team $team, MatchPlan $match, Timeslot $timeslot)
 {
     $date = Date::getDate($match->getSchedule());
     $time = Date::getTime($match->getSchedule());
     $key = $this->makeKey($team, $date, $timeslot);
     unset($this->teams[$key][$time]);
 }