示例#1
0
 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();
 }
示例#2
0
 /**
  * @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');
     }
 }