private function hasSubscription(\Club\UserBundle\Entity\User $user) { foreach ($user->getSubscriptions() as $subscription) { if ($subscription->hasAttribute('team')) { foreach ($subscription->getLocation() as $location) { if ($location == $this->schedule->getLocation()) { $this->users[] = $user; return true; } foreach ($subscription->getLocation() as $child) { if ($child == $this->schedule->getLocation()) { $this->users[] = $user; return true; } foreach ($child->getChilds() as $child2) { if ($child2 == $this->schedule->getLocation()) { $this->users[] = $user; return true; } } foreach ($child2->getChilds() as $child3) { if ($child3 == $this->schedule->getLocation()) { $this->users[] = $user; return true; } foreach ($child3->getChilds() as $child4) { if ($child4 == $this->schedule->getLocation()) { $this->users[] = $user; return true; } } } } } } } return false; }
public function getGroupsByUser(\Club\UserBundle\Entity\User $user) { $location_str = ''; $used = array(); foreach ($user->getSubscriptions() as $subscription) { foreach ($subscription->getLocation() as $location) { if (!isset($used[$location->getId()])) { $location_str .= 'l.id = ' . $location->getId() . ' OR '; $used[$location->getId()] = 1; } if ($location->getLocation()) { if (!isset($used[$location->getLocation()->getId()])) { $location_str .= 'l.id = ' . $location->getLocation()->getId() . ' OR '; $used[$location->getLocation()->getId()] = 1; } if ($location->getLocation()->getLocation()) { if (!isset($used[$location->getLocation()->getLocation()->getId()])) { $location_str .= 'l.id = ' . $location->getLocation()->getLocation()->getId() . ' OR '; $used[$location->getLocation()->getLocation()->getId()] = 1; } } } } } $subs = $this->_em->getRepository('ClubShopBundle:Subscription')->getActiveSubscriptions($user); $active = !$subs ? false : true; return $this->_em->createQueryBuilder()->select('g')->from('ClubUserBundle:Group', 'g')->leftJoin('g.location', 'l')->andWhere('g.group_type = :type')->andWhere('(g.gender IS NULL OR g.gender=:gender)')->andWhere('(g.min_age IS NULL OR g.min_age <= :min_age)')->andWhere('(g.max_age IS NULL OR g.max_age >= :max_age)')->andWhere('(g.active_member IS NULL OR g.active_member = :active_member)')->andWhere('(' . $location_str . ' l.id IS NULL)')->setParameter('type', 'dynamic')->setParameter('gender', $user->getProfile()->getGender())->setParameter('min_age', $user->getProfile()->getAge())->setParameter('max_age', $user->getProfile()->getAge())->setParameter('active_member', $active)->getQuery()->getResult(); }