/**
  * @Route("/new")
  * @Method("POST")
  */
 public function createAction()
 {
     $request = $this->getRequest();
     $name = $request->get('name');
     $did = $request->get('did');
     $companyID = $request->get('company');
     $em = $this->getDoctrine()->getManager();
     $company = $em->getRepository('VoIPCompanyStructureBundle:Company')->find($companyID);
     if (!$company) {
         throw $this->createNotFoundException('Unable to find $company entity.');
     }
     $subscription = new Subscription();
     $subscription->setName($name);
     $subscription->setDid($did);
     $subscription->setCompany($company);
     $em->persist($subscription);
     $em->flush();
     return $this->redirect($this->generateUrl('admin_subscriptions'));
 }
 /**
  * @Route("/new")
  * @Method("POST")
  * @Security("has_role('ROLE_USER')")
  */
 public function createAction()
 {
     $user = $this->getUser();
     $company = $user->getCompany();
     $em = $this->getDoctrine()->getManager();
     $request = $this->getRequest();
     $requestBag = $request->request;
     $name = $requestBag->get('name');
     $did = $requestBag->get('number');
     $countries = $requestBag->get('countries');
     $employees = $requestBag->get('employees');
     $subscription = new Subscription();
     $subscription->setName($name);
     $subscription->setDid($did);
     $subscription->setCompany($company);
     if ($countries) {
         foreach ($countries as $id) {
             $country = $em->getRepository('VoIPCompanySubscriptionsBundle:Country')->find($id);
             $subscriptions = $country->getSubscriptions()->filter(function ($subscription) use($company) {
                 return $subscription->getCompany() == $company;
             });
             foreach ($subscriptions as $s) {
                 $s->removeCountry($country);
             }
             $subscription->addCountry($country);
         }
     }
     if ($employees) {
         foreach ($employees as $id) {
             $employee = $em->getRepository('VoIPCompanyStructureBundle:Employee')->find($id);
             $subscription->addEmployee($employee);
         }
     }
     $em->persist($subscription);
     $em->flush();
     return $this->redirect($this->generateUrl('ui_company'));
 }