private function makeMatchSchedule(Tournament $tournament, MatchPlan $match) { // for QMatchPlan, group and team are undefined - use classification and litra instead if ($match instanceof QMatchPlan) { /* @var $match QMatchPlan */ $ms = new QMatchSchedule(); $ms->setTournament($tournament); $ms->setCategory($this->em->merge($match->getCategory())); $ms->setBranch(''); $ms->setClassification($match->getClassification()); $ms->setLitra($match->getLitra()); $hr = new QMatchScheduleRelation(); $hr->setBranch($match->getRelA()->getBranch()); $hr->setClassification($match->getRelA()->getClassification()); $hr->setLitra($match->getRelA()->getLitra()); $hr->setRank($match->getRelA()->getRank()); $hr->setAwayteam(false); $ms->addQMatchRelation($hr); $ar = new QMatchScheduleRelation(); $ar->setBranch($match->getRelB()->getBranch()); $ar->setClassification($match->getRelB()->getClassification()); $ar->setLitra($match->getRelB()->getLitra()); $ar->setRank($match->getRelB()->getRank()); $ar->setAwayteam(true); $ms->addQMatchRelation($ar); } else { $ms = new MatchSchedule(); $ms->setTournament($tournament); $ms->setGroup($this->em->merge($match->getGroup())); $hr = new MatchScheduleRelation(); $hr->setTeam($this->em->merge($match->getTeamA())); $hr->setAwayteam(false); $ms->addMatchRelation($hr); $ar = new MatchScheduleRelation(); $ar->setTeam($this->em->merge($match->getTeamB())); $ar->setAwayteam(true); $ms->addMatchRelation($ar); } return $ms; }
/** * Check if two match records share the same team * @param MatchPlan $match * @param MatchPlan $replanMatch * @return bool */ private function teamsMatch(MatchPlan $match, MatchPlan $replanMatch) { return $match->getTeamA()->getId() == $replanMatch->getTeamA()->getId() || $match->getTeamA()->getId() == $replanMatch->getTeamB()->getId() || $match->getTeamB()->getId() == $replanMatch->getTeamA()->getId() || $match->getTeamB()->getId() == $replanMatch->getTeamB()->getId(); }
/** * Test match for schedule availability * Different rules may apply: * 1. within each timeslot teams may play one or more times each day * 2. if timeslot allows more games each day then a rest period must be allowed between each match * 3. if timeslot allows more games each day and penalty for different sites is selected only one site is allowed for these matches * 4. No two matches can be played at the same time * @param MatchPlan $match match to be verified - each team for this match will be verified individually * @param DateTime $slotschedule the schedule to test for availablity * @param Playground $playground the planned playground for the scheduled match * @param Timeslot $timeslot the planned timeslot for the scheduled match * @return bool true if schedule is available for the planned playground and timeslot */ public function isCapacity(MatchPlan $match, DateTime $slotschedule, Playground $playground, Timeslot $timeslot) { $tac = $this->isTeamCapacity($match->getTeamA(), $slotschedule, $playground, $timeslot); $tab = $this->isTeamCapacity($match->getTeamB(), $slotschedule, $playground, $timeslot); return $tac && $tab; }