/** * Reference purchase summary * * @Route() * @Method({"GET", "POST"}) * @Template() * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request) { $previouslyPostedData = null; // if we are not posting new data, and a request for $this->formType is stored in the session, prepopulate the form with the stored request $storedRequest = unserialize($request->getSession()->get($this->formType->getName())); if ($request->isMethod('GET') && $storedRequest instanceof Request) { $previouslyPostedData = $this->createForm($this->formType)->handleRequest($storedRequest)->getData(); } $form = $this->createForm($this->formType, $previouslyPostedData); if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { // Persist the case to IRIS /** @var ReferencingCase $case */ $case = $form->getData()['case']; $this->irisEntityManager->persist($case); /** @var ReferencingApplication $application */ foreach ($case->getApplications() as $application) { // Always default $application->setSignaturePreference(SignaturePreference::SCAN_DECLARATION); $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId())); // Persist each guarantor of the application if (null !== $application->getGuarantors()) { foreach ($application->getGuarantors() as $guarantor) { $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId())); } } } $request->getSession()->set('submitted-case', serialize($case)); // Send the user to the success page return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_newreference_tenancyagreement_index'), 301); } } return array('form' => $form->createView()); }
/** * @param FormInterface $form * @param Request $request * @return AccountUser|bool */ public function process(FormInterface $form, Request $request) { if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { $email = $form->get('email')->getData(); /** @var AccountUser $user */ $user = $this->userManager->findUserByUsernameOrEmail($email); if ($this->validateUser($form, $email, $user)) { if (null === $user->getConfirmationToken()) { $user->setConfirmationToken($user->generateToken()); } try { $this->userManager->sendResetPasswordEmail($user); $user->setPasswordRequestedAt(new \DateTime('now', new \DateTimeZone('UTC'))); $this->userManager->updateUser($user); return $user; } catch (\Exception $e) { $this->addFormError($form, 'oro.email.handler.unable_to_send_email'); } } } } return false; }
/** * Add a new Article or edit an existing Article * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function editAction() { $slug = $this->request->get('slug'); if ($slug === null) { $article = new Article(); } else { $article = $this->articleService->getArticleBySlug($slug); if (empty($article)) { return $this->redirect($this->generateUrl('article_dashboard')); } } $form = $this->createForm(new ArticleType(), $article); if ($this->request->isMethod('POST')) { $form->handleRequest($this->request); if ($form->isValid()) { $file = $form->get('file')->getData(); $uniqueFileName = $this->uploadService->uploadFile($file); $article->setPictureName($uniqueFileName); $article->setAuthor($this->getUser()); $this->articleService->save($article); return $this->redirect($this->generateUrl('article_view', array('slug' => $article->getSlug()))); } } return $this->render('AppBundle:Article:edit.html.twig', array('form' => $form->createView())); }
public function ajaxEditGlobalAwardAction() { $globalAward = $this->getDoctrine()->getRepository('HelperBundle:GlobalAward')->find($this->request->get('globalAwardId', 0)); if (!$globalAward) { throw $this->createNotFoundException('Invalid global award'); } $propertyType = $this->get('services.institution_property')->getAvailablePropertyType(InstitutionPropertyType::TYPE_GLOBAL_AWARD); $imcProperty = $this->imcService->getPropertyValue($this->institutionMedicalCenter, $propertyType, $globalAward->getId(), $this->request->get('propertyId', 0)); $imcProperty->setValueObject($globalAward); $editGlobalAwardForm = $this->createForm(new InstitutionGlobalAwardFormType(), $imcProperty); if ($this->request->isMethod('POST')) { $editGlobalAwardForm->bind($this->request); if ($editGlobalAwardForm->isValid()) { $imcProperty = $editGlobalAwardForm->getData(); $em = $this->getDoctrine()->getEntityManager(); $em->persist($imcProperty); $em->flush(); // Invalidate InstitutionMedicalCenterProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId())); $output = array('status' => true, 'extraValue' => $imcProperty->getExtraValue()); $response = new Response(\json_encode($output), 200, array('content-type' => 'application/json')); } else { $response = new Response('Form error', 400); } } return $response; }
/** * Prepare & process form * * @author Jeremie Samson <*****@*****.**> * * @return bool */ public function process() { if ($this->request->isMethod('POST')) { $this->form->handleRequest($this->request); if ($this->form->isValid()) { /** @var ModelUserRole $model */ $model = $this->form->getData(); if (!$model->getUser() || !$model->getRole()) { $this->form->addError(new FormError('Missing parameter(s)')); } /** @var User $user */ $user = $this->em->getRepository('UserBundle:User')->find($model->getUser()); /** @var Post $role */ $role = $this->em->getRepository('FaucondorBundle:Post')->find($model->getRole()); if (!$user) { $this->form->get('user')->addError(new FormError('User with id ' . $model->getUser() . ' not found ')); } if (!$role) { $this->form->get('role')->addError(new FormError('Role with id ' . $model->getRole() . ' not found ')); } $this->onSuccess($user, $role); return true; } } return false; }
/** * Determines if redirect may be performed. * * @param Request $request * The current request object. * @param string $route_name * The current route name. * * @return bool * TRUE if redirect may be performed. */ public function canRedirect(Request $request, $route_name = NULL) { $can_redirect = TRUE; if (isset($route_name)) { $route = $this->routeProvider->getRouteByName($route_name); if ($this->config->get('access_check')) { // Do not redirect if is a protected page. $can_redirect = $this->accessManager->checkNamedRoute($route_name, [], $this->account); } } else { $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); } if (strpos($request->getScriptName(), 'index.php') === FALSE) { // Do not redirect if the root script is not /index.php. $can_redirect = FALSE; } elseif (!($request->isMethod('GET') || $request->isMethod('HEAD'))) { // Do not redirect if this is other than GET request. $can_redirect = FALSE; } elseif ($this->state->get('system.maintenance_mode') || defined('MAINTENANCE_MODE')) { // Do not redirect in offline or maintenance mode. $can_redirect = FALSE; } elseif ($this->config->get('ignore_admin_path') && isset($route)) { // Do not redirect on admin paths. $can_redirect &= !(bool) $route->getOption('_admin_route'); } return $can_redirect; }
public function ajoutDetailsWEIAction(Request $request) { $em = $this->getDoctrine()->getManager(); if ($request->isMethod('POST')) { $id = $_POST['id']; } else { $id = $_GET['id']; } $detailsWEI = $this->serviceMembre->GetDetailsByIdEtudiant($id); if ($detailsWEI == NULL) { $detailsWEI = new DetailsWEI(); } $etu = $this->serviceMembre->GetEtudiantById($id); if (boolval($em->getRepository("BdEMainBundle:Config")->get("wei.bungMixtes"))) { $sexeEtu = -1; } elseif ($etu->getCivilite() == "M") { $sexeEtu = "M"; } else { $sexeEtu = "F"; } $form = $this->createForm(new DetailsWEIType($sexeEtu, $detailsWEI->getBus(), $detailsWEI->getBungalow()), $detailsWEI); if ($request->isMethod('POST')) { $form->bind($request); if ($form->isValid()) { $bizuth = $this->serviceMembre->GetEtudiantById($request->request->get('id')); $detailsWEI->setIdEtudiant($bizuth); $em->persist($detailsWEI); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'Details enregistres'); return $this->redirect($this->generateUrl('bde_wei_inscription_rechercheBizuthWEI')); } } return $this->render('BdEWeiBundle:Default:ajoutDetailsWEI.html.twig', array('form' => $form->createView(), 'id' => $request->query->get('id'))); }
/** * Prepare & process form * * @author Jeremie Samson <*****@*****.**> * * @return bool */ public function process() { if ($this->request->isMethod('POST')) { $this->form->handleRequest($this->request); if ($this->form->isValid()) { /** @var ModelUser $user */ $user = $this->form->getData(); if (!$user->getFirstname() || !$user->getLastname() || !$user->getEmailGalaxy() || !$user->getSection()) { $this->form->addError(new FormError('Missing parameter(s)')); } else { if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL) || !filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) { $error = new FormError('email invalid'); if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL)) { $this->form->get('email')->addError($error); } if (!filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) { $this->form->get('emailGalaxy')->addError($error); } } else { $section_id = $this->em->getRepository('FaucondorBundle:Section')->find($user->getSection()); $section_code = $this->em->getRepository('FaucondorBundle:Section')->findOneBy(array("code" => $user->getSection())); if (!$section_id && !$section_code) { $this->form->get('section')->addError(new FormError('Section with id ' . $user->getSection() . ' not found')); } else { /** @var Section $section */ $section = $section_id ? $section_id : $section_code; $this->onSuccess($user, $section); return true; } } } } } return false; }
/** * */ public function getHttpVars() : array { if ($this->request->isMethod('POST')) { $http_vars = $this->request->request->all(); } else { $http_vars = $this->request->query->all(); } return $http_vars; }
/** * Returns the GET or POST parameters form the request. * * @return ParameterBag */ protected function getRequestParameters() { if ($this->request->isMethod('POST')) { $parameters = $this->request->request; } else { $parameters = $this->request->query; } return $parameters; }
public function apply(Request $request, ParamConverter $configuration) { if ($request->isMethod('POST') && !empty($configuration->getOptions()['request_path'])) { $requestPath = $configuration->getOptions()['request_path']; $request->attributes->set($requestPath, $request->request->get($requestPath)); } elseif ($request->isMethod('GET') && !empty($configuration->getOptions()['query_path'])) { $queryPath = $configuration->getOptions()['query_path']; $request->attributes->set($queryPath, $request->query->get($queryPath)); } return parent::apply($request, $configuration); }
/** * Process form * * @param RFPRequest $rfpRequest * @return bool True on successful processing, false otherwise */ public function process(RFPRequest $rfpRequest) { if ($this->request->isMethod('POST')) { $this->form->submit($this->request); if ($this->form->isValid()) { $this->onSuccess($rfpRequest); return true; } } return false; }
/** * @param Quote $quote * @return Order|null */ public function process(Quote $quote) { $this->form->setData($quote); if ($this->request->isMethod('POST')) { $this->form->submit($this->request); if ($this->form->isValid()) { return $this->onSuccess($quote, $this->form->getData()); } } return null; }
/** * {@inheritdoc} */ public function process($entity) { $this->form->setData($entity); if ($this->request->isMethod('POST')) { $this->form->submit($this->request); if ($this->form->isValid()) { $this->saver->save($entity); return true; } } return false; }
/** * Process method for handler * @param AssociationType $associationType * * @return boolean */ public function process(AssociationType $associationType) { $this->form->setData($associationType); if ($this->request->isMethod('POST')) { $this->form->submit($this->request); if ($this->form->isValid()) { $this->onSuccess($associationType); return true; } } return false; }
/** * Process method for handler * @param Channel $channel * * @return boolean */ public function process(Channel $channel) { $this->form->setData($channel); if ($this->request->isMethod('POST')) { $this->form->bind($this->request); if ($this->form->isValid()) { $this->onSuccess($channel); return true; } } return false; }
/** * Process method for handler * * @param Family $family * * @return boolean */ public function process(Family $family) { $this->form->setData($family); if ($this->request->isMethod('POST')) { $this->form->submit($this->request); if ($this->form->isValid()) { $this->onSuccess($family); return true; } } return false; }
/** * Process form * * @param AccountGroup $entity * @return bool True on successful processing, false otherwise */ public function process(AccountGroup $entity) { $this->form->setData($entity); if ($this->request->isMethod('POST')) { $this->form->submit($this->request); if ($this->form->isValid()) { $this->onSuccess($entity, $this->form->get('appendAccounts')->getData(), $this->form->get('removeAccounts')->getData()); return true; } } return false; }
/** * Process method for handler * @param AttributeGroup $group * * @return boolean */ public function process(AttributeGroup $group) { $this->form->setData($group); if ($this->request->isMethod('POST')) { $this->form->bind($this->request); if ($this->form->isValid()) { $this->onSuccess($group); return true; } } return false; }
/** * Process method for handler * @param AbstractAttribute $entity * * @return boolean */ public function process(AbstractAttribute $entity) { $this->addMissingOptionValues($entity); $this->form->setData($entity); if ($this->request->isMethod('POST')) { $oldOptions = clone $entity->getOptions(); $this->form->submit($this->request); if ($this->form->isValid()) { $this->onSuccess($entity, $oldOptions); return true; } } return false; }
function it_handles_form(Request $request, FormFactoryInterface $formFactory, FormBuilderInterface $formBuilder, FormInterface $form, FileBag $fileBag, ObjectManager $manager) { $formFactory->createNamedBuilder('', 'kreta_dummy_type', null, [])->shouldBeCalled()->willReturn($formBuilder); $formBuilder->getForm()->shouldBeCalled()->willReturn($form); $request->isMethod('POST')->shouldBeCalled()->willReturn(false); $request->isMethod('PUT')->shouldBeCalled()->willReturn(false); $request->isMethod('PATCH')->shouldBeCalled()->willReturn(true); $form->handleRequest($request)->shouldBeCalled()->willReturn($form); $form->isValid()->shouldBeCalled()->willReturn(true); $form->getData()->shouldBeCalled()->willReturn($this->object); $request->files = $fileBag; $manager->persist($this->object)->shouldBeCalled(); $manager->flush()->shouldBeCalled(); $this->handleForm($request)->shouldReturn($form); }
public function guideShareAction(Request $request) { $slug = $request->get('slug'); $eguide = $this->getDoctrine()->getRepository('BugglMainBundle:EGuide')->findOneBySlug($slug); $localAuthor = $this->get('security.context')->getToken()->getUser(); if (is_null($eguide) || $eguide->getLocalAuthor()->getId() != $localAuthor->getId()) { $this->get('session')->setFlash('error', 'The guide does not exist or is not yours!'); return new RedirectResponse($this->generateUrl('local_author_dashboard')); } $socialMedia = $this->get('buggl_main.entity_repository')->getRepository('BugglMainBundle:SocialMedia')->findByLocalAuthor($localAuthor); $prevEmails = ''; $invalidMessage = ''; if ($request->isMethod('POST')) { $invalidEmails = array(); $validEmails = array(); $prevEmails = $request->request->get('emails', ''); // TODO: maybe refactor email validation in a separate service $localReferenceService = $this->get('buggl_main.local_reference_service'); $validationData = $localReferenceService->validateEmails($prevEmails); $invalidMessage = $validationData['invalidMessage']; if (empty($invalidMessage)) { $prevEmails = ''; exec('../app/console buggl:guide_share_email ' . implode(',', $validationData['validEmails']) . ' ' . $eguide->getId() . ' > /dev/null 2>&1 &'); $this->get('session')->getFlashBag()->add('success', "Guide has been shared!"); return new RedirectResponse($this->generateUrl('e_guide_share', array('slug' => $eguide->getSlug()))); } } $data = array('eguide' => $eguide, 'socialMedia' => $socialMedia, 'invalidMessage' => $invalidMessage, 'prevEmails' => $prevEmails); return $this->render('BugglMainBundle:LocalAuthor/EGuideShare:share.html.twig', $data); }
/** * {@inheritdoc} */ protected function requiresAuthentication(Request $request) { if ($this->options['post_only'] && !$request->isMethod('POST')) { return false; } return parent::requiresAuthentication($request); }
/** * {@inheritdoc} */ public function filter(RouteCollection $collection, Request $request) { // The Content-type header does not make sense on GET requests, because GET // requests do not carry any content. Nothing to filter in this case. if ($request->isMethod('GET')) { return $collection; } $format = $request->getContentType(); foreach ($collection as $name => $route) { $supported_formats = array_filter(explode('|', $route->getRequirement('_content_type_format'))); if (empty($supported_formats)) { // No restriction on the route, so we move the route to the end of the // collection by re-adding it. That way generic routes sink down in the // list and exact matching routes stay on top. $collection->add($name, $route); } elseif (!in_array($format, $supported_formats)) { $collection->remove($name); } } if (count($collection)) { return $collection; } // We do not throw a // \Symfony\Component\Routing\Exception\ResourceNotFoundException here // because we don't want to return a 404 status code, but rather a 415. throw new UnsupportedMediaTypeHttpException('No route found that matches "Content-Type: ' . $request->headers->get('Content-Type') . '"'); }
public function newarticleAction(Request $request) { $em = $this->getDoctrine()->getManager(); $article = new Article(); $form = $this->createForm(new ArticleType($em), $article); if ($request->isMethod('POST')) { $form->handleRequest($request); $thumbnail = $article->getThumbnail(); $thumbnailName = md5(uniqid()) . '.' . $thumbnail->guessExtension(); $thumbnailDir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/thumbnail'; $thumbnail->move($thumbnailDir, $thumbnailName); $article->setThumbnail('uploads/thumbnail/' . $thumbnailName); $banner = $article->getBanner(); $bannerName = md5(uniqid()) . '.' . $banner->guessExtension(); $bannerDir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/banner'; $banner->move($bannerDir, $bannerName); $article->setBanner('uploads/banner/' . $bannerName); $article->setDate(new \DateTime("now")); $article->setUser($this->get('security.token_storage')->getToken()->getUser()); if (!$form->isValid()) { return $this->redirectToRoute('aved_new_article'); } $em->persist($article); $em->flush(); return $this->redirectToRoute('aved_new_article'); } return $this->render('AvedBlogBundle:Default:new_article.html.twig', array('form' => $form->createView())); }
/** * Generates the robots administration form and fills it with a default value if needed. * * @Route(path="/", name="KunstmaanSeoBundle_settings_robots") * @Template(template="@KunstmaanSeo/Admin/Settings/robotsSettings.html.twig") * @param Request $request * @return array|RedirectResponse */ public function robotsSettingsAction(Request $request) { $this->checkPermission(); $em = $this->getDoctrine()->getManager(); $repo = $this->getDoctrine()->getRepository("KunstmaanSeoBundle:Robots"); $robot = $repo->findOneBy(array()); $default = $this->container->getParameter('robots_default'); $isSaved = true; if (!$robot) { $robot = new Robots(); } if ($robot->getRobotsTxt() == NULL) { $robot->setRobotsTxt($default); $isSaved = false; } $form = $this->createForm(new RobotsType(), $robot); if ($request->isMethod('POST')) { $form->handleRequest($request); if ($form->isValid()) { $em->persist($robot); $em->flush(); return new RedirectResponse($this->generateUrl('KunstmaanSeoBundle_settings_robots')); } } if (!$isSaved) { $warning = $this->get('translator')->trans('seo.robots.warning'); $this->get('session')->getFlashBag()->add('warning', $warning); } return array('form' => $form->createView()); }
function it_throws_exception_if_product_with_given_id_does_not_exist($productRepository, CartItemInterface $item, Request $request) { $request->isMethod('POST')->willReturn(true); $request->get('id')->willReturn(5); $productRepository->findOneBy(['id' => 5, 'channels' => null])->willReturn(null); $this->shouldThrow(ItemResolvingException::class)->duringResolve($item, $request); }
public function shareBugglAction(Request $request) { $prevEmails = ''; $invalidMessage = ''; if ($request->isMethod('POST')) { $invalidEmails = array(); $validEmails = array(); $prevEmails = $request->request->get('emails', ''); $localReferenceService = $this->get('buggl_main.local_reference_service'); $validationData = $localReferenceService->validateEmails($prevEmails); $invalidMessage = $validationData['invalidMessage']; if (empty($invalidMessage)) { $shareService = $this->get('buggl_main.share'); $user = $this->get('security.context')->getToken()->getUser(); foreach ($validationData['validEmails'] as $key => $email) { $share = $shareService->saveShareInfo($email, $user); } $prevEmails = ''; exec('../app/console buggl:email_shares > /dev/null 2>&1 &'); $streetCreditService = $this->get('buggl_main.street_credit'); $streetCreditService->updateShareStatus($user); $this->get('session')->getFlashBag()->add('success', "Emails sent!"); } } $localAuthor = $this->get('security.context')->getToken()->getUser(); //$streetCredit = $this->getDoctrine()->getRepository("BugglMainBundle:StreetCredit")->findOneByLocalAuthor($localAuthor); $newEGuideRequestCount = $this->getDoctrine()->getEntityManager()->getRepository('BugglMainBundle:MessageToUser')->countRequestByStatus($localAuthor, array('0' => '0')); $data = array('invalidMessage' => $invalidMessage, 'prevEmails' => $prevEmails, 'newRequestCount' => $newEGuideRequestCount); return $this->render('BugglMainBundle:LocalAuthor\\EarnMore:shareBuggl.html.twig', $data); }
/** * Automatically generated run method * * @param Request $request * @return Response */ public function run(Request $request) { $id = $this->getParam('id'); $sport = SportQuery::create()->findOneById($id); $data = ['sport' => $sport]; $payload = new Blank($data); if ($request->isMethod('POST')) { $post = $request->request; $domain = new SportDomain($this->getServiceContainer()); $serializer = Sport::getSerializer(); $fields = $serializer->getFields(); $attribs = []; foreach ($fields as $field) { if ($post->has($field)) { $attribs[$field] = $post->get($field); } } $attribs['feature_composition'] = $post->has('feature_composition'); $attribs['feature_tester'] = $post->has('feature_tester'); $payload = $domain->update($id, ['meta' => $post->get('meta', []), 'attributes' => $attribs]); if ($payload instanceof NotValid) { $payload = new NotValid(array_merge($data, $payload->get())); } } return $this->responder->run($request, $payload); }
public function infiniteScroll($contenttypeslug, Request $request) { $contenttype = $this->app['storage']->getContenttype($contenttypeslug); if (empty($contenttype)) { return 'Not a valid contenttype'; } if ($request->isMethod('GET')) { $page = $request->request->get('page'); $amount = !empty($contenttype['listing_records']) ? $contenttype['listing_records'] : $this->app['config']->get('general/listing_records'); $order = !empty($contenttype['sort']) ? $contenttype['sort'] : $this->app['config']->get('general/listing_sort'); $content = $this->app['storage']->getContent($contenttype['slug'], array('limit' => $amount, 'order' => $order, 'page' => $page, 'paging' => true)); if (empty($contenttype['infinitescroll_template'])) { $this->app['twig.loader.filesystem']->addPath(dirname(__DIR__) . '/assets/views'); $template = 'listing_ajax.html.twig'; } else { $template = $contenttype['infinitescroll_template']; } $globals = ['records' => $content, $contenttype['slug'] => $content, 'contenttype' => $contenttype['name']]; if ($content) { return $this->app['render']->render($template, [], $globals); } else { return 'No more posts'; } } }