/** * 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 Request $request * @return Response */ public function getSettingClubAction(Request $request) { $item = json_decode($request->getContent(), true); $em = $this->getDoctrine()->getManager(); $club = $em->getRepository('FfjvBoBundle:Clubs')->find($item['club_id']); if (!$club) { throw $this->createNotFoundException('Unable to find Clubs club.'); } $apiLog = $this->getDoctrine()->getRepository('FfjvBoBundle:WeezeventApiLog')->findOneBy(array('club' => $club)); if (!$apiLog) { $apiLog = new WeezeventApiLog(); $apiLog->setUser($this->getUser()); $apiLog->setClub($club); } $editForm = $this->createEditForm($club); $apiLogForm = $this->getApiLogForm($apiLog); $content = $this->renderView('FfjvBoBundle:Clubs:_setting.html.twig', ['edit_form' => $editForm->createView(), 'weezevent_api_form' => $apiLogForm->createView()]); return new Response(json_encode(['template' => $content, 'item' => $item]), 200, ['Content-Type' => 'applcation/json']); }