public function getGroupedOrders(Event $event) { $query = $this->getEntityManager()->createQuery('SELECT o orders, SUM(o.quantity) quantity_sum, SUM(o.pricePerUnit*o.quantity) price_sum FROM EventBundle:Order o WHERE o.event = :event GROUP BY o.dish')->setParameter('event', $event->getId()); return $orders = $query->getResult(); }
public function testListenerThatChangesEventStatus() { $client = static::createClient(); $container = $client->getContainer(); $dispatcher = $container->get('event_dispatcher'); $corvus_event = new Event(); /*corvus event cant be without host*/ $host = $this->getMock(User::class); $host->expects($this->once())->method('getEmail')->will($this->returnValue('*****@*****.**')); $corvus_event->setHost($host); $dispatcher->dispatch(EventEvents::EVENT_CREATED, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertEquals(1, $corvus_event->getStatus()); $dispatcher->dispatch(EventEvents::EVENT_CANCEL, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertEquals(0, $corvus_event->getStatus()); $dispatcher->dispatch(EventEvents::EVENT_NO_DEBTS, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertEquals(5, $corvus_event->getStatus()); $dispatcher->dispatch(EventEvents::EVENT_SUSPEND, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertEquals(2, $corvus_event->getStatus()); $dispatcher->dispatch(EventEvents::EVENT_FOOD_ORDERED, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertEquals(3, $corvus_event->getStatus()); $dispatcher->dispatch(EventEvents::EVENT_TIMEOUT, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertEquals(2, $corvus_event->getStatus()); $dispatcher->dispatch(EventEvents::EVENT_EDITED_TIME_EXTENDED, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertEquals(1, $corvus_event->getStatus()); $dispatcher->dispatch(EventEvents::EVENT_FOOD_DELIVERED, new \Corvus\EventBundle\Event\SendMailsEvent($corvus_event)); $this->assertGreaterThan(3, $corvus_event->getStatus()); $this->assertLessThan(6, $corvus_event->getStatus()); }
/** * @Route("/event/{id}/edit") * @Template() */ public function editEventAction(Request $request, Event $event) { $isFullyAuthenticated = $this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY'); $userIsHost = $event->getHost() === $this->getUser(); if (!$event) { throw $this->createNotFoundException('No event found for id ' . $event->getId()); } elseif ($isFullyAuthenticated && $userIsHost) { $OldDateTime = $event->getEndDateTime(); $OldEmails = $this->getDoctrine()->getRepository('EventBundle:EventMail')->findBy(['event' => $event]); $form = $this->createForm(new EditEventType(), $event); $form->handleRequest($request); $users = new ArrayCollection(); $emails = new ArrayCollection(); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $NewDateTime = $event->getEndDateTime(); foreach ($event->getEmails() as $email) { $count = 0; foreach ($event->getEmails() as $emailDupe) { if (strtolower($email->getEmail()) == strtolower($emailDupe->getEmail())) { $count++; } } foreach ($event->getUsers() as $user) { if (strtolower($email->getEmail()) == strtolower($user->getEmail())) { $count++; } } if ($count > 1) { $event->removeEmail($email); continue; } $user = $this->getDoctrine()->getRepository('CorvusMainBundle:User')->findOneBy(['email' => $email->getEmail()]); if ($user) { $event->addUser($user); $event->removeEmail($email); $users->add($user); } else { //Need to iterate through old emails and check if this email is already in the list. $count = 0; foreach ($OldEmails as $OldEmail) { if (strtolower($OldEmail->getEmail()) == strtolower($email->getEmail())) { $count++; } } if ($count == 0) { $emails->add($email); } $event->addEmail($email); } } $dispatcher = $this->get('event_dispatcher'); if (!($OldDateTime == $NewDateTime)) { $dispatcher->dispatch(EventEvents::EVENT_EDITED_TIME_EXTENDED, new SendMailsEvent($event)); } if ($emails->count() == 0) { $emails = null; } if ($users->count() == 0) { $users = null; } if ($emails != null || $users != null) { $dispatcher->dispatch(EventEvents::EVENT_EDITED_ADD_USERS, new SendMailsEvent($event, $users, $emails)); } foreach ($event->getEmails() as $email) { $email->setEvent($event); $em->persist($email); } $em->persist($event); $em->flush(); $this->addFlash('notice', 'Changes have been saved!'); return $this->redirect($this->generateUrl('dashboard')); } return ['form' => $form->createView()]; } else { return $this->redirectToRoute('dashboard'); } }