/**
  * @param Tournament $tournament
  * @param PlanningResults $results
  */
 public function savePlan(Tournament $tournament, PlanningResults $results)
 {
     /* @var $pa PA */
     foreach ($results->getTimeslots() as $pa) {
         /* @var $match MatchPlan */
         foreach ($pa->getMatchlist() as $match) {
             $ms = $this->makeMatchSchedule($tournament, $match);
             $mp = new MatchSchedulePlan();
             $mp->setPlaygroundAttribute($this->em->merge($pa->getPA()));
             $mp->setMatchstart($match->getTime());
             $mp->setFixed($match->isFixed());
             $ms->setPlan($mp);
             $this->em->persist($ms);
         }
     }
     /* @var $match MatchPlan */
     foreach ($results->getUnresolved() as $match) {
         $ms = $this->makeMatchSchedule($tournament, $match);
         $this->em->persist($ms);
         if (!$match instanceof QMatchPlan) {
             /* @var $pa PA */
             foreach ($results->getTimeslots() as $pa) {
                 /* Both teams must be allowed to play now */
                 if ($results->getTeamCheck()->isCapacity($match, $pa->getSchedule(), $pa->getPlayground(), $pa->getTimeslot())) {
                     $matchAlternative = new MatchAlternative();
                     $matchAlternative->setMatchSchedule($ms);
                     $matchAlternative->setPlaygroundAttribute($this->em->merge($pa->getPA()));
                     $this->em->persist($matchAlternative);
                 }
             }
         }
     }
     $this->em->flush();
 }
 private function commitImport(Tournament $tournament, $matchList)
 {
     $em = $this->getDoctrine()->getManager();
     foreach ($matchList as $match) {
         $matchrec = new MatchSchedule();
         $matchrec->setTournament($tournament);
         $matchrec->setGroup($match['group']);
         $hr = $match['teamA'];
         $hr->setAwayteam(MatchSupport::$HOME);
         $matchrec->addMatchRelation($hr);
         $ar = $match['teamB'];
         $ar->setAwayteam(MatchSupport::$AWAY);
         $matchrec->addMatchRelation($ar);
         $matchPlan = new MatchSchedulePlan();
         $matchPlan->setPlaygroundAttribute($match['pa']);
         $matchPlan->setMatchstart($match['time']);
         $matchPlan->setFixed(true);
         $matchrec->setPlan($matchPlan);
         $em->persist($matchrec);
     }
     $em->flush();
 }
 /**
  * @param MatchPlan $match
  * @param MatchSchedulePlan $plan
  * @param $ts
  */
 private function prepareMatch(MatchPlan $match, MatchSchedulePlan $plan, &$ts)
 {
     $match->setTime($plan->getMatchstart());
     $match->setFixed($plan->isFixed());
     /* @var $pattr PlaygroundAttribute */
     $pattr = $plan->getPlaygroundAttribute();
     $match->setPlayground($pattr->getPlayground());
     $match->setDate($pattr->getDate());
     if (isset($ts[$pattr->getId()])) {
         /* @var $pa PA */
         $pa = $ts[$pattr->getId()];
         $ml = $pa->getMatchList();
         $ml[] = $match;
         $pa->setMatchlist($ml);
         $slotschedule = $match->getSchedule();
         $slotschedule->add(new DateInterval('PT' . $match->getCategory()->getMatchtime() . 'M'));
         $pa->setSchedule($slotschedule);
     }
 }