public function getTeam(\Club\RankingBundle\Entity\Ranking $ranking, \Club\MatchBundle\Entity\Team $team) { $lt = $this->findOneBy(array('ranking' => $ranking->getId(), 'team' => $team->getId())); if (!$lt) { $lt = $this->addTeam($ranking, $team); } return $lt; }
public function getRecentMatches(\Club\RankingBundle\Entity\Ranking $ranking, $limit = 10) { $matches = $this->_em->createQueryBuilder()->select('m')->from('ClubRankingBundle:Match', 'm')->where('m.ranking = :ranking_id')->orderBy('m.id', 'DESC')->setMaxResults($limit)->setParameter('ranking_id', $ranking->getId())->getQuery()->getResult(); if (!$matches) { return false; } $ids = array(); foreach ($matches as $match) { $ids[] = $match->getMatch()->getId(); } return $this->_em->createQueryBuilder()->select('m')->from('ClubMatchBundle:Match', 'm')->where('m.id IN (:ids)')->orderBy('m.id', 'DESC')->setParameter('ids', $ids)->getQuery()->getResult(); }
private function validateRules(\Club\RankingBundle\Entity\Ranking $ranking) { $qb = $this->em->createQueryBuilder()->select('count(mt.team)')->from('ClubRankingBundle:Ranking', 'r')->join('r.matches', 'm')->join('m.match', 'm2')->join('m2.match_teams', 'mt')->where('r.id = :ranking')->andWhere('mt.team = ?1 OR mt.team = ?2')->groupBy('mt.match')->having('count(mt.team) = 2')->setParameter('ranking', $ranking->getId()); $i = 0; foreach ($this->match->getMatchTeams() as $match_team) { $i++; $qb->setParameter($i, $match_team->getTeam()->getId()); } $matches = $qb->getQuery()->getResult(); $total = $ranking->getRule()->getSamePlayer(); if (count($matches) >= $total) { throw new \Exception($this->translator->trans('Teams has already played %count% matches against each other.', array('%count%' => count($matches)))); return false; } return true; }