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; }