/** * @Route("/datapresentation/filter_set", name="datapresentation_filter_set") */ public function filterSetAction(Request $request) { $this->init($request); $this->initForm(); if ($this->form->isSubmitted() && $this->form->isValid()) { $filters = $this->form->getData(); unset($filters['today']); $filtersString = serialize($filters); $cookie = new Cookie('filters', $filtersString, time() + 3600 * 24 * 7, '/'); $response = new Response(); $response->headers->setCookie($cookie); $response->send(); $this->request->cookies->set('filters', $filtersString); } return $this->redirectToRoute('datapresentation'); }
public function createView(Form $form, $template, $parameters, $extraParameters = []) { $html = $this->templating->render($template, $parameters); $response = new JsonResponse(); $response->setData(array_merge($extraParameters, ['submitted' => $form->isSubmitted(), 'errors' => count($form->getErrors(true)), 'html' => $html])); return $response; }
/** * @param Form $form * @param Request $request * * @return bool */ public function process(Form $form, Request $request) { if (!$request->isMethod('POST')) { return false; } $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); $this->em->persist($data); $this->em->flush(); return true; } return false; }
public function buildFilterQuery() { $em = $this->getDoctrine()->getManager(); $qb = $em->createQueryBuilder()->select('a')->from($this->entity, 'a'); if (null !== $this->filterForm) { $this->filterForm->handleRequest($this->request); if ($this->filterForm->isSubmitted() && $this->filterForm->isValid()) { $data = $this->filterForm->getData(); foreach ($data as $name => $value) { if (substr($name, 0, 7) === 'filter_') { $this->filtersType[substr($name, 7)] = $value; } else { if (null !== $value) { $this->filters[] = [$name, $value]; } } } } } foreach ($this->filters as $key => $filter) { $filterType = '='; if (isset($this->filtersType[$filter[0]])) { $filterType = $this->filtersType[$filter[0]]; $value = $filter[1]; if ($this->filtersType[$filter[0]] === 'contains') { $value = '%' . $filter[1] . '%'; $filterType = 'like'; } } if (0 === $key) { $qb->where('a.' . $filter[0] . ' ' . $filterType . ' :a_' . $filter[0])->setParameter('a_' . $filter[0], $value); } else { $qb->andWhere('a.' . $filter[0] . ' ' . $filterType . ' :a_' . $filter[0])->setParameter('a_' . $filter[0], $value); } } return $qb; }
/** * @param Request $request * @param Form $form * @param $entity * @return bool */ private function processForm(Request $request, Form $form, ActivityBase $entity) { $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $key = $request->get('activity') . '_list_eleves'; $this->setSessionValue($key, $request->get("list_eleves")); $entity->setStatus(ActivityBase::STATUS_NOT_REGISTERED); $entity->setDate($this->getDateDay()); $this->mapper->preUpdateEntity($entity); $em = $this->getDoctrineManager(); $em->persist($entity); $em->flush(); return true; } return false; }
/** * Handle CostumerType submission and/or persist and update a costumer entity * * @param CostumerType|Costumer $form A Form instance of a costumer entity * @return bool|Costumer|ConstraintViolationList Return false when form validation errors, * a Costumer instance when created successfully * or a error list when entity has validation errors */ public function create(Costumer $costumer, Form $form = null, Request $request = null) { $canStore = true; if ($form !== null && $request !== null) { // Handle request and validate the submitted form (if submitted) $form->handleRequest($request); if ($form->isSubmitted()) { if (!$form->isValid()) { return false; } } else { $canStore = false; } } elseif ($form !== null && $request === null) { throw new \Exception("The 'request' parameter can't be null if the 'form' parameter was defined"); } else { $validationGroups = null; // []; // Validate the costumer entity using validation service $validator = $this->getValidator(); $errors = $validator->validate($costumer, null, $validationGroups); if (count($errors) > 0) { return $errors; } } // Persist costumer if ($canStore == true) { $conn = $this->getDoctrine()->getConnection(); $objectManager = $this->getDoctrine()->getManager(); try { $conn->beginTransaction(); if ($costumer->getId() === null) { $objectManager->persist($costumer); } $objectManager->flush($costumer); $conn->commit(); return $costumer; } catch (\Exception $e) { $conn->rollBack(); throw $e; } } return null; }
public function testIsSubmitted() { $form = new Form('author', array('validator' => $this->validator)); $this->assertFalse($form->isSubmitted()); $form->submit(array('firstName' => 'Bernhard')); $this->assertTrue($form->isSubmitted()); }
/** * * @param Request $r * @param Form $form * @param boolean $save * @param array $callbackBefore - Array con el método a llamar key = method y un array de parámetros * @param array $callbackAfter * @return boolean */ protected function checkSaveForm(Request $r, Form &$form, $save = true, $callbackBefore = null, $callbackAfter = null) { $form->handleRequest($r); if ($save && $form->isSubmitted() && $form->isValid()) { $obj = $form->getData(); $this->callBackExec($form, $callbackBefore); if (\method_exists($obj, 'beforeSave')) { $obj->beforeSave(); } $this->persist($obj); if (\method_exists($obj, 'afterSave')) { if ($obj->afterSave() == 2) { $this->persist($obj); } } $this->callBackExec($form, $callbackAfter); return true; } else { if ($form->isSubmitted() && !$form->isValid()) { return false; } } return null; }
/** * Get list data. Process filters if submitted. * * @param Form $filter * @return \RunOpenCode\ExchangeRate\Contract\RateInterface[] */ protected function getListData(Form $filter) { if ($filter->isSubmitted() && $filter->isValid()) { return $this->repository->all($filter->getData()); } return $this->repository->all(); }