/** * @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); } }