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
 public function testPreUpdate()
 {
     $obj = new Call();
     $this->assertNull($obj->getUpdatedAt());
     $obj->preUpdate();
     $this->assertInstanceOf('\\DateTime', $obj->getUpdatedAt());
 }
 public function testGetDirection()
 {
     $directionName = 'incoming';
     $direction = new CallDirection($directionName);
     $call = new Call();
     $call->setDirection($direction);
     $this->assertEquals($directionName, $this->provider->getDirection($call, new \stdClass()));
 }
Exemplo n.º 4
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.º 5
0
 public function testRemoveContactFromContextShouldDecreaseActivityCounter()
 {
     $firstContact = $this->findContact(LoadContactEntitiesData::FIRST_ENTITY_NAME);
     $secondContact = $this->findContact(LoadContactEntitiesData::SECOND_ENTITY_NAME);
     $firstContacted = $firstContact->getAcContactCount();
     $secondContacted = $firstContact->getAcContactCount();
     $call = new Call();
     $call->setPhoneNumber('3058304958')->setSubject('subj')->setDirection($this->findCallDirection(DirectionProviderInterface::DIRECTION_OUTGOING));
     $this->getActivityManager()->addActivityTargets($call, [$firstContact, $secondContact]);
     $this->getEntityManager()->persist($call);
     $this->getEntityManager()->flush();
     $this->assertEquals($firstContacted + 1, $firstContact->getAcContactCount());
     $this->assertEquals($secondContacted + 1, $secondContact->getAcContactCount());
     $this->getActivityManager()->removeActivityTarget($call, $secondContact);
     $this->getEntityManager()->flush();
     $this->assertEquals($firstContacted + 1, $firstContact->getAcContactCount());
     $this->assertEquals($secondContacted, $secondContact->getAcContactCount());
 }
Exemplo n.º 6
0
 /**
  * @dataProvider supportedMethods
  *
  * @param string $method
  */
 public function testProcessValidDataWithTargetEntity($method)
 {
     $this->entity->setPhoneNumber('phone1');
     $targetEntity = new TestTarget(123);
     $targetEntity1 = new TestTarget(456);
     $this->request->query->set('entityClass', get_class($targetEntity));
     $this->request->query->set('entityId', $targetEntity->getId());
     $this->formFactory->expects($this->once())->method('createNamed')->with('orocrm_call_form', 'orocrm_call_form', $this->entity, [])->will($this->returnValue($this->form));
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->phoneProvider->expects($this->never())->method('getPhoneNumber');
     $this->phoneProvider->expects($this->once())->method('getPhoneNumbers')->with($this->identicalTo($targetEntity))->will($this->returnValue([['phone1', $targetEntity], ['phone2', $targetEntity], ['phone1', $targetEntity1]]));
     $this->entityRoutingHelper->expects($this->once())->method('getEntity')->with(get_class($targetEntity), $targetEntity->getId())->will($this->returnValue($targetEntity));
     // phone1, $targetEntity
     $this->callActivityManager->expects($this->at(0))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
     // phone2, $targetEntity
     $this->callActivityManager->expects($this->at(1))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
     // phone1, $targetEntity1
     $this->callActivityManager->expects($this->at(2))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity1));
     $this->manager->expects($this->once())->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->request->setMethod($method);
     $this->assertTrue($this->handler->process($this->entity));
 }
Exemplo n.º 7
0
 public function testIsNotUpdatedFlags()
 {
     $call = new Call();
     $call->setUpdatedAt(null);
     $this->assertFalse($call->isUpdatedAtSet());
 }
Exemplo n.º 8
0
 /**
  * @param ObjectManager $om
  */
 protected function persistDemoCalls(ObjectManager $om)
 {
     $accounts = $om->getRepository('OroCRMAccountBundle:Account')->findAll();
     $contacts = $om->getRepository('OroCRMContactBundle:Contact')->findAll();
     $callStatus = $om->getRepository('OroCRMCallBundle:CallStatus')->findOneBy(['name' => 'completed']);
     $directions = ['incoming' => $om->getRepository('OroCRMCallBundle:CallDirection')->findOneBy(['name' => 'incoming']), 'outgoing' => $om->getRepository('OroCRMCallBundle:CallDirection')->findOneBy(['name' => 'outgoing'])];
     $contactCount = count($contacts);
     $accountCount = count($accounts);
     for ($i = 0; $i < 100; ++$i) {
         $contactRandom = rand(0, $contactCount - 1);
         $accountRandom = rand(0, $accountCount - 1);
         /** @var Contact $contact */
         $contact = $contacts[$contactRandom];
         /** @var Account $account */
         $account = $accounts[$accountRandom];
         $call = new Call();
         $call->setCallStatus($callStatus);
         $call->setOrganization($this->organization);
         $call->setOwner($contact->getOwner());
         $call->setSubject($this->subjects[array_rand($this->subjects)]);
         $call->setDuration(new \DateTime(rand(0, 1) . ':' . rand(0, 59) . ':' . rand(0, 59), new \DateTimeZone('UTC')));
         if ($call->supportActivityTarget(get_class($contact->getOwner()))) {
             $call->addActivityTarget($contact->getOwner());
         }
         $randomPath = rand(1, 10);
         if ($randomPath > 2) {
             if ($call->supportActivityTarget(get_class($contact))) {
                 $this->setSecurityContext($contact->getOwner());
                 $call->addActivityTarget($contact);
             }
             $contactPrimaryPhone = $contact->getPrimaryPhone();
             if ($contactPrimaryPhone) {
                 $call->setPhoneNumber($contactPrimaryPhone->getPhone());
             }
             $call->setDirection($directions['outgoing']);
         }
         if ($randomPath > 3) {
             /** @var Contact[] $relatedContacts */
             $relatedContacts = $call->getActivityTargets('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact');
             if ($relatedContacts) {
                 if ($call->supportActivityTarget(get_class($relatedContacts[0]->getAccounts()[0]))) {
                     $call->addActivityTarget($relatedContacts[0]->getAccounts()[0]);
                 }
             } else {
                 if ($call->supportActivityTarget(get_class($account))) {
                     $call->addActivityTarget($account);
                 }
             }
         }
         $phone = $call->getPhoneNumber();
         if (empty($phone)) {
             $phone = rand(1000000000, 9999999999);
             $phone = sprintf("%s-%s-%s", substr($phone, 0, 3), substr($phone, 3, 3), substr($phone, 6));
             $call->setPhoneNumber($phone);
             $call->setDirection($directions['incoming']);
         }
         $om->persist($call);
     }
 }
Exemplo n.º 9
0
 /**
  * Check if call log action is applicable to entity as activity
  *
  * @param object|null $entity
  * @return bool
  */
 public function isApplicable($entity = null)
 {
     return is_object($entity) && $this->call->supportActivityTarget(ClassUtils::getClass($entity)) && $this->activityManager->hasActivityAssociation(ClassUtils::getClass($entity), ClassUtils::getClass($this->call));
 }
Exemplo n.º 10
0
 /**
  * @Route("/update/{id}", name="orocrm_call_update", requirements={"id"="\d+"})
  * @Template
  * @Acl(
  *      id="orocrm_call_update",
  *      type="entity",
  *      permission="EDIT",
  *      class="OroCRMCallBundle:Call"
  * )
  */
 public function updateAction(Call $entity)
 {
     $formAction = $this->get('router')->generate('orocrm_call_update', ['id' => $entity->getId()]);
     return $this->update($entity, $formAction);
 }
Exemplo n.º 11
0
 /**
  * @param int|null $contactId
  * @param int|null $accountId
  * @return Call
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 protected function initEntity($contactId = null, $accountId = null)
 {
     $entity = new Call();
     $callStatus = $this->getDoctrine()->getRepository('OroCRMCallBundle:CallStatus')->findOneByName('completed');
     $entity->setCallStatus($callStatus);
     $callDirection = $this->getDoctrine()->getRepository('OroCRMCallBundle:CallDirection')->findOneByName('outgoing');
     $entity->setDirection($callDirection);
     if ($contactId) {
         $repository = $this->getDoctrine()->getRepository('OroCRMContactBundle:Contact');
         $contact = $repository->find($contactId);
         if ($contact) {
             $entity->setRelatedContact($contact);
             $entity->setContactPhoneNumber($contact->getPrimaryPhone());
         } else {
             throw new NotFoundHttpException(sprintf('Contact with ID %s is not found', $contactId));
         }
     }
     if ($accountId) {
         $repository = $this->getDoctrine()->getRepository('OroCRMAccountBundle:Account');
         /** @var Account $account */
         $account = $repository->find($accountId);
         if ($account) {
             $entity->setRelatedAccount($account);
         } else {
             throw new NotFoundHttpException(sprintf('Account with ID %s is not found', $accountId));
         }
     }
     return $entity;
 }
Exemplo n.º 12
0
 /**
  * Check if call log action is applicable to entity as activity
  *
  * @param object|null $entity
  * @return bool
  */
 public function isApplicable($entity = null)
 {
     return is_object($entity) && $this->call->supportActivityTarget(ClassUtils::getClass($entity));
 }
Exemplo n.º 13
0
 /**
  * @param ObjectManager                                     $om
  */
 protected function persistDemoCalls(ObjectManager $om)
 {
     $accounts = $om->getRepository('OroCRMAccountBundle:Account')->findAll();
     $contacts = $om->getRepository('OroCRMContactBundle:Contact')->findAll();
     $directions = array('incoming' => $om->getRepository('OroCRMCallBundle:CallDirection')->findOneBy(array('name' => 'incoming')), 'outgoing' => $om->getRepository('OroCRMCallBundle:CallDirection')->findOneBy(array('name' => 'outgoing')));
     $contactCount = count($contacts);
     $accountCount = count($accounts);
     for ($i = 0; $i < 100; ++$i) {
         $contactRandom = rand(0, $contactCount - 1);
         $accountRandom = rand(0, $accountCount - 1);
         /** @var Contact $contact */
         $contact = $contacts[$contactRandom];
         /** @var Account $account */
         $account = $accounts[$accountRandom];
         $call = new Call();
         $call->setOrganization($this->organization);
         $call->setOwner($contact->getOwner());
         $call->setSubject($this->subjects[array_rand($this->subjects)]);
         $call->setDuration(new \DateTime(rand(0, 1) . ':' . rand(0, 59) . ':' . rand(0, 59), new \DateTimeZone('UTC')));
         $randomPath = rand(1, 10);
         if ($randomPath > 2) {
             $call->setRelatedContact($contact);
             $call->setContactPhoneNumber($contact->getPrimaryPhone());
             $call->setDirection($directions['outgoing']);
         }
         if ($randomPath > 3) {
             if ($call->getRelatedContact()) {
                 $call->setRelatedAccount($call->getRelatedContact()->getAccounts()[0]);
             } else {
                 $call->setRelatedAccount($account);
             }
         }
         if (is_null($call->getContactPhoneNumber())) {
             $phone = rand(1000000000, 9999999999);
             $phone = sprintf("%s-%s-%s", substr($phone, 0, 3), substr($phone, 3, 3), substr($phone, 6));
             $call->setPhoneNumber($phone);
             $call->setDirection($directions['incoming']);
         }
         $om->persist($call);
     }
 }