public function listOpenQMatchesByTournament($tournamentid) { $qb = $this->em->createQuery("select m.id as mid,m.matchno,m.date,m.time," . "p.id as pid," . "g.id as gid," . "q.id as rid,q.awayteam,q.rank,gq.id as rgrp " . "from " . $this->entity->getRepositoryPath('QMatchRelation') . " q, " . $this->entity->getRepositoryPath('MatchRelation') . " r, " . $this->entity->getRepositoryPath('Match') . " m, " . $this->entity->getRepositoryPath('Group') . " g, " . $this->entity->getRepositoryPath('Category') . " cat, " . $this->entity->getRepositoryPath('Playground') . " p, " . $this->entity->getRepositoryPath('Group') . " gq " . "where cat.tournament=:tournament and " . "g.category=cat.id and " . "m.group=g.id and " . "p.id=m.playground and " . "q.match=m.id and " . "q.group=gq.id and " . "(select count(r.match) from matchrelations r where r.match=m.id) = 0 " . "order by m.id"); $qb->setParameter('tournament', $tournamentid); // Collect match relations as matches $matchList = array(); foreach ($qb->getResult() as $qmatch) { $matchList[$qmatch['matchno']][$qmatch['awayteam'] == 'Y' ? 'A' : 'H'] = $qmatch; } // Prepare match list for output $matches = array(); foreach ($matchList as $matchRelList) { // There must be two relations for each match - otherwise ignore the match if (count($matchRelList) == 2) { $match = new QMatch(); $match->setId($matchRelList['H']['mid']); $match->setMatchno($matchRelList['H']['matchno']); $match->setPid($matchRelList['H']['gid']); $match->setPlayground($matchRelList['H']['pid']); $match->setDate($matchRelList['H']['date']); $match->setTime($matchRelList['H']['time']); $match->setGroupA($matchRelList['H']['rgrp']); $match->setGroupB($matchRelList['A']['rgrp']); $match->setRankA($matchRelList['H']['rank']); $match->setRankB($matchRelList['A']['rank']); $matches[] = $match; } } // Sort the matches based on schedule usort($matches, function (QMatch $match1, QMatch $match2) { $p1 = $match2->getPid() - $match1->getPid(); $p2 = $match2->getDate() - $match1->getDate(); $p3 = $match2->getPlayground() - $match1->getPlayground(); $p4 = $match2->getTime() - $match1->getTime(); if ($p1 == 0 && $p2 == 0 && $p3 == 0 && $p4 == 0) { return 0; } elseif ($p1 < 0 || $p1 == 0 && $p2 < 0 || $p1 == 0 && $p2 == 0 && $p3 < 0 || $p1 == 0 && $p2 == 0 && $p3 == 0 && $p4 < 0) { return 1; } else { return -1; } }); return $matches; }
private function checkForm($form, MatchForm $matchForm) { if (!$form->isValid()) { return false; } if ($matchForm->getGroupA() == null) { $form->addError(new FormError($this->get('translator')->trans('FORM.MATCH.NOHOMEGROUP', array(), 'admin'))); } if ($matchForm->getGroupB() == null) { $form->addError(new FormError($this->get('translator')->trans('FORM.MATCH.NOAWAYGROUP', array(), 'admin'))); } if ($matchForm->getRankA() == null || trim($matchForm->getRankA()) == '') { $form->addError(new FormError($this->get('translator')->trans('FORM.MATCH.NOHOMERANK', array(), 'admin'))); } if ($matchForm->getRankB() == null || trim($matchForm->getRankB()) == '') { $form->addError(new FormError($this->get('translator')->trans('FORM.MATCH.NOAWAYRANK', array(), 'admin'))); } elseif ($matchForm->getGroupA() == $matchForm->getGroupB() && $matchForm->getRankA() == $matchForm->getRankB()) { $form->addError(new FormError($this->get('translator')->trans('FORM.MATCH.SAMEQ', array(), 'admin'))); } return $form->isValid(); }