Exemplo n.º 1
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;
 }
Exemplo n.º 2
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  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;
 }
Exemplo n.º 4
0
 /**
  * @param string $className
  * @param int    $id
  *
  * @return object
  *
  * @throws \Exception
  */
 protected function getEntity($className, $id)
 {
     try {
         $entity = $this->entityRoutingHelper->getEntity($className, $id);
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage(), Codes::HTTP_NOT_FOUND);
     }
     return $entity;
 }
Exemplo n.º 5
0
 /**
  * @param string $className
  * @param int    $id
  * @param array  $data
  *
  * @return array
  *
  * @throws AccessDeniedException
  */
 public function patch($className, $id, $data)
 {
     $entity = $this->entityRoutingHelper->getEntity($className, $id);
     if (!$this->securityService->isGranted('EDIT', $entity)) {
         throw new AccessDeniedException();
     }
     try {
         return $this->entityDataManager->update($entity, $data);
     } catch (FieldUpdateAccessException $e) {
         throw new AccessDeniedException($e->getMessage(), $e);
     }
 }
Exemplo n.º 6
0
 /**
  * @param string      $emailAddress
  * @param string|null $ownerClass
  * @param mixed|null  $ownerId
  */
 protected function preciseFullEmailAddress(&$emailAddress, $ownerClass = null, $ownerId = null)
 {
     if (!$this->emailAddressHelper->isFullEmailAddress($emailAddress)) {
         if (!empty($ownerClass) && !empty($ownerId)) {
             $owner = $this->entityRoutingHelper->getEntity($ownerClass, $ownerId);
             if ($owner) {
                 $ownerName = $this->nameFormatter->format($owner);
                 if (!empty($ownerName)) {
                     $emailAddress = $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $ownerName);
                     return;
                 }
             }
         }
         $repo = $this->emailAddressManager->getEmailAddressRepository($this->em);
         $emailAddressObj = $repo->findOneBy(array('email' => $emailAddress));
         if ($emailAddressObj) {
             $owner = $emailAddressObj->getOwner();
             if ($owner) {
                 $ownerName = $this->nameFormatter->format($owner);
                 if (!empty($ownerName)) {
                     $emailAddress = $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $ownerName);
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Adds default or existent activity contexts data to the form
  *
  * @param FormEvent $event
  */
 public function addDefaultContextListener(FormEvent $event)
 {
     /** @var ActivityInterface $entity */
     $entity = $event->getData();
     $form = $event->getForm();
     if ($entity) {
         $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
         $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
         $contexts = [];
         if ($entity->getId()) {
             $contexts = $entity->getActivityTargetEntities();
         } elseif ($targetEntityClass && $this->request->getMethod() === 'GET') {
             $contexts[] = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
         }
         $form->get('contexts')->setData($contexts);
     }
 }
Exemplo n.º 8
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()) {
             $phone = $this->request->query->get('phone');
             if (!$phone) {
                 $phone = $this->phoneProvider->getPhoneNumber($targetEntity);
             }
             $entity->setPhoneNumber($phone);
         }
         $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()) {
             // 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) {
                 // if we don't have "contexts" form field
                 // we should save association between activity and target manually
                 $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;
 }
Exemplo n.º 9
0
 /**
  * @param string $entityClass
  * @param string $entityId
  * @return object
  */
 public function getTargetEntity($entityClass, $entityId)
 {
     return $this->entityRoutingHelper->getEntity($entityClass, $entityId);
 }
Exemplo n.º 10
0
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  * @expectedExceptionMessage The entity "Acme\Bundle\TestClass" with ID "123" was not found.
  */
 public function testGetEntityForNotExistingEntity()
 {
     $this->doctrineHelper->expects($this->once())->method('getEntity')->with('Acme\\Bundle\\TestClass', 123)->will($this->returnValue(null));
     $this->entityRoutingHelper->getEntity('Acme_Bundle_TestClass', 123);
 }
Exemplo n.º 11
0
 /**
  * {@inheritDoc}
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $parameters = $grid->getParameters();
     $this->object = $this->routingHelper->getEntity($parameters->get('entityClass'), $parameters->get('entityId'));
     $grid->setDatasource(clone $this);
 }