Programming Language PHP

Namespace Oro\Bundle\SalesBundle\Entity

Class Lead

Method/Function setUpdatedAt

Total Examples 1

1 code examples of PHP Oro\Bundle\SalesBundle\Entity\Lead::setUpdatedAt extracted from open source projects

Was this example useful?
0
                                                    /**
     * @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;
    }