3 code examples of PHP Oro\Bundle\SalesBundle\Entity\Lead extracted from open source projects
protected function setContactAndAccountToLeadFromOpportunity(Lead $lead, Opportunity $opportunity)
{
$lead->setContact($opportunity->getContact());
}
/**
* Gets a list of all phone numbers available for the given Lead object
*
*
* @return array of [phone number, phone owner]
*/
public function getPhoneNumbers(Lead $object): array
{
$result = [];
foreach ($object->getPhones() as $phone) {
$result[] = [$phone->getPhone(), $object];
}
return $result;
}
/**
* @throws BadRequestHttpException
*/
protected function update(Request $request, Lead $lead, LeadAddress $address): array
{
$responseData = [
'saved' => false,
'lead' => $lead,
];
if ($request->isMethod('GET') && !$address->getId()) {
$address->setFirstName($lead->getFirstName());
$address->setLastName($lead->getLastName());
if (!$lead->getAddresses()->count()) {
$address->setPrimary(true);
}
}
if ($address->getOwner() && $address->getOwner()->getId() != $lead->getId()) {
throw new BadRequestHttpException('Address must belong to lead');
} elseif (!$address->getOwner()) {
$lead->addAddress($address);
}
// Update lead's modification date when an address is changed
$lead->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC')));
if ($this->get(AddressHandler::class)->process($address)) {
$this->getDoctrine()->getManager()->flush();
$responseData['entity'] = $address;
$responseData['saved'] = true;
}
$responseData['form'] = $this->get('oro_sales.lead_address.form')->createView();
return $responseData;
}