Exemplo n.º 1
0
 /**
  * @param Contact $contact
  * @param ContactAddress $address
  * @return array
  * @throws BadRequestHttpException
  */
 protected function update(Contact $contact, ContactAddress $address)
 {
     $responseData = array('saved' => false, 'contact' => $contact);
     if ($this->getRequest()->getMethod() == 'GET' && !$address->getId()) {
         $address->setFirstName($contact->getFirstName());
         $address->setLastName($contact->getLastName());
         if (!$contact->getAddresses()->count()) {
             $address->setPrimary(true);
         }
     }
     if ($address->getOwner() && $address->getOwner()->getId() != $contact->getId()) {
         throw new BadRequestHttpException('Address must belong to contact');
     } elseif (!$address->getOwner()) {
         $contact->addAddress($address);
     }
     // Update contact's modification date when an address is changed
     $contact->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC')));
     if ($this->get('orocrm_contact.form.handler.contact_address')->process($address)) {
         $this->getDoctrine()->getManager()->flush();
         $responseData['entity'] = $address;
         $responseData['saved'] = true;
     }
     $responseData['form'] = $this->get('orocrm_contact.contact_address.form')->createView();
     return $responseData;
 }
Exemplo n.º 2
0
 /**
  * @param Contact     $contact
  * @param B2bCustomer $customer
  * @param User        $user
  *
  * @return Opportunity
  */
 protected function createOpportunity($contact, $customer, $user)
 {
     $opportunity = new Opportunity();
     $dataChannel = $this->getReference('default_channel');
     $opportunity->setName($contact->getFirstName() . ' ' . $contact->getLastName());
     $opportunity->setContact($contact);
     $opportunity->setOwner($user);
     $opportunity->setOrganization($this->organization);
     $opportunity->setCustomer($customer);
     $opportunity->setDataChannel($dataChannel);
     return $opportunity;
 }
Exemplo n.º 3
0
 /**
  * @param \OroCRM\Bundle\ContactBundle\Entity\Contact $contact
  */
 protected function getFirstNameTest($contact)
 {
     $this->assertEquals('First', $contact->getFirstName());
 }
Exemplo n.º 4
0
 /**
  * @param $randomTemplate
  * @param User $owner
  * @param Contact $contact
  * @param EmailOrigin $origin
  *
  * @return EmailUser
  */
 protected function addEmailUser($randomTemplate, $owner, $contact, $origin)
 {
     $ownerEmail = $owner->getFullName() . ' <' . $owner->getEmail() . '>';
     $contactEmail = $contact->getFirstName() . ' ' . $contact->getLastName() . ' <' . $contact->getPrimaryEmail()->getEmail() . '>';
     $emailUser = $this->emailEntityBuilder->emailUser($this->templates[$randomTemplate]['Subject'], $ownerEmail, $contactEmail, new \DateTime('now'), new \DateTime('now'), new \DateTime('now'));
     $this->setSecurityContext($owner);
     $emailUser->addFolder($origin->getFolder(FolderType::SENT));
     $emailUser->setOrigin($origin);
     $emailUser->setOwner($owner);
     $emailUser->setOrganization($owner->getOrganization());
     $emailBody = $this->emailEntityBuilder->body("Hi,\n" . $this->templates[$randomTemplate]['Text'], false, true);
     $emailUser->getEmail()->setEmailBody($emailBody);
     $emailUser->getEmail()->setMessageId(sprintf('<id.%s@%s', uniqid(), '@bap.migration.generated>'));
     return $emailUser;
 }