示例#1
0
 /**
  * Build list of matches (elimination rounds) for tournament
  * @param Tournament $tournament
  * @return array
  */
 public function populate(Tournament $tournament)
 {
     $matchPlanList = array();
     /* @var $category Category */
     foreach ($tournament->getCategories() as $category) {
         $matches = array();
         switch ($category->getStrategy()) {
             case 0:
                 $matches = $this->populateAB($category);
                 break;
             case 1:
                 $matches = $this->populateType1($category);
                 break;
             case 2:
                 $matches = $this->populateType2($category);
                 break;
             case 3:
                 $matches = $this->populateType3($category);
                 break;
         }
         /* @var $match QMatchPlan */
         foreach ($matches as $match) {
             $match->setCategory($category);
             $matchPlanList[] = $match;
         }
     }
     return $matchPlanList;
 }
示例#2
0
 /**
  * Build list of matches (preliminary rounds) for tournament
  * @param Tournament $tournament
  * @param PlanningOptions $options
  * @return array
  */
 public function populate(Tournament $tournament, PlanningOptions $options)
 {
     $matchPlanList = array();
     /* @var Category $category */
     foreach ($tournament->getCategories() as $category) {
         /* @var $group Group */
         foreach ($category->getGroupsClassified(Group::$PRE) as $group) {
             $matches = $this->populateGroup($group, $options);
             /* @var $match MatchPlan */
             foreach ($matches as $match) {
                 $match->setCategory($category);
                 $match->setGroup($group);
                 $matchPlanList[] = $match;
             }
         }
     }
     return $matchPlanList;
 }
 private function listEnrolled(Tournament $tmnt, Club $club)
 {
     $host = $tmnt->getHost();
     $enrolled = $this->get('logic')->listEnrolledByClub($tmnt->getId(), $club->getId());
     $enrolledList = array();
     /* @var $enroll Enrollment */
     foreach ($enrolled as $enroll) {
         $enrolledList[$enroll->getCategory()->getId()][] = $enroll;
     }
     $classMap = array();
     $categoryMap = array();
     /* @var $category Category */
     foreach ($tmnt->getCategories() as $category) {
         $classification = $category->getClassification() . $category->getAge();
         $classMap[$classification] = $classification;
         $cls = $category->getGender() . $classification;
         $categoryMap[$cls][] = $category;
     }
     return array('host' => $host, 'tournament' => $tmnt, 'club' => $club, 'classifications' => $classMap, 'enrolled' => $enrolledList, 'categories' => $categoryMap);
 }
示例#4
0
 /**
  * @param Tournament $tournament
  * @param $matchList
  * @param PlanningOptions $options
  * @return PlanningResults
  */
 public function setupCriteria(Tournament $tournament, $matchList, PlanningOptions $options)
 {
     $result = new PlanningResults();
     /* @var $timeslot Timeslot */
     foreach ($tournament->getTimeslots()->toArray() as $timeslot) {
         /* @var $pattr PlaygroundAttribute */
         foreach ($timeslot->getPlaygroundattributes()->toArray() as $pattr) {
             if ($pattr->getFinals() == $options->isFinals()) {
                 $pa = new PA();
                 $pa->setPA($pattr);
                 $pa->setId($pattr->getId());
                 $pa->setPlayground($pattr->getPlayground());
                 $pa->setTimeslot($pattr->getTimeslot());
                 $pa->setSchedule($pattr->getStartSchedule());
                 $categories = array();
                 foreach ($pattr->getCategories() as $category) {
                     $categories[$category->getId()] = $category;
                 }
                 $pa->setCategories($categories);
                 $pa->setMatchlist(array());
                 $result->addTimeslot($pa);
             }
         }
     }
     if ($options->isFinals()) {
         // Order the match plan by classification ascending
         usort($matchList, function (QMatchPlan $m1, QMatchPlan $m2) {
             return min(1, max(-1, $m1->getClassification() - $m2->getClassification()));
         });
     } else {
         // Order the match plan by group ascending
         usort($matchList, function (MatchPlan $m1, MatchPlan $m2) {
             return min(1, max(-1, $m1->getGroup()->getId() - $m2->getGroup()->getId()));
         });
     }
     foreach ($matchList as $match) {
         $result->appendUnresolved($match);
     }
     return $result;
 }
 private function makeResultForm(Tournament $tournament)
 {
     $categories = array();
     foreach ($tournament->getCategories() as $category) {
         $categories[$category->getId()] = $this->get('translator')->trans('CATEGORY', array(), 'tournament') . " " . $category->getName() . " - " . $this->get('translator')->transChoice('GENDER.' . $category->getGender() . $category->getClassification(), $category->getAge(), array('%age%' => $category->getAge()), 'tournament');
     }
     $playgroundList = $this->get('logic')->listPlaygroundsByTournament($tournament->getId());
     $playgrounds = array();
     foreach ($playgroundList as $playground) {
         $playgrounds[$playground->getId()] = $playground->getName();
     }
     $formDef = $this->createFormBuilder();
     $formDef->add('matchno', 'text', array('label' => 'FORM.MATCHPLANNING.MATCHNO', 'required' => false, 'help' => 'FORM.MATCHPLANNING.HELP.MATCHNO', 'icon' => 'fa fa-lg fa-tag', 'translation_domain' => 'admin'));
     $formDef->add('date', 'text', array('label' => 'FORM.MATCHPLANNING.DATE', 'required' => false, 'help' => 'FORM.MATCHPLANNING.HELP.DATE', 'icon' => 'fa fa-lg fa-calendar', 'translation_domain' => 'admin'));
     $formDef->add('category', 'choice', array('label' => 'FORM.MATCHPLANNING.CATEGORY', 'choices' => $categories, 'empty_value' => 'FORM.MATCHPLANNING.DEFAULT', 'required' => false, 'help' => 'FORM.MATCHPLANNING.HELP.CATEGORY', 'icon' => 'fa fa-lg fa-sitemap', 'translation_domain' => 'admin'));
     $formDef->add('group', 'choice', array('label' => 'FORM.MATCHPLANNING.GROUP', 'choices' => array(), 'empty_value' => 'FORM.MATCHPLANNING.DEFAULT', 'required' => false, 'help' => 'FORM.MATCHPLANNING.HELP.GROUP', 'icon' => 'fa fa-lg fa-bookmark', 'translation_domain' => 'admin'));
     $formDef->add('playground', 'choice', array('label' => 'FORM.MATCHPLANNING.PLAYGROUND', 'choices' => $playgrounds, 'empty_value' => 'FORM.MATCHPLANNING.DEFAULT', 'required' => false, 'help' => 'FORM.MATCHPLANNING.HELP.PLAYGROUND', 'icon' => 'fa fa-lg fa-futbol-o', 'translation_domain' => 'admin'));
     return $formDef->getForm();
 }
示例#6
0
 public function updatePoints(Tournament $tournament, &$relA, &$relB)
 {
     $looserPoints = $tournament->getOption()->getLpoints();
     $tiePoints = $tournament->getOption()->getTpoints();
     $winnerPoints = $tournament->getOption()->getWpoints();
     if ($relA->getScore() > $relB->getScore()) {
         $relA->setPoints($winnerPoints);
         $relB->setPoints($looserPoints);
     } else {
         if ($relA->getScore() < $relB->getScore()) {
             $relA->setPoints($looserPoints);
             $relB->setPoints($winnerPoints);
         } else {
             $relA->setPoints($tiePoints);
             $relB->setPoints($tiePoints);
         }
     }
 }
 private function makePAttrForm(PAttrForm $pattrForm, Tournament $tournament, $action)
 {
     $timeslots = array();
     foreach ($tournament->getTimeslots() as $timeslot) {
         $timeslots[$timeslot->getId()] = $timeslot->getName();
     }
     $formDef = $this->createFormBuilder($pattrForm);
     $formDef->add('timeslot', 'choice', array('label' => 'FORM.PLAYGROUNDATTR.TIMESLOT.PROMPT', 'help' => 'FORM.PLAYGROUNDATTR.TIMESLOT.HELP', 'choices' => $timeslots, 'empty_value' => 'FORM.PLAYGROUNDATTR.DEFAULT', 'required' => false, 'disabled' => $action == 'del', 'translation_domain' => 'admin'));
     $formDef->add('date', 'text', array('label' => 'FORM.PLAYGROUNDATTR.DATE.PROMPT', 'help' => 'FORM.PLAYGROUNDATTR.DATE.HELP', 'required' => false, 'disabled' => $action == 'del', 'translation_domain' => 'admin'));
     $formDef->add('start', 'text', array('label' => 'FORM.PLAYGROUNDATTR.START.PROMPT', 'help' => 'FORM.PLAYGROUNDATTR.START.HELP', 'required' => false, 'disabled' => $action == 'del', 'translation_domain' => 'admin'));
     $formDef->add('end', 'text', array('label' => 'FORM.PLAYGROUNDATTR.END.PROMPT', 'help' => 'FORM.PLAYGROUNDATTR.END.HELP', 'required' => false, 'disabled' => $action == 'del', 'translation_domain' => 'admin'));
     $formDef->add('finals', 'checkbox', array('label' => 'FORM.PLAYGROUNDATTR.FINALS.PROMPT', 'help' => 'FORM.PLAYGROUNDATTR.FINALS.HELP', 'required' => false, 'disabled' => $action == 'del', 'translation_domain' => 'admin'));
     $formDef->add('cancel', 'submit', array('label' => 'FORM.PLAYGROUNDATTR.CANCEL.' . strtoupper($action), 'translation_domain' => 'admin', 'buttontype' => 'btn btn-default', 'icon' => 'fa fa-times'));
     $formDef->add('save', 'submit', array('label' => 'FORM.PLAYGROUNDATTR.SUBMIT.' . strtoupper($action), 'translation_domain' => 'admin', 'icon' => 'fa fa-check'));
     return $formDef->getForm();
 }
 private function validateData(Tournament $tournament, &$parseObj)
 {
     $match = $this->get('match')->getMatchByNo($tournament->getId(), $parseObj['id']);
     if ($match == null) {
         throw new ValidationException("BADMATCH", "tournament=" . $tournament->getId() . " match=" . $parseObj['id']);
     }
     $qmh = $this->get('match')->getQMatchRelationByMatch($match->getId(), false);
     $teamA = $this->getTeam($qmh->getGroup(), $parseObj, 'teamA');
     $qma = $this->get('match')->getQMatchRelationByMatch($match->getId(), true);
     $teamB = $this->getTeam($qma->getGroup(), $parseObj, 'teamB');
     $parseObj['match'] = $match;
     $parseObj['teamA'] = $teamA;
     $parseObj['teamB'] = $teamB;
 }
 public function listChampionsByTournament(Tournament $tournament)
 {
     $sortedGroups = array();
     $teams = array();
     /* @var $category Category */
     foreach ($tournament->getCategories() as $category) {
         /* @var $champion Champion */
         foreach ($category->getChampions() as $champion) {
             $groupid = $champion->getGroup()->getId();
             if (!isset($sortedGroups[$groupid])) {
                 $sortedGroups[$groupid] = $this->container->get('orderTeams')->sortCompletedGroup($groupid);
             }
             $rankedTeams = $sortedGroups[$groupid];
             if ($rankedTeams && isset($rankedTeams[$champion->getRank() - 1])) {
                 $team = $this->entity->getTeamById($rankedTeams[$champion->getRank() - 1]->getId());
                 $teams[$category->getId()][$champion->getChampion()] = $team;
             }
         }
     }
     return $teams;
 }
示例#10
0
 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);
         }
     }
 }
示例#11
0
 private function makeTimeslotTable(Tournament $tournament)
 {
     $ts = array();
     $pattrs = array();
     $tournament->getTimeslots()->forAll(function ($idx, Timeslot $timeslot) use(&$pattrs) {
         $pattrs = array_merge($pattrs, $timeslot->getPlaygroundattributes()->toArray());
         return true;
     });
     /* @var $pattr PlaygroundAttribute */
     foreach ($pattrs as $pattr) {
         $pa = new PA();
         $pa->setPA($pattr);
         $pa->setId($pattr->getId());
         $pa->setPlayground($pattr->getPlayground());
         $pa->setTimeslot($pattr->getTimeslot());
         $pa->setSchedule($pattr->getStartSchedule());
         $categories = array();
         foreach ($pattr->getCategories() as $category) {
             $categories[$category->getId()] = $category;
         }
         $pa->setCategories($categories);
         $pa->setMatchlist(array());
         $ts[$pattr->getId()] = $pa;
     }
     return $ts;
 }
 private function checkForm($form, Tournament $tournament)
 {
     if ($form->isValid()) {
         if ($tournament->getName() == null || trim($tournament->getName()) == '') {
             $form->addError(new FormError($this->get('translator')->trans('FORM.TOURNAMENT.NONAME', array(), 'admin')));
             return false;
         }
         if ($tournament->getKey() == null || trim($tournament->getKey()) == '') {
             $form->addError(new FormError($this->get('translator')->trans('FORM.TOURNAMENT.NOKEY', array(), 'admin')));
             return false;
         }
         if ($tournament->getEdition() == null || trim($tournament->getEdition()) == '') {
             $form->addError(new FormError($this->get('translator')->trans('FORM.TOURNAMENT.NOEDITION', array(), 'admin')));
             return false;
         }
         return true;
     }
     return false;
 }
 private function validateData(Tournament $tournament, &$parseObj)
 {
     $playground = $this->get('logic')->getPlaygroundByNo($tournament->getId(), $parseObj['playground']);
     if ($playground == null) {
         throw new ValidationException("BADPLAYGROUND", "tournament=" . $tournament->getId() . " no=" . $parseObj['playground']);
     }
     $group = $this->get('logic')->getGroupByCategory($tournament->getId(), $parseObj['category'], $parseObj['group']);
     if ($group == null) {
         throw new ValidationException("BADGROUP", "tournament=" . $tournament->getId() . " category=" . $parseObj['category'] . " group=" . $parseObj['group']);
     }
     $groupRA = $this->get('logic')->getGroupByCategory($tournament->getId(), $parseObj['category'], $parseObj['teamA']['group']);
     if ($group == null) {
         throw new ValidationException("BADGROUP", "tournament=" . $tournament->getId() . " category=" . $parseObj['category'] . " group=" . $parseObj['teamA']['group']);
     }
     $groupRB = $this->get('logic')->getGroupByCategory($tournament->getId(), $parseObj['category'], $parseObj['teamB']['group']);
     if ($group == null) {
         throw new ValidationException("BADGROUP", "tournament=" . $tournament->getId() . " category=" . $parseObj['category'] . " group=" . $parseObj['teamB']['group']);
     }
     $parseObj['playground'] = $playground;
     $parseObj['group'] = $group;
     $parseObj['teamAgroup'] = $groupRA;
     $parseObj['teamBgroup'] = $groupRB;
 }
示例#14
0
 public function removeMatchSchedules(Tournament $tournament)
 {
     // wipe matchalternatives
     $qba = $this->em->createQuery("delete from " . $this->entity->getRepositoryPath('MatchAlternative') . " m " . "where m.matchschedule in (select ms.id " . "from " . $this->entity->getRepositoryPath('MatchSchedule') . " ms " . "where ms.tournament=:tournament)");
     $qba->setParameter('tournament', $tournament->getId());
     $qba->getResult();
     // wipe matchschedules
     foreach ($this->listMatchSchedules($tournament) as $ms) {
         $this->em->remove($ms);
     }
     $this->em->flush();
 }
 private function importCategories(Tournament $source_tournament, Tournament $tournament)
 {
     $em = $this->getDoctrine()->getManager();
     $cconversion = array();
     /* @var $category Category */
     foreach ($source_tournament->getCategories() as $category) {
         $new_category = new Category();
         $new_category->setTournament($tournament);
         $new_category->setName($category->getName());
         $new_category->setGender($category->getGender());
         $new_category->setClassification($category->getClassification());
         $new_category->setAge($category->getAge());
         $new_category->setMatchtime($category->getMatchtime());
         $em->persist($new_category);
         $cconversion[$category->getId()] = $new_category;
         foreach ($category->getGroups() as $group) {
             $new_group = new Group();
             $new_group->setCategory($new_category);
             $new_group->setName($group->getName());
             $new_group->setClassification($group->getClassification());
             $em->persist($new_group);
         }
     }
     $em->flush();
     return $cconversion;
 }