/**
  * @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;
 }
 /**
  * {@inheritdoc}
  */
 public function chooseGroups(FormInterface $form)
 {
     $phoneData = $form->get('phone')->getData();
     $mobileData = $form->get('mobile')->getData();
     // All other fields are validated through the Default validation group
     $validation_groups = array('Default');
     // If both or neither phone and mobile fields are given,
     // validate both fields
     if (empty($phoneData) && empty($mobileData)) {
         $validation_groups[] = 'phone';
         $validation_groups[] = 'mobile';
     } else {
         // If only phone field alone is given, validate, but
         // not mobile. Only 1 is required.
         if (!empty($phoneData)) {
             $validation_groups[] = 'phone';
         }
         // If only mobile field alone is given, validate, but
         // not phone. Only 1 is required.
         if (!empty($mobileData)) {
             $validation_groups[] = 'mobile';
         }
     }
     return $validation_groups;
 }
 /**
  * {@inheritdoc}
  */
 public function chooseGroups(FormInterface $form)
 {
     if (!$form->get('flat')->getData() && !$form->get('houseName')->getData() && !$form->get('houseNumber')->getData()) {
         return array('Default', 'propertyIdentifier', 'postcode');
     }
     return array('Default', 'postcode');
 }
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * Process form
  *
  * @param  Task $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Task $entity)
 {
     $action = $this->entityRoutingHelper->getAction($this->request);
     $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
     $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
     if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) {
         $entity->setOwner($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId));
         FormUtils::replaceField($this->form, 'owner', ['read_only' => true]);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // TODO: should be refactored after finishing BAP-8722
             // Contexts handling should be moved to common for activities form handler
             if ($this->form->has('contexts')) {
                 $contexts = $this->form->get('contexts')->getData();
                 $this->activityManager->setActivityTargets($entity, $contexts);
             } elseif ($targetEntityClass && $action === 'activity') {
                 // if we don't have "contexts" form field
                 // we should save association between activity and target manually
                 $this->activityManager->addActivityTarget($entity, $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId));
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
 /**
  * Process form
  *
  * @param AccountUser $accountUser
  * @return bool True on successful processing, false otherwise
  */
 public function process(AccountUser $accountUser)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if (!$accountUser->getId()) {
                 if ($this->form->get('passwordGenerate')->getData()) {
                     $generatedPassword = $this->userManager->generatePassword(10);
                     $accountUser->setPlainPassword($generatedPassword);
                 }
                 if ($this->form->get('sendEmail')->getData()) {
                     $this->userManager->sendWelcomeEmail($accountUser);
                 }
             }
             $token = $this->securityFacade->getToken();
             if ($token instanceof OrganizationContextTokenInterface) {
                 $organization = $token->getOrganizationContext();
                 $accountUser->setOrganization($organization)->addOrganization($organization);
             }
             $this->userManager->updateUser($accountUser);
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function chooseGroups(FormInterface $form)
 {
     $dayPhoneData = $form->get('dayPhone')->getData();
     $eveningPhoneData = $form->get('eveningPhone')->getData();
     $emailData = $form->get('email')->getData();
     // All other fields are validated through the Default validation group
     $validation_groups = array('Default');
     // todo: is there an apprpoach that does not require the sdk models?
     /** @var ReferencingApplication $application */
     $application = $form->getParent()->getData();
     if ($application instanceof ReferencingApplication) {
         // If Optimum product, require at least one contact detail must be given
         if (19 == $application->getProductId()) {
             if (empty($dayPhoneData) && empty($eveningPhoneData) && empty($emailData)) {
                 $validation_groups[] = 'dayphone';
                 $validation_groups[] = 'eveningphone';
                 $validation_groups[] = 'email';
             }
         }
         // If no day phone, enforce evening
         if (empty($dayPhoneData)) {
             $validation_groups[] = 'eveningphone';
         }
         // If no evening phone, enforce day
         if (empty($eveningPhoneData)) {
             if ($k = array_search('eveningphone', $validation_groups)) {
                 unset($validation_groups[$k]);
             }
             $validation_groups[] = 'dayphone';
         }
         return $validation_groups;
     }
     return array('Default');
 }
 /**
  * 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;
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['entityId'] = $form->get('entityId')->getData();
     $view->vars['entityClass'] = $form->get('entityClass')->getData();
     $routeParameters = isset($view->children['entities']->vars['configs']['route_parameters']) ? $view->children['entities']->vars['configs']['route_parameters'] : [];
     $routeParameters['entityClass'] = $form->get('entityClass')->getData();
     $view->children['entities']->vars['configs']['route_parameters'] = $routeParameters;
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 protected function createEmptyData(FormInterface $form)
 {
     $user = $form->get('user')->getData();
     if (!$user instanceof UserInterface) {
         $user = $this->user;
     }
     return $this->factory->create($this->options['project'], $user, $form->get('role')->getData());
 }
Esempio n. 11
0
 /**
  * @param Account $entity
  */
 protected function handleContacts($entity)
 {
     if ($this->form->has('contacts')) {
         $contacts = $this->form->get('contacts');
         $this->appendContacts($entity, $contacts->get('added')->getData());
         $this->removeContacts($entity, $contacts->get('removed')->getData());
     }
 }
Esempio n. 12
0
 /**
  * Passe la config du champ à la vue
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if ($form->get('content')->isDisabled()) {
         $form->get('content')->addError(new FormError('calendar.error.all_calendars_selected'));
     } elseif (count($this->choices) == 0) {
         $form->get('content')->addError(new FormError('calendar.error.no_calendars_found'));
     }
 }
Esempio n. 13
0
 /**
  * @dataProvider getInvalidInputs
  */
 public function testErrorSubmit($submitted, $expected, array $invalidFields = [])
 {
     $this->sut->submit($submitted);
     $this->assertFalse($this->sut->isValid());
     foreach ($invalidFields as $child) {
         $this->assertFalse($this->sut->get($child)->isValid(), "{$child} isValid");
     }
     $this->assertEquals($expected, $this->sut->getData());
 }
Esempio n. 14
0
 /**
  * @param GridView $entity
  */
 protected function onSuccess(GridView $entity)
 {
     $default = $this->form->get('is_default')->getData();
     $this->setDefaultGridView($entity, $default);
     $this->fixFilters($entity);
     $om = $this->registry->getManagerForClass('OroDataGridBundle:GridView');
     $om->persist($entity);
     $om->flush();
 }
 public function onRegistrationCompleted(FilterUserResponseEvent $event)
 {
     $user = $event->getUser();
     $tenantName = $this->_form->get('tenantName')->getData();
     $tenantSubdomain = $this->_form->get('tenantSubdomain')->getData();
     $tenant = $this->registrationManager->createTenant($user, $tenantName, $tenantSubdomain);
     // this referenced redirect response will be used
     $this->redirectResponse->setTargetUrl($this->tenantAwareRouter->generateUrl($tenant));
     unset($this->_form);
 }
 /**
  * Call when form is valid
  *
  * @param GroupInterface $group
  */
 protected function onSuccess(GroupInterface $group)
 {
     $appendProducts = $this->form->get('appendProducts')->getData();
     $removeProducts = $this->form->get('removeProducts')->getData();
     $options = ['add_products' => $appendProducts, 'remove_products' => $removeProducts];
     if ($group->getType()->isVariant()) {
         $options['copy_values_to_products'] = true;
     }
     $this->groupSaver->save($group, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function chooseGroups(FormInterface $form)
 {
     $accountNoData = $form->get('accountNumber')->getData();
     $accountSortCodeData = $form->get('accountSortcode')->getData();
     // Note: Only validate when either field is supplied.
     // If neither field is supplied, no validation should occur.
     if (!empty($accountNoData) || !empty($accountSortCodeData)) {
         return array('bankaccount');
     }
     return array();
 }
 /**
  * @param PaymentTerm $paymentTerm
  * @return boolean
  */
 public function process(PaymentTerm $paymentTerm)
 {
     $this->form->setData($paymentTerm);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($paymentTerm, $this->form->get('appendAccounts')->getData(), $this->form->get('removeAccounts')->getData(), $this->form->get('appendAccountGroups')->getData(), $this->form->get('removeAccountGroups')->getData());
             return true;
         }
     }
     return false;
 }
Esempio n. 19
0
 /**
  * @return Response|null
  */
 private function handleGameDetailForm(Request $request, FormInterface $form, GameDetailForm $formObject)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid() && !$form->get('dealGame')->isClicked()) {
         throw new BadRequestHttpException('invalid or missing submit action');
     }
     if ($form->isSubmitted() && $form->isValid() && $form->get('dealGame')->isClicked()) {
         $this->gameService->deal($formObject->getGameId());
         return $this->redirectToRoute(self::ROUTE_GAME_DETAIL, ['gameId' => $formObject->getGameId()]);
     }
     return;
 }
 /**
  * "Success" form handler
  *
  * @param RFPRequest $rfpRequest
  */
 protected function onSuccess(RFPRequest $rfpRequest)
 {
     $status = $this->form->get('status')->getData();
     $noteMessage = trim($this->form->get('note')->getData());
     $rfpRequest->setStatus($status);
     if (!empty($noteMessage)) {
         $note = new Note();
         $note->setTarget($rfpRequest)->setMessage(htmlspecialchars_decode($this->templating->render('OroB2BRFPBundle:Request:note.html.twig', ['status' => $status->getLabel(), 'note' => $noteMessage])));
         $this->manager->persist($note);
     }
     $this->manager->flush();
 }
    public function validate(Form\FormInterface $form)
    {
        $discount = $form->getData();
        if (self::APPLIES_TO_ORDER === $form->get('appliesTo')->getData() && 0 !== count($discount->products)) {
            $form->get('products')->addError(new Form\FormError('No products can be chosen if the
				discount applies to a whole order. Please either deselect the products or change
				`Applies to` to `Specific Products Only`.'));
        } elseif (self::APPLIES_TO_PRODUCTS === $form->get('appliesTo')->getData() && 0 === count($discount->products)) {
            $form->get('products')->addError(new Form\FormError('Please choose at least one product the discount
				can be applied to or change `Applies to` to `Whole Order`.'));
        }
    }
Esempio n. 22
0
 /**
  * {@inheritdoc}
  */
 public function handle(GridInterface $grid, FormInterface $form = null, FormInterface $batchForm = null)
 {
     $valid = $form !== null && $form->isValid();
     $view = $this->handler->handle($grid, $valid ? $form->get('filters')->getData() : [], $valid ? $form->get('sorting')->getData() : [], $valid ? ['page' => $form->get('page')->getData(), 'limit' => $form->get('limit')->getData()] : []);
     if ($form !== null) {
         $view->setForm($form->createView());
     }
     if ($batchForm !== null) {
         $view->setBatchForm($batchForm->createView());
     }
     return $view;
 }
 /**
  * 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;
 }
 /**
  * @param  Request      $request
  * @return JsonResponse
  */
 public function uploadComposerAction(Request $request)
 {
     $this->composerForm->handleRequest($request);
     if ($this->composerForm->isValid()) {
         $data = $this->composerForm->getData();
         $this->sonataNotificationsBackend->createAndPublish('upload.composer', array('body' => $data['body'], 'channelName' => $request->getSession()->get('channelName'), 'hasDevDependencies' => $data['hasDevDependencies']));
         return new JsonResponse(array('status' => 'ok'));
     }
     $errors = array_map(function (FormError $error) {
         return $error->getMessage();
     }, $this->composerForm->get('body')->getErrors());
     return new JsonResponse(array('status' => 'ko', 'message' => $errors));
 }
 /**
  * Call when form is valid
  * @param Group $group
  */
 protected function onSuccess(Group $group)
 {
     $groupManager = $this->registry->getManagerForClass(get_class($group));
     $groupManager->persist($group);
     $productManager = $this->registry->getManagerForClass($this->productClass);
     $appendProducts = $this->form->get('appendProducts')->getData();
     $removeProducts = $this->form->get('removeProducts')->getData();
     $products = $appendProducts + $removeProducts;
     foreach ($products as $product) {
         $productManager->persist($product);
     }
     $productManager->flush();
     $groupManager->flush();
 }
Esempio n. 26
0
 /**
  * Process form
  *
  * @param  BusinessUnit $entity
  * @return bool  True on successfull processing, false otherwise
  */
 public function process(BusinessUnit $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $appendUsers = $this->form->get('appendUsers')->getData();
             $removeUsers = $this->form->get('removeUsers')->getData();
             $this->onSuccess($entity, $appendUsers, $removeUsers);
             return true;
         }
     }
     return false;
 }
Esempio n. 27
0
 /**
  * @param Category $category
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(Category $category)
 {
     $this->form->setData($category);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $appendProducts = $this->form->get('appendProducts')->getData();
             $removeProducts = $this->form->get('removeProducts')->getData();
             $this->onSuccess($category, $appendProducts, $removeProducts);
             return true;
         }
     }
     return false;
 }
 protected function validateFields(FormInterface $form, $data)
 {
     if (!in_array($data->getType(), OneTimeContribution::getTypeChoices())) {
         $form->get('type')->addError(new FormError('Choose an option.'));
     } else {
         if ($data->getType() == OneTimeContribution::TYPE_FUNDING_BANK) {
             $bankInformationValidator = new BankInformationFormValidator($form->get('bankInformation'), $data->getBankInformation());
             $bankInformationValidator->validate();
             if (!$data->getStartTransferDate() instanceof \DateTime) {
                 $form->get('start_transfer_date_month')->addError(new FormError('Enter correct date.'));
             } else {
                 $minDate = new \DateTime('+5 days');
                 if ($data->getStartTransferDate() < $minDate) {
                     $form->get('start_transfer_date_month')->addError(new FormError("The start of your transfer should be at least 5 days after today’s date."));
                 }
             }
             if (!$data->getAmount()) {
                 $form->get('amount')->addError(new FormError('Required.'));
             }
             if ($form->has('transaction_frequency')) {
                 $frequency = $form->get('transaction_frequency')->getData();
                 if (null === $frequency || !is_numeric($frequency)) {
                     $form->get('transaction_frequency')->addError(new FormError('Choose an option.'));
                 }
             }
             if ($form->has('contribution_year')) {
                 $contributionYear = $data->getContributionYear();
                 if (null === $contributionYear || !is_numeric($contributionYear)) {
                     $form->get('contribution_year')->addError(new FormError('Enter valid year.'));
                 } else {
                     $currDate = new \DateTime();
                     $currYear = $currDate->format('Y');
                     $minDate = new \DateTime($currYear . '-01-01');
                     $maxDate = new \DateTime($currYear . '-04-15');
                     $startTransferDate = $data->getStartTransferDate();
                     if ($startTransferDate < $minDate || $startTransferDate > $maxDate) {
                         if ($contributionYear !== $currYear) {
                             $form->get('contribution_year')->addError(new FormError(sprintf('Value should be equal %s', $currYear)));
                         }
                     } else {
                         $prevYear = $currDate->add(\DateInterval::createFromDateString('-1 year'))->format('Y');
                         if ($contributionYear !== $currYear && $contributionYear !== $prevYear) {
                             $form->get('contribution_year')->addError(new FormError(sprintf('Value should be equal %s or %s', $prevYear, $currYear)));
                         }
                     }
                 }
             }
         }
     }
 }
 public function validate(Form\FormInterface $form)
 {
     $discountAmounts = false;
     foreach ($form->get('discountAmounts')->getData() as $currency => $amount) {
         if ($amount) {
             $discountAmounts = true;
             break;
         }
     }
     if ($form->get('percentage')->getData() && $discountAmounts) {
         $form->addError(new Form\FormError('Please only fill in either a percentage OR a fixed discount.'));
     } elseif (!$form->get('percentage')->getData() && !$discountAmounts && false === $form->get('freeShipping')->getData()) {
         $form->addError(new Form\FormError('Neither a percentage discount, nor a fixed discount amount, nor free shipping have been added to this discount.'));
     }
 }
Esempio n. 30
0
 /**
  * Process form
  *
  * @param  Role $entity
  * @return bool True on successfull processing, false otherwise
  */
 public function process(Role $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $appendUsers = $this->form->get('appendUsers')->getData();
             $removeUsers = $this->form->get('removeUsers')->getData();
             $entity->setRole(strtoupper(trim(preg_replace('/[^\\w\\-]/i', '_', $entity->getLabel()))));
             $this->onSuccess($entity, $appendUsers, $removeUsers);
             return true;
         }
     }
     return false;
 }