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; }
public function listMatchesByDate($tournamentid, DateTime $date, $club_list = array()) { $matchList = $this->queryMatchListWithTournament($tournamentid, Date::getDate($date)); $qmatchList = $this->queryQMatchListWithTournament($tournamentid, Date::getDate($date)); return $this->prepareAndSort($matchList, $qmatchList, $club_list); }
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(); }
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()); }
/** * @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; }
public function setStartSchedule(DateTime $startdate) { $this->date = Date::getDate($startdate); $this->start = Date::getTime($startdate); }
private function updateEvent(EventForm $eventForm, Event &$event) { $event->setEvent($eventForm->getEvent()); $dateformat = $this->get('translator')->trans('FORMAT.DATE'); $eventdate = date_create_from_format($dateformat, $eventForm->getDate()); $event->setDate(Date::getDate($eventdate)); }
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); } } }
/** * @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; }
private function updateNews(NewsForm $newsForm, News &$news) { $news->setNewsno($newsForm->getNewsno()); $news->setNewstype($newsForm->getNewstype()); $news->setLanguage($newsForm->getLanguage()); $news->setTitle($newsForm->getTitle()); $news->setContext($newsForm->getContext()); $dateformat = $this->get('translator')->trans('FORMAT.DATE'); $eventdate = date_create_from_format($dateformat, $newsForm->getDate()); $news->setDate(Date::getDate($eventdate)); }
/** * Return planned tournament schedule * The planTournament function must have been called to generate the match schedule * @param $tournament * @return array */ public function getSchedule(Tournament $tournament) { $matches = array(); $unassigned = array(); $ts = $this->makeTimeslotTable($tournament); $catcnt = array(); $advice = array(); $matchschedules = $this->logic->listMatchSchedules($tournament); /* @var $ms MatchSchedule */ foreach ($matchschedules as $ms) { $match = new MatchPlan(); $this->buildMatchPlan($ms, $match); if ($ms->getPlan()) { $this->prepareMatch($match, $ms->getPlan(), $ts); $matches[] = $match; } else { $match->setMatchno(0); $advice[] = $this->prepareUnassignedMatch($match, $ms->getId(), $ts, $catcnt); $unassigned[] = $match; } } $qmatchschedules = $this->logic->listQMatchSchedules($tournament); /* @var $qms QMatchSchedule */ foreach ($qmatchschedules as $qms) { $match = new QMatchPlan(); $this->buildQMatchPlan($qms, $match); if ($qms->getPlan()) { $this->prepareMatch($match, $qms->getPlan(), $ts); $matches[] = $match; } else { $match->setMatchno(0); $advice[] = $this->prepareUnassignedMatch($match, $qms->getId(), $ts, $catcnt); $unassigned[] = $match; } } usort($matches, function (MatchPlan $match1, MatchPlan $match2) { $p1 = $match1->getDate() - $match2->getDate(); $p2 = $match1->getPlayground()->getNo() - $match2->getPlayground()->getNo(); $p3 = $match1->getTime() - $match2->getTime(); $test = min(1, max(-1, $p1)) * 4 + min(1, max(-1, $p2)) * 2 + min(1, max(-1, $p3)); return min(1, max(-1, $test)); }); $mno = 1; /* @var $match MatchPlan */ foreach ($matches as $match) { $match->setMatchno($mno); $mno++; } usort($ts, function (PA $ats1, PA $ats2) { $p1 = Date::getDate($ats1->getSchedule()) - Date::getDate($ats2->getSchedule()); $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)); }); return array('matches' => $matches, 'unassigned' => $unassigned, 'timeslots' => $ts, 'advices' => $advice, 'unassigned_by_category' => $catcnt); }
public function enrollTeam(Category $category, User $user, Club $club, $name, $division, $vacant = false) { $team = new Team(); $team->setClub($club); $team->setName($name); $team->setColor(''); $team->setDivision($division); $team->setVacant($vacant); $this->em->persist($team); $this->em->flush(); $today = new DateTime(); $enroll = new Enrollment(); $enroll->setTeam($team); $enroll->setCategory($category); $enroll->setUser($user); $enroll->setDate(Date::getDate($today)); $this->em->persist($enroll); $this->em->flush(); return $enroll; }
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()); }
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]); }