/** * @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); } }
public function testGetDirection() { $directionName = 'incoming'; $direction = new CallDirection($directionName); $call = new Call(); $call->setDirection($direction); $this->assertEquals($directionName, $this->provider->getDirection($call, new \stdClass())); }
/** * @Route("/create", name="orocrm_call_create") * @Template("OroCRMCallBundle:Call:update.html.twig") * @Acl( * id="orocrm_call_create", * type="entity", * permission="CREATE", * class="OroCRMCallBundle:Call" * ) */ public function createAction() { $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); $formAction = $this->get('oro_entity.routing_helper')->generateUrlByRequest('orocrm_call_create', $this->getRequest()); return $this->update($entity, $formAction); }
/** * @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); } }
/** * @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; }