/**
  * @Route("/rental-detail/{subcategoryId}", name="rental-detail")
  */
 public function rentalDetailAction(Request $request, $subcategoryId)
 {
     $subcategory = $this->getDoctrineRepo('AppBundle:Subcategory')->find($subcategoryId);
     // build form
     //<editor-fold>
     $form = $this->createFormBuilder()->add('equipment', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 128)))))->add('name', 'text', array('required' => false, 'constraints' => array(new Length(array('max' => 128)))))->add('email', 'email', array('constraints' => array(new Email(array('checkHost' => true)))))->getForm();
     //</editor-fold>
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         // create Candidate object
         $cand = new Candidate();
         $cand->setSubcategory($subcategory);
         $cand->setName($data['name']);
         $cand->setEmail($data['email']);
         $cand->setEquipment($data['equipment']);
         // save to database
         $em = $this->getDoctrine()->getManager();
         $em->persist($cand);
         $em->flush();
         // send email
         //<editor-fold>
         $url = sprintf('%s%s?register', $request->getSchemeAndHttpHost(), $this->get('router')->generate('rentme'));
         $emailHtml = $this->renderView('Emails/candidate.html.twig', array('mailer_image_url_prefix' => $this->getParameter('mailer_image_url_prefix'), 'custom_message' => $subcategory->getEmailBody(), 'url' => $url));
         $from = array($this->getParameter('mailer_fromemail') => $this->getParameter('mailer_fromname'));
         $message = Swift_Message::newInstance()->setSubject('Willkomen bei')->setFrom($from)->setTo($cand->getEmail())->setBody($emailHtml, 'text/html');
         $this->get('mailer')->send($message);
         //</editor-fold>
         return $this->redirectToRoute('rentme');
     }
     return $this->render('rental/rental_detail.html.twig', array('subcategory' => $subcategory, 'form' => $form->createView()));
 }
 /**
  * @Route("/offer-form/{categoryId}", name="offer-form")
  */
 public function offerFormAction(Request $request, $categoryId)
 {
     $category = $this->getDoctrineRepo('AppBundle:Category')->find($categoryId);
     // build form
     //<editor-fold>
     $form = $this->createRentalForm($category->getId());
     //</editor-fold>
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $subcat = $this->getDoctrineRepo('AppBundle:Subcategory')->find(intval($data['subcategoryId']));
         // create Candidate object
         $cand = new Candidate();
         $cand->setSubcategory($subcat);
         $cand->setEmail($data['email']);
         // save to database
         $em = $this->getDoctrine()->getManager();
         $em->persist($cand);
         $em->flush();
         // send email
         $this->sendGuidelinesEmail($request, $cand->getEmail(), Category::TYPE_TALENT);
         // successful submission, reset values
         $form = $this->createRentalForm($category->getId(), array('success' => 1));
         return $this->render('rental/offer_form.html.twig', array('category' => $category, 'form' => $form->createView()));
     }
     return $this->render('rental/offer_form.html.twig', array('category' => $category, 'form' => $form->createView()));
 }