public function onTeamUnattend(\Club\TeamBundle\Event\FilterScheduleEvent $event)
 {
     $user = $event->getUser();
     $schedule = $event->getSchedule();
     $subs = $this->em->getRepository('ClubShopBundle:Subscription')->getActiveSubscriptions($user, null, 'team');
     $subscription = reset($subs);
     if ($subscription->getType() == 'ticket') {
         $log = new \Club\ShopBundle\Entity\SubscriptionTicket();
         $log->setTickets(-1);
         $log->setSubscription($subscription);
         $note = 'Cancelled ' . $schedule->getTeamCategory()->getTeamName() . ' on ' . $schedule->getFirstDate()->format('Y-m-d') . ', from ' . $schedule->getFirstDate()->format('H:i') . ' to ' . $schedule->getEndDate()->format('H:i');
         $log->setNote($note);
         $this->em->persist($log);
         $this->em->flush();
     }
 }
 public function useTicket(\Club\ShopBundle\Entity\Subscription $subscription, $tickets = 1)
 {
     $left = $this->em->getRepository('ClubShopBundle:Subscription')->getTicketsLeft($subscription);
     if ($left - $tickets < 0) {
         $this->session->getFlashBag()->add('error', $this->translator->trans('You do not have enough tickets.'));
         return false;
     } elseif ($left - $tickets == 0) {
         $this->em->persist($subscription);
         $this->em->flush();
     }
     $st = new \Club\ShopBundle\Entity\SubscriptionTicket();
     $st->setSubscription($subscription);
     $st->setTickets($tickets);
     $this->em->persist($st);
     $this->em->flush();
     $this->session->getFlashBag()->add('notice', $this->translator->trans('The tickets has been removed from your account.'));
 }