public function __wakeup()
 {
     if ($this->location !== null) {
         $this->location->toObject($this);
     } else {
         $this->location = new SelectData();
         $this->location->getFromObject($this);
     }
 }
 /**
  * @Route("/dynamic-form/location", name="dynamic_form_location")
  * @Template()
  */
 public function locationFormAction(Request $request)
 {
     $country = $this->getCountry($request);
     $state = $this->getState($request);
     $city = $this->getCity($request);
     $locationData = new \LoginCidadao\CoreBundle\Model\SelectData();
     if ($city instanceof City) {
         $locationData->setCity($city)->setState($city->getState())->setCountry($city->getState()->getCountry());
     } elseif ($state instanceof State) {
         $locationData->setCity(null)->setState($state)->setCountry($state->getCountry());
     } elseif ($country instanceof Country) {
         $locationData->setCity(null)->setState(null)->setCountry($country);
     }
     $level = $request->get('level');
     $data = new DynamicFormData();
     $data->setPlaceOfBirth($locationData);
     $formBuilder = $this->createFormBuilder($data, array('cascade_validation' => true));
     $this->addPlaceOfBirth($formBuilder, $level);
     return array('form' => $formBuilder->getForm()->createView());
 }
 /**
  * @Route("/client/{clientId}/dynamic-form", name="client_dynamic_form")
  * @Template()
  */
 public function editAction(Request $request, $clientId)
 {
     $client = $this->parseClient($clientId);
     if (!$client instanceof Client) {
         throw $this->createNotFoundException("Client not found.");
     }
     $person = $this->getUser();
     $authorizedScope = $person->getClientScope($client);
     $requestedScope = explode(' ', $request->get('scope', null));
     $scope = $requestedScope;
     // $this->intersectScopes($authorizedScope, $requestedScope);
     /** @var IntentManager $intentManager */
     $intentManager = $this->get('lc.intent.manager');
     $waitEmail = count($scope) === 1 && array_search('email', $scope) !== false;
     if ($waitEmail && $person->getEmailConfirmedAt() instanceof \DateTime) {
         //return $this->redirect($request->get('redirect_url', null));
     }
     $placeOfBirth = new SelectData();
     $placeOfBirth->getFromObject($person);
     $intentUrl = $intentManager->getIntent($request);
     $skipUrl = $request->get('redirect_url', $this->generateUrl('dynamic_form_skip', ['client_id' => $clientId]));
     $data = new DynamicFormData();
     $data->setPerson($person)->setRedirectUrl($request->get('redirect_url', $intentUrl))->setScope($request->get('scope', null))->setPlaceOfBirth($placeOfBirth);
     $dispatcher = $this->getDispatcher();
     $event = new \FOS\UserBundle\Event\GetResponseUserEvent($person, $request);
     $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);
     $formBuilder = $this->createFormBuilder($data, array('cascade_validation' => true));
     foreach ($scope as $curr) {
         $this->addField($request, $formBuilder, $curr, $person);
     }
     $formBuilder->add('redirect_url', 'hidden')->add('scope', 'hidden');
     $form = $formBuilder->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $event = new \FOS\UserBundle\Event\FormEvent($form, $request);
         $dispatcher->dispatch(DynamicFormEvents::POST_FORM_VALIDATION, $event);
         if ($form->has('person')) {
             $event = new \FOS\UserBundle\Event\FormEvent($form->get('person'), $request);
             $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
         }
         $em = $this->getDoctrine()->getManager();
         $person = $formBuilder->getData()->getPerson();
         $address = $formBuilder->getData()->getAddress();
         $idCard = $formBuilder->getData()->getIdCard();
         $placeOfBirth = $formBuilder->getData()->getPlaceOfBirth();
         if ($placeOfBirth instanceof SelectData) {
             $placeOfBirth->toObject($person);
         }
         $userManager = $this->get('fos_user.user_manager');
         $userManager->updateUser($person);
         if ($address instanceof PersonAddress) {
             $address->setPerson($person);
             $em->persist($address);
         }
         if ($idCard instanceof IdCardInterface) {
             $this->getValidationHandler()->persistIdCard($form, $request);
             $em->persist($idCard);
         }
         $response = $this->redirect($formBuilder->getData()->getRedirectUrl());
         $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new \FOS\UserBundle\Event\FilterUserResponseEvent($person, $request, $response));
         $em->flush();
         if ($form->has('person')) {
             $dispatcher->dispatch(DynamicFormEvents::POST_FORM_EDIT, $event);
             $dispatcher->dispatch(DynamicFormEvents::PRE_REDIRECT, $event);
         }
         $person = $userManager->findUserByUsername($person->getUsername());
         if (!$waitEmail || $waitEmail && $person->getConfirmationToken() === null) {
             return $response;
         } else {
             $params = $request->query->all();
             $params['clientId'] = $clientId;
             $url = $this->generateUrl('client_dynamic_form', $params);
             return $this->redirect($url);
         }
     }
     $viewData = compact('client', 'scope', 'authorizedScope', 'skipUrl');
     $viewData['form'] = $form->createView();
     return $viewData;
 }
Beispiel #4
0
 public function setPlaceOfBirth(SelectData $location)
 {
     $location->toObject($this);
 }