示例#1
0
 /**
  * Create HTML template for ticket invitation
  *
  * @param Ticket $ticket
  *
  * @return string
  */
 public function generateHTML(Ticket $ticket)
 {
     $twig = $this->templating;
     $url = $this->router->generate('event_ticket_check', array('ticket' => $ticket->getId(), 'hash' => $ticket->getHash()), true);
     $this->qrCode->setText($url);
     $this->qrCode->setSize(105);
     $this->qrCode->setPadding(0);
     $qrCodeBase64 = base64_encode($this->qrCode->get());
     $templateContent = $twig->loadTemplate('StfalconEventBundle:Ticket:show_pdf.html.twig');
     $body = $templateContent->render(array('ticket' => $ticket, 'qrCodeBase64' => $qrCodeBase64, 'path' => realpath($this->kernel->getRootDir() . '/../web') . '/'));
     return $body;
 }
示例#2
0
 /**
  * Check that QR-code is valid, and register ticket
  *
  * @param Ticket $ticket Ticket
  * @param string $hash   Hash
  *
  * @return Response
  *
  * @Route("/ticket/{ticket}/check/{hash}", name="event_ticket_registration")
  */
 public function registrationAction(Ticket $ticket, $hash)
 {
     //bag fix test ticket.feature:27
     // сверяем хеш билета и хеш из урла
     if ($ticket->getHash() != $hash) {
         return new Response('<h1 style="color:red">Невалидный хеш для билета №' . $ticket->getId() . '</h1>', 403);
     }
     //bag fix test ticket.feature:33
     // любопытных пользователей перенаправляем на страницу события
     if (!$this->get('security.authorization_checker')->isGranted('ROLE_VOLUNTEER')) {
         return $this->redirect($this->generateUrl('event_show', array('event_slug' => $ticket->getEvent()->getSlug())));
     }
     // проверяем существует ли оплата
     if ($ticket->getPayment() instanceof Payment) {
         // проверяем оплачен ли билет
         if ($ticket->getPayment()->isPaid()) {
             // проверяем или билет ещё не отмечен как использованный
             if ($ticket->isUsed()) {
                 $timeNow = new \DateTime();
                 $timeDiff = $timeNow->diff($ticket->getUpdatedAt());
                 return new Response('<h1 style="color:orange">Билет №' . $ticket->getId() . ' был использован ' . $timeDiff->format('%i мин. назад') . '</h1>', 409);
             }
         } else {
             return new Response('<h1 style="color:orange">Билет №' . $ticket->getId() . ' не оплачен' . '</h1>');
         }
     } else {
         return new Response('<h1 style="color:orange">Билет №' . $ticket->getId() . ' оплата не существует' . '</h1>');
     }
     // отмечаем билет как использованный
     $em = $this->getDoctrine()->getManager();
     $ticket->setUsed(true);
     $em->flush();
     return new Response('<h1 style="color:green">Все ок. Билет №' . $ticket->getId() . ' отмечаем как использованный</h1>');
 }
示例#3
0
 /**
  * @param Event $event
  * @param User  $user
  *
  * @return Ticket
  */
 public function createTicket($event, $user)
 {
     // @todo це ще треба передивитись і поправити
     $em = $this->container->get('doctrine.orm.default_entity_manager');
     // Вытягиваем скидку из конфига
     $paymentsConfig = $this->container->getParameter('stfalcon_event.config');
     $discount = (double) $paymentsConfig['discount'];
     $ticket = new Ticket();
     $ticket->setEvent($event);
     $ticket->setUser($user);
     $ticket->setAmountWithoutDiscount($event->getCost());
     $paidPayments = $em->getRepository('StfalconEventBundle:Payment')->findPaidPaymentsForUser($user);
     // если пользователь имеет оплаченные события,
     // то он получает скидку (если для события разрешена такая скидка)
     if (count($paidPayments) > 0 && $event->getUseDiscounts()) {
         $cost = $event->getCost() - $event->getCost() * $discount;
         $hasDiscount = true;
     } else {
         $cost = $event->getCost();
         $hasDiscount = false;
     }
     $ticket->setAmount($cost);
     $ticket->setHasDiscount($hasDiscount);
     $em->persist($ticket);
     $em->flush();
     return $ticket;
 }
示例#4
0
 /**
  * Receive the confirmation token from user email provider, login the user
  */
 public function confirmAction($token)
 {
     $user = $this->container->get('fos_user.user_manager')->findUserByConfirmationToken($token);
     if (null === $user) {
         throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token));
     }
     $user->setConfirmationToken(null);
     $user->setEnabled(true);
     $user->setLastLogin(new \DateTime());
     $this->container->get('fos_user.user_manager')->updateUser($user);
     $response = new RedirectResponse($this->container->get('router')->generate('fos_user_registration_confirmed'));
     $this->authenticateUser($user, $response);
     $activeEvents = $this->container->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Event')->findBy(array('active' => true));
     // Подписываем пользователя на все активные евенты
     $em = $this->container->get('doctrine')->getManagerForClass('StfalconEventBundle:Ticket');
     foreach ($activeEvents as $activeEvent) {
         $ticket = new Ticket();
         $ticket->setEvent($activeEvent);
         $ticket->setUser($user);
         $ticket->setAmount($activeEvent->getCost());
         $ticket->setAmountWithoutDiscount($activeEvent->getCost());
         $em->persist($ticket);
         $em->flush();
     }
     return $response;
 }
示例#5
0
 /**
  * @param \Doctrine\Common\Persistence\ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     /**
      * @var \Application\Bundle\UserBundle\Entity\User $userDefault
      * @var \Application\Bundle\UserBundle\Entity\User $userDefault2
      * @var \Application\Bundle\UserBundle\Entity\User $userDefault3
      * @var \Application\Bundle\UserBundle\Entity\User $userAdmin
      */
     $userDefault = $manager->merge($this->getReference('user-default'));
     $userDefault2 = $manager->merge($this->getReference('user-default2'));
     $userDefault3 = $manager->merge($this->getReference('user-default3'));
     $userAdmin = $manager->merge($this->getReference('user-admin'));
     $eventZfDay = $this->getReference('event-zfday');
     $eventPHPDay = $this->getReference('event-phpday');
     $eventNotActive = $this->getReference('event-not-active');
     // Ticket 1
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventZfDay));
     $ticket->setAmountWithoutDiscount($eventZfDay->getCost());
     $ticket->setAmount($eventZfDay->getCost());
     $ticket->setUser($userDefault);
     $ticket->setPayment($manager->merge($this->getReference('payment')));
     $manager->persist($ticket);
     $this->addReference('ticket-1', $ticket);
     // Ticket 2
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventPHPDay));
     $ticket->setUser($userDefault);
     $ticket->setAmountWithoutDiscount($eventPHPDay->getCost());
     $ticket->setAmount($eventPHPDay->getCost());
     $ticket->setPayment($manager->merge($this->getReference('pending')));
     $manager->persist($ticket);
     $this->addReference('ticket-2', $ticket);
     // Ticket 3
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventNotActive));
     $ticket->setUser($userAdmin);
     $ticket->setAmountWithoutDiscount($eventNotActive->getCost());
     $ticket->setAmount($eventNotActive->getCost());
     $manager->persist($ticket);
     $this->addReference('ticket-3', $ticket);
     // Ticket 4: not used without payment
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventPHPDay));
     $ticket->setUser($userDefault2);
     $ticket->setAmountWithoutDiscount($eventPHPDay->getCost());
     $ticket->setAmount($eventPHPDay->getCost());
     $ticket->setCreatedAt(new \DateTime('2012-12-12 00:00:00'));
     $ticket->setUsed(false);
     $manager->persist($ticket);
     // Ticket 5: not used with paid payment
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventPHPDay));
     $ticket->setUser($userDefault2);
     $ticket->setAmountWithoutDiscount($eventPHPDay->getCost());
     $ticket->setAmount($eventPHPDay->getCost());
     $ticket->setCreatedAt(new \DateTime('2012-12-12 00:00:00'));
     $ticket->setUsed(false);
     $ticket->setPayment($manager->merge($this->getReference('payment2')));
     $manager->persist($ticket);
     // Ticket 6: used with pending payment
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventPHPDay));
     $ticket->setUser($userDefault2);
     $ticket->setAmountWithoutDiscount($eventPHPDay->getCost());
     $ticket->setAmount($eventPHPDay->getCost());
     $ticket->setCreatedAt(new \DateTime('2012-12-12 00:00:00'));
     $ticket->setUsed(true);
     $ticket->setPayment($manager->merge($this->getReference('pending2')));
     $manager->persist($ticket);
     // Ticket 7: used with paid payment
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventPHPDay));
     $ticket->setUser($userDefault2);
     $ticket->setAmountWithoutDiscount($eventPHPDay->getCost());
     $ticket->setAmount($eventPHPDay->getCost());
     $ticket->setCreatedAt(new \DateTime('2012-12-12 00:00:00'));
     $ticket->setUsed(true);
     $ticket->setPayment($manager->merge($this->getReference('payment2')));
     $manager->persist($ticket);
     // Ticket 8: not used without payment
     $ticket = new Ticket();
     $ticket->setEvent($manager->merge($eventZfDay));
     $ticket->setUser($userDefault3);
     $ticket->setAmountWithoutDiscount($eventZfDay->getCost());
     $ticket->setAmount($eventZfDay->getCost());
     $ticket->setCreatedAt(new \DateTime('2012-12-12 00:00:00'));
     $ticket->setUsed(false);
     $manager->persist($ticket);
     for ($i = 1; $i <= 100; $i++) {
         $ticket = new Ticket();
         $ticket->setEvent($manager->merge($eventZfDay));
         $ticket->setAmountWithoutDiscount($eventZfDay->getCost());
         $ticket->setAmount($eventZfDay->getCost());
         $ticket->setUser($manager->merge($this->getReference('user-default-' . $i)));
         $ticket->setPayment($manager->merge($this->getReference('payment')));
         $manager->persist($ticket);
         $this->addReference('ticket-' . ($i + 3), $ticket);
     }
     $manager->flush();
 }
示例#6
0
 /**
  * @Route("/admin/event/{slug}/users/add", name="adminusersadd")
  * @Secure(roles="ROLE_ADMIN")
  * @Template()
  */
 public function addUsersAction(Event $event)
 {
     // @todo удалить этот метод. одноразовый харкод
     $em = $this->getDoctrine()->getManager();
     if (isset($_POST['users'])) {
         $users = explode("\r\n", $_POST['users']);
         foreach ($users as $data) {
             // данные с формы
             $dt = explode(' ', $data);
             unset($data);
             $data['name'] = $dt[0] . ' ' . $dt[1];
             $data['email'] = $dt[2];
             $data['discount'] = isset($dt[3]);
             $user = $this->get('fos_user.user_manager')->findUserBy(array('email' => $data['email']));
             // создаем нового пользователя
             if (!$user) {
                 $user = $this->get('fos_user.user_manager')->createUser();
                 $user->setEmail($data['email']);
                 $user->setFullname($data['name']);
                 // генерация временного пароля
                 $password = substr(str_shuffle(md5(time())), 5, 8);
                 $user->setPlainPassword($password);
                 $user->setEnabled(true);
                 $this->get('fos_user.user_manager')->updateUser($user);
                 // отправляем сообщение о регистрации
                 $text = "Приветствуем " . $user->getFullname() . "!\n\nВы были автоматически зарегистрированы на сайте Frameworks Days.\n\nВаш временный пароль: " . $password . "\nЕго можно сменить на странице " . $this->generateUrl('fos_user_change_password', array(), true) . "\n\n\n---\nС уважением,\nКоманда Frameworks Days";
                 $message = \Swift_Message::newInstance()->setSubject("Регистрация на сайте Frameworks Days")->setFrom('*****@*****.**', 'Frameworks Days')->setTo($user->getEmail())->setBody($text);
                 // @todo каждый вызов отнимает память
                 $this->get('mailer')->send($message);
                 echo "#{$user->getId()} {$user->getFullname()} — Create a new user<br>";
             } else {
                 echo "<b>#{$user->getId()} {$user->getFullname()} — already registered</b><br>";
             }
             // обновляем информацию о компании
             $user->setCountry('Украина');
             if (isset($_POST['city'])) {
                 $user->setCity($_POST['city']);
             }
             $user->setCompany($_POST['company']);
             $em->persist($user);
             $em->flush();
             // проверяем или у него нет билетов на этот ивент
             /** @var Ticket $ticket */
             $ticket = $em->getRepository('StfalconEventBundle:Ticket')->findOneBy(array('event' => $event->getId(), 'user' => $user->getId()));
             if (!$ticket) {
                 $ticket = new Ticket();
                 $ticket->setEvent($event);
                 $ticket->setUser($user);
                 $em->persist($ticket);
             }
             if ($ticket->isPaid()) {
                 echo "<b>he has already paid participation in the conference!</b><br>";
             } else {
                 // цена участия (с учетом скидки)
                 $amount = $data['discount'] ? $_POST['amount'] * 0.8 : $_POST['amount'];
                 $ticket->setAmount($amount);
                 $ticket->setHasDiscount($data['discount']);
                 $ticket->setAmountWithoutDiscount($_POST['amount']);
                 $oldPayment = $ticket->getPayment();
                 if ($oldPayment) {
                     $oldPayment->removeTicket($ticket);
                     $em->persist($oldPayment);
                 }
                 echo "create a new payment<br>";
                 $payment = new Payment();
                 $payment->setUser($user);
                 $payment->addTicket($ticket);
                 $em->persist($payment);
                 $em->flush();
                 // обновляем шлюз и статус платежа
                 $payment->setGate('admin');
                 $payment->markedAsPaid();
                 $em->persist($payment);
                 $em->persist($ticket);
                 // сохраняем все изменения
                 $em->flush();
                 echo "mark as paid<br>";
             }
         }
         echo 'complete';
         exit;
     }
     return [];
 }
示例#7
0
文件: User.php 项目: bolotyuh/fwdays
 public function addTicket(Ticket $ticket)
 {
     $ticket->setUser($this);
     $this->tickets->add($ticket);
 }
示例#8
0
 /**
  * @param Event $event
  * @param User  $user
  *
  * @return Ticket
  */
 private function createTicket($event, $user)
 {
     // @todo це в сервісі мало б бути
     $em = $this->getDoctrine()->getManager();
     // Вытягиваем скидку из конфига
     $paymentsConfig = $this->container->getParameter('stfalcon_payment.config');
     $discount = (double) $paymentsConfig['discount'];
     $ticket = new Ticket();
     $ticket->setEvent($event);
     $ticket->setUser($user);
     $ticket->setAmountWithoutDiscount($event->getCost());
     $paidPayments = $em->getRepository('StfalconPaymentBundle:Payment')->findPaidPaymentsForUser($user);
     // Если пользователь имеет оплаченные события, то он получает скидку
     if (count($paidPayments) > 0) {
         $cost = $event->getCost() - $event->getCost() * $discount;
         $hasDiscount = true;
     } else {
         $cost = $event->getCost();
         $hasDiscount = false;
     }
     $ticket->setAmount($cost);
     $ticket->setHasDiscount($hasDiscount);
     $em->persist($ticket);
     $em->flush();
     return $ticket;
 }