Esempio n. 1
0
 /**
  * Process form
  *
  * @param  EmailTemplate $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(EmailTemplate $entity)
 {
     // always use default locale during template edit in order to allow update of default locale
     $entity->setLocale($this->defaultLocale);
     if ($entity->getId()) {
         // refresh translations
         $this->manager->refresh($entity);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         // deny to modify system templates
         if ($entity->getIsSystem() && !$entity->getIsEditable()) {
             $this->form->addError(new FormError($this->translator->trans('oro.email.handler.attempt_save_system_template')));
             return false;
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // mark an email template creating by an user as editable
             if (!$entity->getId()) {
                 $entity->setIsEditable(true);
             }
             $this->manager->persist($entity);
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * @param LineItem $lineItem
  *
  * @return bool
  */
 public function process(LineItem $lineItem)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             /** @var LineItemRepository $lineItemRepository */
             $lineItemRepository = $this->manager->getRepository('OroB2BShoppingListBundle:LineItem');
             $existingLineItem = $lineItemRepository->findDuplicate($lineItem);
             if ($existingLineItem) {
                 $existingLineItem->setQuantity($lineItem->getQuantity() + $existingLineItem->getQuantity());
                 $existingLineItemNote = $existingLineItem->getNotes();
                 $newNotes = $lineItem->getNotes();
                 $notes = trim(implode(' ', [$existingLineItemNote, $newNotes]));
                 if ($notes) {
                     $existingLineItem->setNotes($notes);
                 }
                 $this->savedId = $existingLineItem->getId();
             } else {
                 $this->manager->persist($lineItem);
             }
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
 /**
  * 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. 4
0
 /**
  * @dataProvider getNicknameExample
  */
 public function testNickBadChar($nick)
 {
     $submitted = ['nickname' => $nick, 'gender' => 'xy'];
     $this->sut->submit($submitted);
     $this->assertFalse($this->sut->isValid());
     $this->assertRegexp('#not valid#', $this->sut->get('nickname')->getErrors()[0]->getMessage());
 }
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;
 }
 /**
  * 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;
 }
 /**
  * Process form
  *
  * @param  Issue $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Issue $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->setAssignee($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId));
         FormUtils::replaceField($this->form, 'assignee', ['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()) {
             /* if ($targetEntityClass && $action === 'activity') {
                    $this->activityManager->addActivityTarget(
                        $entity,
                        $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId)
                    );
                }*/
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
Esempio n. 8
0
 public function testInvalidName_MaxLengthValid()
 {
     $name = str_repeat('S', $this->app['config']['stext_len']);
     $this->formData['name'] = $name;
     $this->form->submit($this->formData);
     $this->assertTrue($this->form->isValid());
 }
Esempio n. 9
0
 /**
  * Process form
  *
  * @param  Call $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Call $entity)
 {
     $targetEntityClass = $this->request->get('entityClass');
     $targetEntityId = $this->request->get('entityId');
     $options = [];
     if ($targetEntityClass && $this->request->getMethod() === 'GET') {
         $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
         if (!$entity->getId()) {
             $entity->setPhoneNumber($this->phoneProvider->getPhoneNumber($targetEntity));
         }
         $options = ['phone_suggestions' => array_unique(array_map(function ($item) {
             return $item[0];
         }, $this->phoneProvider->getPhoneNumbers($targetEntity)))];
     }
     $this->form = $this->formFactory->createNamed($this->formName, $this->formType, $entity, $options);
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if ($targetEntityClass) {
                 $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
                 $this->callActivityManager->addAssociation($entity, $targetEntity);
                 $phones = $this->phoneProvider->getPhoneNumbers($targetEntity);
                 foreach ($phones as $phone) {
                     if ($entity->getPhoneNumber() === $phone[0]) {
                         $this->callActivityManager->addAssociation($entity, $phone[1]);
                     }
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  *
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $originalChildren = new ArrayCollection();
         foreach ($entity->getChildEvents() as $childEvent) {
             $originalChildren->add($childEvent);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->ensureCalendarSet($entity);
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity, $originalChildren, $this->form->get('notifyInvitedUsers')->getData());
             return true;
         }
     }
     return false;
 }
Esempio n. 11
0
 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     if (!$entity->getCalendar()) {
         if ($this->securityFacade->getLoggedUser() && $this->securityFacade->getOrganization()) {
             /** @var Calendar $defaultCalendar */
             $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($this->securityFacade->getLoggedUser()->getId(), $this->securityFacade->getOrganization()->getId());
             $entity->setCalendar($defaultCalendar);
         } else {
             throw new \LogicException('Current user did not define');
         }
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
Esempio n. 12
0
 public function testInvalidEmail_RFC2822()
 {
     $this->formData['email']['first'] = '*****@*****.**';
     $this->formData['email']['second'] = '*****@*****.**';
     $this->form->submit($this->formData);
     $this->assertFalse($this->form->isValid());
 }
 /**
  * @param LineItem $lineItem
  *
  * @return bool
  */
 public function process(LineItem $lineItem)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         /** @var EntityManagerInterface $manager */
         $manager = $this->registry->getManagerForClass('OroB2BShoppingListBundle:LineItem');
         $manager->beginTransaction();
         // handle case for new shopping list creation
         $formName = $this->form->getName();
         $formData = $this->request->request->get($formName, []);
         if (empty($formData['shoppingList']) && !empty($formData['shoppingListLabel'])) {
             $shoppingList = $this->shoppingListManager->createCurrent($formData['shoppingListLabel']);
             $formData['shoppingList'] = $shoppingList->getId();
             $this->request->request->set($formName, $formData);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             /** @var LineItemRepository $lineItemRepository */
             $lineItemRepository = $manager->getRepository('OroB2BShoppingListBundle:LineItem');
             $existingLineItem = $lineItemRepository->findDuplicate($lineItem);
             if ($existingLineItem) {
                 $this->updateExistingLineItem($lineItem, $existingLineItem);
             } else {
                 $manager->persist($lineItem);
             }
             $manager->flush();
             $manager->commit();
             return true;
         } else {
             $manager->rollBack();
         }
     }
     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;
 }
 public function testInvalidTel_Blank()
 {
     $this->formData['law_tel']['law_tel01'] = '';
     $this->formData['law_tel']['law_tel02'] = '';
     $this->formData['law_tel']['law_tel03'] = '';
     $this->form->submit($this->formData);
     $this->assertFalse($this->form->isValid());
 }
 public function testValidTel_Blank()
 {
     $this->formData['tel']['tel01'] = '';
     $this->formData['tel']['tel02'] = '';
     $this->formData['tel']['tel03'] = '';
     $this->form->submit($this->formData);
     $this->assertTrue($this->form->isValid());
 }
Esempio n. 17
0
 public function testRequiredAddNotBlank_Zip02()
 {
     $app = $this->createApplication();
     $this->form = $app['form.factory']->createBuilder('form', null, array('csrf_protection' => false))->add('zip', 'zip', array('required' => true))->getForm();
     $this->formData['zip']['zip02'] = '';
     $this->form->submit($this->formData);
     $this->assertFalse($this->form->isValid());
 }
Esempio n. 18
0
 public function testInvalidData()
 {
     // Request に依存しているため WebTest で代替する
     $this->markTestSkipped('Can not support of FormInterface::submit()');
     $this->form->submit($this->formData);
     $this->assertFalse($this->form->isValid());
     //var_dump($this->form->getErrorsAsString());die();
 }
Esempio n. 19
0
 public function testInvalidTel_Blank()
 {
     $this->app['request'] = new Request();
     $this->formData['tel']['tel01'] = '';
     $this->formData['tel']['tel02'] = '';
     $this->formData['tel']['tel03'] = '';
     $this->form->submit($this->formData);
     $this->assertFalse($this->form->isValid());
 }
Esempio n. 20
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());
 }
 /**
  * Process and validate form
  *
  * @return true if form is valid
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException on invalid form
  */
 public function process()
 {
     $this->form->submit($this->getPostJsonData());
     // form validation
     if (!$this->form->isValid()) {
         $this->throwFirstError($this->form);
     }
     $this->success = true;
     return true;
 }
 public function testInvalidTel_Blank()
 {
     $this->formData['tel']['tel01'] = '';
     $this->formData['tel']['tel02'] = '';
     $this->formData['tel']['tel03'] = '';
     $this->form->submit($this->formData);
     $this->assertFalse($this->form->isValid());
     // エラーメッセージデバッグ用
     //var_dump($this->form->getErrorsAsString());die;
 }
 /**
  * Process job configuration form.
  *
  * @param JobConfigurationInterface $configuration
  * @param Request $request
  *
  * @return bool
  */
 public function process(JobConfigurationInterface $configuration, Request $request)
 {
     $this->form->setData($configuration);
     $this->form->handleRequest($request);
     if ($this->form->isValid()) {
         $this->manager->add($configuration);
         return true;
     }
     return false;
 }
 /**
  * @param ShoppingList $shoppingList
  * @return boolean
  */
 public function process(ShoppingList $shoppingList)
 {
     $this->form->setData($shoppingList);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             return $this->onSuccess($shoppingList);
         }
     }
     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;
 }
Esempio n. 26
0
 /**
  * Process form
  *
  * @param mixed $entity
  *
  * @return mixed|null The instance of saved entity on successful processing; otherwise, null
  */
 public function process($entity)
 {
     $entity = $this->prepareFormData($entity);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             return $this->onSuccess($entity) ?: $entity;
         }
     }
     return null;
 }
 /**
  * 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 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. 29
0
 /**
  * Process form
  *
  * @param  Order $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(Order $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
 /**
  * Process form
  *
  * @param  UserInterface $user
  * @return bool True on successfull processing, false otherwise
  */
 public function process(UserInterface $user)
 {
     $this->form->setData($user);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($user);
             return true;
         }
     }
     return false;
 }