/** * Replace match schedule with other matches with same match time * @param PlanningResults $result * @param QMatchPlan $match * @return MatchPlan|null */ private function replanMatch_2run(PlanningResults $result, QMatchPlan $match) { $result->mark(); while ($pa = $result->cycleTimeslot()) { /* Find a candidate for replacement */ $matchlist = $pa->getMatchlist(); /* @var $replan_match QMatchPlan */ foreach ($matchlist as $idx => $replan_match) { /* Both teams must be allowed to play now */ if ($replan_match->getCategory()->getMatchtime() == $match->getCategory()->getMatchtime() && $result->isQScheduleAvailable($match, $replan_match->getSchedule(), $pa->getTimeslot())) { $match->setDate($replan_match->getDate()); $match->setTime($replan_match->getTime()); $match->setPlayground($replan_match->getPlayground()); $matchlist[$idx] = $match; $pa->setMatchlist($matchlist); $result->setQSchedule($match, $replan_match->getSchedule()); $result->resetQSchedule($replan_match); $result->rewind(); return $replan_match; } } } return null; }