diff --git a/src/Application/Bundle/DefaultBundle/Controller/DefaultController.php b/src/Application/Bundle/DefaultBundle/Controller/DefaultController.php index d7cc0b324..6c974b28c 100644 --- a/src/Application/Bundle/DefaultBundle/Controller/DefaultController.php +++ b/src/Application/Bundle/DefaultBundle/Controller/DefaultController.php @@ -25,7 +25,7 @@ public function indexAction() { $events = $this->getDoctrine() ->getRepository('StfalconEventBundle:Event') - ->findBy(['active' => true], ['date' => 'ASC']); + ->findAllByActiveSorted(true, 'ASC'); return $this->render('ApplicationDefaultBundle:Redesign:index.html.twig', ['events' => $events]); } @@ -35,8 +35,8 @@ public function indexAction() */ public function footerPagesAction() { - $pages = $staticPage = $this->getDoctrine()->getRepository('StfalconEventBundle:Page') - ->findBy(['showInFooter' => true]); + $pages = $this->getDoctrine()->getRepository('StfalconEventBundle:Page') + ->getPagesForFooter(); return $this->render('ApplicationDefaultBundle:Redesign:_footer_pages.html.twig', ['pages' => $pages]); } @@ -82,7 +82,7 @@ public function cabinetAction() public function contactsAction() { $staticPage = $this->getDoctrine()->getRepository('StfalconEventBundle:Page') - ->findOneBy(['slug' => 'contacts']); + ->findOneBySlug('contacts'); if (!$staticPage) { throw $this->createNotFoundException('Page not found! about'); } @@ -100,7 +100,7 @@ public function contactsAction() public function aboutAction() { $staticPage = $this->getDoctrine()->getRepository('StfalconEventBundle:Page') - ->findOneBy(['slug' => 'about']); + ->findOneBySlug('about'); if (!$staticPage) { throw $this->createNotFoundException('Page not found! about'); } @@ -118,7 +118,7 @@ public function aboutAction() public function pageAction($slug) { $staticPage = $this->getDoctrine()->getRepository('StfalconEventBundle:Page') - ->findOneBy(['slug' => $slug]); + ->findOneBySlug($slug); if (!$staticPage) { throw $this->createNotFoundException(sprintf('Page not found! %s', $slug)); } diff --git a/src/Application/Bundle/DefaultBundle/Controller/EmailSubscribeController.php b/src/Application/Bundle/DefaultBundle/Controller/EmailSubscribeController.php index 615c649e5..c6abe3b22 100644 --- a/src/Application/Bundle/DefaultBundle/Controller/EmailSubscribeController.php +++ b/src/Application/Bundle/DefaultBundle/Controller/EmailSubscribeController.php @@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Stfalcon\Bundle\EventBundle\Entity\MailQueue; +use Symfony\Component\HttpFoundation\Response; /** * EmailSubscribe controller. @@ -24,9 +25,7 @@ class EmailSubscribeController extends Controller * @param int $userId * @param int $mailId * - * @Template() - * - * @return array + * @return Response */ public function unsubscribeAction($hash, $userId, $mailId = null) { @@ -46,7 +45,7 @@ public function unsubscribeAction($hash, $userId, $mailId = null) } /** @var MailQueue $mailQueue */ $mailQueue = $em->getRepository('StfalconEventBundle:MailQueue') - ->findOneBy(['user' => $userId, 'mail' => $mailId]); + ->findByUserAndMail($userId, $mailId); if ($mailQueue && $subscriber->isSubscribe()) { $mailQueue->setIsUnsubscribe(); } @@ -55,7 +54,7 @@ public function unsubscribeAction($hash, $userId, $mailId = null) $subscriber->setSubscribe(false); $em->flush(); - return ['hash' => $hash, 'userId' => $userId]; + return $this->render('@ApplicationDefault/EmailSubscribe/unsubscribe.html.twig', ['hash' => $hash, 'userId' => $userId]); } /** @@ -66,9 +65,7 @@ public function unsubscribeAction($hash, $userId, $mailId = null) * @param int $userId * @param string $hash * - * @Template() - * - * @return array + * @return Response */ public function subscribeAction($userId, $hash) { @@ -84,7 +81,10 @@ public function subscribeAction($userId, $hash) $subscriber->setSubscribe(true); $em->flush(); - return ['hash' => $hash, 'userId' => $userId]; + return $this->render( + '@ApplicationDefault/EmailSubscribe/subscribe.html.twig', + ['hash' => $hash, 'userId' => $userId] + ); } /** @@ -108,7 +108,8 @@ public function actionTrackOpenMail($userId, $hash, $mailId = null) if ($user) { /** @var MailQueue $mailQueue */ - $mailQueue = $em->getRepository('StfalconEventBundle:MailQueue')->findOneBy(['user' => $userId, 'mail' => $mailId]); + $mailQueue = $em->getRepository('StfalconEventBundle:MailQueue') + ->findByUserAndMail($userId, $mailId); if ($mailQueue && !$mailQueue->getIsOpen()) { /** @var Mail $mail */ $mail = $em->getRepository('StfalconEventBundle:Mail')->find($mailId); diff --git a/src/Application/Bundle/DefaultBundle/Controller/EventController.php b/src/Application/Bundle/DefaultBundle/Controller/EventController.php index b1e47cf78..f9c28dab9 100644 --- a/src/Application/Bundle/DefaultBundle/Controller/EventController.php +++ b/src/Application/Bundle/DefaultBundle/Controller/EventController.php @@ -8,8 +8,9 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Stfalcon\Bundle\EventBundle\Entity\Event; use Stfalcon\Bundle\EventBundle\Entity\EventPage; +use Stfalcon\Bundle\SponsorBundle\Entity\Category; +use Stfalcon\Bundle\SponsorBundle\Entity\Sponsor; use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -25,24 +26,18 @@ class EventController extends Controller * * @Route("/events", name="events") * - * @Template("@ApplicationDefault/Redesign/Event/events.html.twig") - * - * @return array + * @return Response */ public function eventsAction() { - $activeEvents = $this->getDoctrine()->getManager() - ->getRepository('StfalconEventBundle:Event') - ->findBy(['active' => true], ['date' => 'ASC']); - - $pastEvents = $this->getDoctrine()->getManager() - ->getRepository('StfalconEventBundle:Event') - ->findBy(['active' => false], ['date' => 'DESC']); + $eventRepository = $this->getDoctrine()->getManager()->getRepository('StfalconEventBundle:Event'); + $activeEvents = $eventRepository->findAllByActiveSorted(true, 'ASC'); + $pastEvents = $eventRepository->findAllByActiveSorted(false, 'DESC'); - return [ + return $this->render('@ApplicationDefault/Redesign/Event/events.html.twig', [ 'activeEvents' => $activeEvents, 'pastEvents' => $pastEvents, - ]; + ]); } /** @@ -53,16 +48,17 @@ public function eventsAction() * * @param string $eventSlug * - * @Template("@ApplicationDefault/Redesign/Event/event.html.twig") - * - * @return array + * @return Response */ public function showAction($eventSlug) { $referralService = $this->get('stfalcon_event.referral.service'); $referralService->handleRequest($this->container->get('request_stack')->getCurrentRequest()); - return $this->getEventPagesArr($eventSlug); + return $this->render( + '@ApplicationDefault/Redesign/Event/event.html.twig', + $this->getEventPagesArr($eventSlug) + ); } /** @@ -70,9 +66,7 @@ public function showAction($eventSlug) * * @param Event $event * - * @Template("@ApplicationDefault/Redesign/Event/event_price.html.twig") - * - * @return array + * @return Response */ public function getEventCostsAction(Event $event) { @@ -82,11 +76,14 @@ public function getEventCostsAction(Event $event) $eventCurrentCost = $ticketCostRepository->getEventCurrentCost($event); $ticketCosts = $ticketCostRepository->getEventTicketsCost($event); - return [ - 'ticketCosts' => $ticketCosts, - 'currentPrice' => $eventCurrentCost, - 'event' => $event, - ]; + return $this->render( + '@ApplicationDefault/Redesign/Event/event_price.html.twig', + [ + 'ticketCosts' => $ticketCosts, + 'currentPrice' => $eventCurrentCost, + 'event' => $event, + ] + ); } /** @@ -97,13 +94,14 @@ public function getEventCostsAction(Event $event) * @param string $eventSlug * @param string $reviewSlug * - * @Template("ApplicationDefaultBundle:Redesign/Speaker:report_review.html.twig") - * - * @return array + * @return Response */ public function showEventReviewAction($eventSlug, $reviewSlug) { - return $this->getEventPagesArr($eventSlug, $reviewSlug); + return $this->render( + 'ApplicationDefaultBundle:Redesign/Speaker:report_review.html.twig', + $this->getEventPagesArr($eventSlug, $reviewSlug) + ); } /** @@ -111,9 +109,7 @@ public function showEventReviewAction($eventSlug, $reviewSlug) * * @param Event $event * - * @Template("ApplicationDefaultBundle:Redesign/Partner:partners.html.twig") - * - * @return array + * @return Response */ public function eventPartnersAction(Event $event) { @@ -126,9 +122,11 @@ public function eventPartnersAction(Event $event) $sortedPartners = []; foreach ($partners as $key => $partner) { - $partnerCategory = $partnerCategoryRepository->find($partner['id']); - if ($partnerCategory) { - $sortedPartners[$partnerCategory->isWideContainer()][$partnerCategory->getSortOrder()][$partnerCategory->getName()][] = $partner[0]; + if (isset($partner['categoryId'])) { + $partnerCategory = $partnerCategoryRepository->findById((int) $partner['categoryId']); + if ($partnerCategory instanceof Category && isset($partner[0]) && $partner[0] instanceof Sponsor) { + $sortedPartners[$partnerCategory->isWideContainer()][$partnerCategory->getSortOrder()][$partnerCategory->getName()][] = $partner[0]; + } } } @@ -140,7 +138,10 @@ public function eventPartnersAction(Event $event) krsort($sortedPartners[1]); } - return ['partners' => $sortedPartners]; + return $this->render( + 'ApplicationDefaultBundle:Redesign/Partner:partners.html.twig', + ['partners' => $sortedPartners] + ); } /** @@ -158,7 +159,7 @@ public function eventPartnersAction(Event $event) public function getModalHeaderAction($slug, $headerType) { $event = $this->getDoctrine() - ->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); + ->getRepository('StfalconEventBundle:Event')->findOneBySlug($slug); if (!$event) { return new JsonResponse(['result' => false, 'error' => 'Unable to find Event by slug: '.$slug]); } @@ -186,7 +187,7 @@ public function getModalHeaderAction($slug, $headerType) public function getEventMapPosition($slug) { $event = $this->getDoctrine() - ->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); + ->getRepository('StfalconEventBundle:Event')->findOneBySlug($slug); if (!$event) { return new JsonResponse(['result' => false, 'error' => 'Unable to find Event by slug: '.$slug]); } @@ -223,7 +224,7 @@ public function userAddWantsToVisitEventAction($slug, Request $request) $flashContent = ''; $em = $this->getDoctrine()->getManager(); $event = $this->getDoctrine() - ->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); + ->getRepository('StfalconEventBundle:Event')->findOneBySlug($slug); if (!$event) { if ($request->isXmlHttpRequest()) { @@ -275,7 +276,7 @@ public function userSubWantsToVisitEventAction($slug) $flashContent = ''; $em = $this->getDoctrine()->getManager(); $event = $this->getDoctrine() - ->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); + ->getRepository('StfalconEventBundle:Event')->findOneBySlug($slug); if (!$event) { return new JsonResponse(['result' => $result, 'error' => 'Unable to find Event by slug: '.$slug]); @@ -302,9 +303,7 @@ public function userSubWantsToVisitEventAction($slug) * * @param string $eventSlug * - * @Template("ApplicationDefaultBundle:Redesign:venue_review.html.twig") - * - * @return array + * @return Response */ public function showEventVenuePageAction($eventSlug) { @@ -316,7 +315,10 @@ public function showEventVenuePageAction($eventSlug) $newText = $resultArray['venuePage']->getTextNew(); $text = isset($newText) && !empty($newText) ? $newText : $resultArray['venuePage']->getText(); - return array_merge($resultArray, ['text' => $text]); + return $this->render( + 'ApplicationDefaultBundle:Redesign:venue_review.html.twig', + array_merge($resultArray, ['text' => $text]) + ); } /** @@ -325,14 +327,12 @@ public function showEventVenuePageAction($eventSlug) * @param string $eventSlug * @param string $pageSlug * - * @Template("ApplicationDefaultBundle:Redesign:static.page.html.twig") - * - * @return array + * @return Response */ public function showEventPageInStaticAction($eventSlug, $pageSlug) { $event = $this->getDoctrine() - ->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $eventSlug]); + ->getRepository('StfalconEventBundle:Event')->findOneBySlug($eventSlug); if (!$event) { throw $this->createNotFoundException(sprintf('Unable to find event by slug: ', $eventSlug)); } @@ -353,7 +353,7 @@ public function showEventPageInStaticAction($eventSlug, $pageSlug) $newText = $myPage->getTextNew(); $text = isset($newText) && !empty($newText) ? $newText : $myPage->getText(); - return ['text' => $text]; + return $this->render('ApplicationDefaultBundle:Redesign:static.page.html.twig', ['text' => $text]); } /** diff --git a/src/Stfalcon/Bundle/EventBundle/Repository/EventRepository.php b/src/Stfalcon/Bundle/EventBundle/Repository/EventRepository.php index 4418c5752..7401f2c6d 100644 --- a/src/Stfalcon/Bundle/EventBundle/Repository/EventRepository.php +++ b/src/Stfalcon/Bundle/EventBundle/Repository/EventRepository.php @@ -13,6 +13,40 @@ */ class EventRepository extends EntityRepository { + /** + * @param bool $active + * @param string $sort + * + * @return array|null + */ + public function findAllByActiveSorted($active = true, $sort = 'ASC') + { + $qb = $this->createQueryBuilder('e'); + $qb->where($qb->expr()->eq('e.active', ':active')) + ->setParameter('active', $active) + ->orderBy('e.date', $sort) + ; + + return $qb->getQuery()->getResult(); + } + + /** + * @param string $slug + * + * @return mixed + * + * @throws \Doctrine\ORM\NonUniqueResultException + */ + public function findOneBySlug($slug) + { + $qb = $this->createQueryBuilder('e'); + $qb->where($qb->expr()->eq('e.slug', ':slug')) + ->setParameter('slug', $slug) + ; + + return $qb->getQuery()->getOneOrNullResult(); + } + /** * @param User $user * @param bool $active diff --git a/src/Stfalcon/Bundle/EventBundle/Repository/MailQueueRepository.php b/src/Stfalcon/Bundle/EventBundle/Repository/MailQueueRepository.php index 88d413795..7112f1fae 100644 --- a/src/Stfalcon/Bundle/EventBundle/Repository/MailQueueRepository.php +++ b/src/Stfalcon/Bundle/EventBundle/Repository/MailQueueRepository.php @@ -59,4 +59,21 @@ public function deleteAllNotSentMessages($mail) return $qb->getQuery()->getResult(); } + + /** + * @param int $userId + * @param int $mailId + * + * @return mixed + */ + public function findByUserAndMail($userId, $mailId) + { + $qb = $this->createQueryBuilder('mq'); + $qb->where($qb->expr()->eq('mq.user', ':user')) + ->andWhere($qb->expr()->eq('mq.mail', ':mail')) + ->setParameters(['user' => $userId, 'mail' => $mailId]) + ; + + return $qb->getQuery()->getOneOrNullResult(); + } } diff --git a/src/Stfalcon/Bundle/EventBundle/Repository/PageRepository.php b/src/Stfalcon/Bundle/EventBundle/Repository/PageRepository.php index 9b736e945..34942a23e 100644 --- a/src/Stfalcon/Bundle/EventBundle/Repository/PageRepository.php +++ b/src/Stfalcon/Bundle/EventBundle/Repository/PageRepository.php @@ -12,4 +12,30 @@ */ class PageRepository extends EntityRepository { + /** + * @return array + */ + public function getPagesForFooter() + { + $qb = $this->createQueryBuilder('p'); + $qb->where($qb->expr()->eq('p.showInFooter', true)); + + return $qb->getQuery()->getResult(); + } + + /** + * @param string $slug + * + * @return mixed + */ + public function findOneBySlug($slug) + { + $qb = $this->createQueryBuilder('p'); + $qb->where($qb->expr()->eq('p.slug', ':slug')) + ->setParameter('slug', $slug) + ->setMaxResults(1) + ; + + return $qb->getQuery()->getOneOrNullResult(); + } } diff --git a/src/Stfalcon/Bundle/SponsorBundle/Repository/CategoryRepository.php b/src/Stfalcon/Bundle/SponsorBundle/Repository/CategoryRepository.php index 149615a4f..9f6e163ad 100644 --- a/src/Stfalcon/Bundle/SponsorBundle/Repository/CategoryRepository.php +++ b/src/Stfalcon/Bundle/SponsorBundle/Repository/CategoryRepository.php @@ -12,4 +12,20 @@ */ class CategoryRepository extends EntityRepository { + /** + * @param int $id + * + * @return mixed + * + * @throws \Doctrine\ORM\NonUniqueResultException + */ + public function findById($id) + { + $qb = $this->createQueryBuilder('c'); + $qb->where($qb->expr()->eq('c.id', ':id')) + ->setParameter('id', $id) + ; + + return $qb->getQuery()->getOneOrNullResult(); + } } diff --git a/src/Stfalcon/Bundle/SponsorBundle/Repository/SponsorRepository.php b/src/Stfalcon/Bundle/SponsorBundle/Repository/SponsorRepository.php index c8a2405bf..06b15a401 100644 --- a/src/Stfalcon/Bundle/SponsorBundle/Repository/SponsorRepository.php +++ b/src/Stfalcon/Bundle/SponsorBundle/Repository/SponsorRepository.php @@ -53,7 +53,7 @@ public function getSponsorsOfEventWithCategory(Event $event) $qb = $this->createQueryBuilder('s'); return - $qb->select('s', 'c.id') + $qb->select('s', 'c.id AS categoryId') ->where('e.id = :eventId') ->join('s.sponsorEvents', 'se') ->join('se.event', 'e')