/** * Creates a new WeezeventApiLog entity. * */ public function newAction(Request $request) { $weezeventApiLog = new WeezeventApiLog(); $form = $this->createForm(WeezeventApiLogType::class, $weezeventApiLog->toArray(), ['app_service' => $this->get('app_service')->setUser($this->getUser())])->add('submit', SubmitType::class); $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); $em = $this->getDoctrine()->getManager(); $club = $em->getRepository('FfjvBoBundle:Clubs')->find($data['club_id']); if (!$club) { throw new \Exception('Club unknown'); } $weezeventApiLog = $this->getDoctrine()->getRepository('FfjvBoBundle:WeezeventApiLog')->findOneBy(array('club' => $club)); if (!$weezeventApiLog) { $weezeventApiLog = new WeezeventApiLog(); } $weezeventApiLog->setClub($club); $weezeventApiLog->setUser($this->getUser()); $weezeventApiLog->setApiPassword($data['api_password']); $weezeventApiLog->setApiKey($data['api_key']); $weezeventApiLog->setApiUsername($data['api_username']); if ($this->get('weezeventapi')->setAuthAccess($data['api_username'], $data['api_password'], $data['api_key'])->initConnection()) { $em->persist($weezeventApiLog); $em->flush(); $this->addFlash('success', 'Connection successfully'); return $this->redirectToRoute('clubs_show', array('id' => $club->getId())); } } $this->addFlash('error', 'Wrong loging submit'); return $this->redirectToRoute('clubs_show', array('id' => $club->getId())); }
/** * @param WeezeventApiLog $apiLog * @return $this|\Symfony\Component\Form\FormInterface */ private function getApiLogForm(WeezeventApiLog $apiLog) { return $this->createForm(WeezeventApiLogType::class, $apiLog->toArray(), ['method' => 'POST', 'action' => $this->generateUrl('weezeventapilog_new'), 'app_service' => $this->get('app_service')->setUser($this->getUser())])->add('submit', SubmitType::class, ['label' => 'submit', 'attr' => ['class' => 'btn btn-success']]); }