/**
  * @param Request $request
  * @param Form $form
  * @param Eleve $eleve
  * @return bool
  */
 private function processPostedForm(Request $request, Form $form, Eleve $eleve, Period $periode)
 {
     $em = $this->getDoctrine()->getManager();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $temporary_taps_to_persist = $eleve->getTaps();
         // retire toutes les inscriptions au TAP pour la période qui ne sont pas
         // et qui n'ont pas été enregistré par le parent
         // dans la nouvelle sélection
         $repo = $em->getRepository('WCSCantineBundle:Eleve');
         $eleve_taps_periode = $repo->findAllTapsForPeriode($eleve, $periode, true);
         foreach ($eleve_taps_periode as $item) {
             if (!$temporary_taps_to_persist->contains($item)) {
                 $em->remove($item);
             }
         }
         // retire toutes les inscriptions à la garderie pour la période qui ne sont pas
         // et qui n'ont pas été enregistré par le parent
         // dans la nouvelle sélection
         $temporary_garderies_to_persist = $eleve->getGarderies();
         $eleve_garderies_periode = $repo->findAllGarderiesForPeriode($eleve, $periode, true);
         foreach ($eleve_garderies_periode as $item) {
             if (!$temporary_garderies_to_persist->contains($item)) {
                 $em->remove($item);
             }
         }
         $eleve->setTapgarderieSigned(true);
         $em->flush();
         return true;
     }
     return false;
 }
 /**
  * @param Request $request
  */
 public function bindRequest(Request $request)
 {
     $this->form->handleRequest($request);
     foreach ($this->tabs as $tab) {
         $tab->bindRequest($request);
     }
 }
 /**
  * @return bool
  */
 public function process()
 {
     $this->form->handleRequest($this->request);
     if ($this->form->isValid()) {
         return $this->onSuccess();
     }
     return false;
 }
 /**
  * @param Request $request
  * @param Form $form
  * @param Eleve $eleve
  * @return bool
  */
 private function processPostedForm(Request $request, Form $form, Eleve $eleve)
 {
     $em = $this->getDoctrine()->getManager();
     $form->handleRequest($request);
     if ($form->isValid()) {
         // la nouvelle sélection de dates (avec celles déjà présentes en
         // base de données, et les nouvelles à ajouter
         // (cette liste a été mise à jour avec LunchToStringTransformer)
         $lunchesNew = $eleve->getLunches();
         // récupère les réservations actuellement en base de données
         $lunchesOld = $em->getRepository("WCSCantineBundle:Lunch")->findByEleve($eleve);
         // supprime les dates qui ne sont plus sélectionnées
         foreach ($lunchesOld as $lunchOld) {
             if (!$lunchesNew->contains($lunchOld)) {
                 $em->remove($lunchOld);
             }
         }
         $eleve->setCanteenSigned(true);
         // met à jour la fiche élève (le régime alimentaire,...)
         $em->persist($eleve);
         $em->flush();
         return true;
     }
     return false;
 }
 public function bindForm(Request $request)
 {
     $this->form->handleRequest($request);
     if ($this->form->isValid()) {
         $this->writeTranslationsToFile($request->request->all());
         return true;
     }
     return false;
 }
 /**
  * @param Form $form
  * @throws MethodNotAllowedException
  * @throws ValidatorException
  */
 protected function handle(Form $form)
 {
     if (false === $this->getRequest()->isMethod('POST')) {
         throw new MethodNotAllowedException(array('POST'), 'Form can be posted only by "POST" method.');
     }
     $form->handleRequest($this->getRequest());
     if (false === $form->isValid()) {
         throw new ValidatorException('Form object validation failed, form is invalid.');
     }
 }
 /**
  * @param \Symfony\Component\Form\Form $form
  * @param \Symfony\Component\HttpFoundation\Request $request
  */
 private function processForm(Form $form, Entry $entry, Request $request)
 {
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->getEm()->persist($entry);
         $this->getEm()->flush();
         return true;
     }
     return false;
 }
 /**
  * @param Request $request
  * @param Form    $form
  *
  * @return array|boolean
  */
 public function handleConfigForm(Request $request, Form $form)
 {
     if ($request->isMethod('post')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             return $form->getData();
         }
     }
     return false;
 }
Beispiel #9
0
 public function process(Form $form, Request $request)
 {
     if (!$request->isMethod('POST')) {
         return false;
     }
     $form->handleRequest($request);
     if ($form->isValid()) {
         return $this->processValidForm($form, $request);
     }
     return false;
 }
 /**
  * @param Form $form
  * @param Request $request
  * @return bool|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 private function handleFormRequest(Form $form, Request $request)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $userEntity = $this->initUser($form->getData());
     $em = $this->getDoctrine()->getManager();
     $em->persist($userEntity);
     $em->flush();
     return true;
 }
Beispiel #11
0
 /**
  * validate
  *
  * @param Form    $form    Form
  * @param Request $request Request
  *
  * @return boolean
  */
 public function validate(Form $form, Request $request)
 {
     if ($this->hasMethod($request->getMethod())) {
         if ($request->getMethod() != 'POST') {
             $form->submit($request);
         } else {
             $form->handleRequest($request);
         }
         return $form->isValid();
     }
     return false;
 }
 /**
  * @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;
 }
 private function isValid(Request $request, Form $form)
 {
     $session = $request->getSession();
     if ('POST' === $request->getMethod()) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $sessionData = $session->get(self::SESSION_KEY) ?: array();
             $formData = array_replace_recursive($sessionData, $form->getData());
             $session->set(self::SESSION_KEY, $formData);
             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 string $key
  * @return RedirectResponse|Response
  * @throws NotFoundHttpException
  */
 public function onlyAction(Request $request, $key)
 {
     $ajaxTemplates = $this->container->getParameter('l91.sulu.form.ajax_templates');
     if (!$ajaxTemplates[$key]) {
         throw new NotFoundHttpException();
     }
     $this->form = $this->getFormHandler()->get($key, $request->query->all());
     if ($request->isMethod('post')) {
         $this->form->handleRequest($request);
         if ($this->getFormHandler()->handle($this->form)) {
             return new RedirectResponse('?send=true');
         }
     }
     return $this->render($ajaxTemplates[$key], array('form' => $this->form->createView()));
 }
 /**
  * @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;
 }
    public function it_return_json_with_success_status_and_create_sonata_notification(Request $request, Session $session, Form $composerForm, AMQPBackendDispatcher $sonataNotificationsBackend)
    {
        $composerJsonContent = <<<'EOT'
{
    "require": {
        "monolog/monolog": "1.2.*"
    }
}
EOT;
        $composerForm->handleRequest($request)->shouldBeCalled();
        $composerForm->isValid()->shouldBeCalled()->willReturn(true);
        $composerForm->getData()->shouldBeCalled()->willReturn(array('body' => $composerJsonContent, 'hasDevDependencies' => false));
        $request->getSession()->shouldBeCalled()->willReturn($session);
        $session->get('channelName')->shouldBeCalled()->willReturn('example_channel_name');
        $sonataNotificationsBackend->createAndPublish('upload.composer', array('body' => $composerJsonContent, 'channelName' => 'example_channel_name', 'hasDevDependencies' => false))->shouldBeCalled();
        $this->uploadComposerAction($request)->shouldBeJsonResponse(array('status' => 'ok'));
    }
Beispiel #18
0
 /**
  * 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;
 }
 /**
  * @param Request $request
  * @param Form $form
  * @return bool
  */
 private function processForm(Request $request, Form $form)
 {
     $form->handleRequest($request);
     if ($request->getMethod() == 'POST') {
         //        if ($form->isSubmitted()) {
         $em = $this->getDoctrineManager();
         $repo = $em->getRepository($this->mapper->getEntityClassName());
         foreach (explode(',', $form["status"]->getData()) as $id) {
             if (!empty($id)) {
                 $entity = $repo->find($id);
                 if ($entity) {
                     $entity->setStatus(ActivityBase::STATUS_REGISTERED_AND_PRESENT);
                     $em->persist($entity);
                 }
             }
         }
         $em->flush();
         return true;
     }
     return false;
 }
 protected function processForm($type, Form $form)
 {
     $repo = $this->get('social.publishing.repository');
     $form->handleRequest($this->getRequest());
     // remove the current edited entity from the listing
     if (!is_null($form->getData())) {
         $param['skipped_pub'] = $form->getData()->getId();
     }
     if ($form->isValid()) {
         $newPost = $form->getData();
         try {
             $repo->persist($newPost);
             $this->pushFlash('notice', 'Message saved');
             return $this->redirectRouteOk('wall_index', ['wallNick' => $this->getUser()->getUsername(), 'wallFilter' => 'self'], 'anchor-' . $newPost->getId());
         } catch (\MongoException $e) {
             $this->pushFlash('warning', 'Cannot save message');
         }
     }
     $param['form'] = $form->createView();
     $template = "TrismegisteSocialBundle:Content:form/{$type}.html.twig";
     return $this->renderWall($this->getUser()->getUsername(), 'self', $template, $param);
 }
 /**
  * {@inheritDoc}
  */
 public function process(Request $request, Form $form, UserResponseInterface $userInformation)
 {
     $user = $this->userManager->createUser();
     // Try to get some properties for the initial form when coming from github
     if ('GET' === $request->getMethod()) {
         $user->setUsername($this->getUniqueUsername($userInformation->getNickname()));
         $user->setEmail($userInformation->getEmail());
     }
     $form->setData($user);
     if ('POST' === $request->getMethod()) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $randomPassword = $this->tokenGenerator->generateToken();
             $user->setPlainPassword($randomPassword);
             $user->setEnabled(true);
             $apiToken = substr($this->tokenGenerator->generateToken(), 0, 20);
             $user->setApiToken($apiToken);
             return true;
         }
     }
     return false;
 }
 /**
  * 
  * @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;
 }
Beispiel #23
0
 /**
  * Processes the form
  *
  * @param Form    $form
  * @param Request $request
  *
  * @return bool|mixed
  */
 protected function process_form(Form $form, Request $request)
 {
     if (!$request->isMethod('POST')) {
         return false;
     }
     $form->handleRequest($request);
     return $form->isValid() ? $form->getData() : false;
 }
 /**
  * @param Form $form
  * @param Request $request
  * @return bool
  */
 private function processForm(Form $form, Request $request)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $om = $this->getDoctrine()->getManagerForClass(Subscription::class);
     $om->persist($form->getData());
     $om->flush();
     return true;
 }
Beispiel #25
0
 /**
  * Binds form data, checks validity, and determines cancel request
  *
  * @param Form $form
  *
  * @return int
  */
 protected function isFormValid(Form &$form)
 {
     //bind request to the form
     $form->handleRequest($this->request);
     return $form->isValid();
 }
 /**
  * @param Form $form
  * @param Request $request
  * @return bool
  */
 private function processForm(Form $form, Request $request)
 {
     $participants = $form->getData()->getParticipants()->toArray();
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     // Gestion de la suppression des participants
     $participantOm = $this->getDoctrine()->getManagerForClass(Participant::class);
     foreach ($participants as $participant) {
         if (!$form->getData()->getParticipants()->contains($participant)) {
             $participantOm->remove($participant);
         }
     }
     $participantOm->flush();
     $artworkOm = $this->getDoctrine()->getManagerForClass(Artwork::class);
     $artworkOm->persist($form->getData());
     $artworkOm->flush();
     return true;
 }
 /**
  * Adds Topic to database if form is valid
  * 
  * @param Form  $topicForm
  * @param Topic $topic
  * @param string   $parentSlug
  * 
  * @return RedirectResponse|null
  */
 protected function addTopic(Form $topicForm, Topic $topic, $parentSlug)
 {
     $topicForm->handleRequest($this->request);
     if ($topicForm->isValid()) {
         try {
             $this->getDoctrine()->getManager()->getFilters()->disable('softdeleteable');
             $this->getTopicManager()->update($topic);
             $this->getDoctrine()->getManager()->getFilters()->enable('softdeleteable');
             $this->addFlash('success', $this->translator->trans('topic.has.been.created'));
             return $this->redirect($this->generateUrl('topic_show', array('slug' => $topic->getSlug())));
         } catch (Exception $ex) {
             throw $ex;
             $this->addFlash('danger', $this->translator->trans('topic.has.not.been.created'));
             return $this->redirect($this->generateUrl('forum_index', array('slug' => $parentSlug)));
         }
     }
     return;
 }
 public function testRequestWithoutStringShouldThrowException()
 {
     $this->setExpectedExceptionRegExp('InvalidArgumentException', '/^Invalid argument: the submitted variable must be a string when you enable the json_format option.$/');
     $request = $this->getRequest(['test']);
     $this->form->handleRequest($request);
 }
Beispiel #29
0
 /**
  * @param Request $request
  * @param Form $form
  * @return $this
  */
 public function load(Request $request, Form $form)
 {
     $this->_load($request, $form->getConfig()->getMethod(), $form->getName());
     $form->handleRequest($request);
     return $this;
 }
 /**
  * Save a content entity
  *
  * @param \Symfony\Component\HttpFoundation\Request
  * @param \Leapt\AdminBundle\Admin\ContentAdmin $admin
  * @param \Symfony\Component\Form\Form $form
  * @param object $entity
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  * @throws ValidationException
  */
 protected function save(Request $request, ContentAdmin $admin, Form $form, $entity)
 {
     $form->handleRequest($request);
     if ($form->isValid()) {
         $admin->saveEntity($entity);
     } else {
         throw new ValidationException('could not save');
     }
 }