/** * Test team for schedule availability * Different rules may apply: * 1. within each timeslot a team 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 Team $team the team to be verified * @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 */ private function isTeamCapacity(Team $team, DateTime $slotschedule, Playground $playground, Timeslot $timeslot) { $date = Date::getDate($slotschedule); $time = Date::getTime($slotschedule); $key = $this->makeKey($team, $date, $timeslot); if (isset($this->teams[$key])) { if (count($this->teams[$key]) < $timeslot->getCapacity() && !isset($this->teams[$key][$time])) { /* @var $match MatchPlan */ foreach ($this->teams[$key] as $match) { /* @var $diff DateInterval */ $diff = $match->getSchedule()->diff($slotschedule); if ($diff->h * 60 + $diff->i < $team->getCategory()->getMatchtime() + $timeslot->getRestperiod()) { return false; } if ($timeslot->getPenalty() && $match->getPlayground()->getSite()->getId() != $playground->getSite()->getId()) { return false; } } return true; } return false; } $this->teams[$key] = array(); return $timeslot->getCapacity() > 0; }
private function copyPlayground(Playground $source_playground, Playground $target_playground) { $em = $this->getDoctrine()->getManager(); /* @var $attr PlaygroundAttribute */ foreach ($source_playground->getPlaygroundAttributes() as $attr) { if ($this->get('logic')->getPlaygroundAttribute($target_playground->getId(), $attr->getDate(), $attr->getStart()) == null) { $target_attr = new PlaygroundAttribute(); $target_attr->setPlayground($target_playground); $target_attr->setTimeslot($attr->getTimeslot()); $target_attr->setDate($attr->getDate()); $target_attr->setStart($attr->getStart()); $target_attr->setEnd($attr->getEnd()); $target_attr->setFinals($attr->getFinals()); $em->persist($target_attr); } } $em->flush(); }
private function checkForm($form, Playground $playground) { if ($form->isValid()) { if ($playground->getName() == null || trim($playground->getName()) == '') { $form->addError(new FormError($this->get('translator')->trans('FORM.PLAYGROUND.NONAME', array(), 'admin'))); } if ($playground->getNo() == null || trim($playground->getNo()) == '') { $form->addError(new FormError($this->get('translator')->trans('FORM.PLAYGROUND.NONO', array(), 'admin'))); } if ($playground->getLocation() == null) { $playground->setLocation(''); } } return $form->isValid(); }
public function makePlaygrounds(Tournament $tournament) { for ($s = 1; $s <= 2; $s++) { $site = new Site(); $site->setName("Test site " . $s); $site->setTournament($tournament); for ($n = 1; $n <= 2; $n++) { $playground = new Playground(); $playground->setName("Test playground " . $s . "-" . $n); $playground->setLocation(""); $playground->setNo($n); $playground->setSite($site); $site->getPlaygrounds()->add($playground); } $tournament->getSites()->add($site); $this->em->persist($site); } $timeslot = new Timeslot(); $timeslot->setName("Period AM"); $timeslot->setTournament($tournament); $timeslot->setCapacity(2); $timeslot->setPenalty(true); $timeslot->setRestperiod(60); $tournament->getTimeslots()->add($timeslot); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "5-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "5-7-2015 12.00"), false); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "6-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "6-7-2015 12.00"), false); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "7-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "7-7-2015 12.00"), false); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "8-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "8-7-2015 12.00"), true); $this->em->persist($timeslot); $timeslot = new Timeslot(); $timeslot->setName("Period PM"); $timeslot->setTournament($tournament); $timeslot->setCapacity(1); $timeslot->setPenalty(false); $timeslot->setRestperiod(60); $tournament->getTimeslots()->add($timeslot); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "5-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "5-7-2015 19.00"), false); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "6-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "6-7-2015 19.00"), false); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "7-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "7-7-2015 19.00"), false); $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "8-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "8-7-2015 22.00"), true); $this->em->persist($timeslot); $this->em->flush(); }
private function importPAttrs(Playground $playground, Playground $new_playground, array $tsconversion, array $cconversion) { $em = $this->getDoctrine()->getManager(); foreach ($playground->getPlaygroundAttributes() as $pattr) { $new_pattr = new PlaygroundAttribute(); $new_pattr->setPlayground($new_playground); $new_pattr->setTimeslot($tsconversion[$pattr->getTimeslot()->getId()]); $new_pattr->setDate($pattr->getDate()); $new_pattr->setStart($pattr->getStart()); $new_pattr->setEnd($pattr->getEnd()); $new_pattr->setFinals($pattr->getFinals()); foreach ($pattr->getCategories() as $category) { $new_pattr->getCategories()->add($cconversion[$category->getId()]); } $em->persist($new_pattr); } $em->flush(); }