Ejemplo n.º 1
0
 public function testRemoveContact()
 {
     $account = new Account();
     $account->setId(1);
     $contact = new Contact();
     $contact->setId(2);
     $account->addContact($contact);
     $this->assertCount(1, $account->getContacts()->toArray());
     $account->removeContact($contact);
     $this->assertEmpty($account->getContacts()->toArray());
 }
Ejemplo n.º 2
0
 /**
  * Gets a list of all phone numbers available for the given Account object
  *
  * @param Account $object
  *
  * @return array of [phone number, phone owner]
  */
 public function getPhoneNumbers($object)
 {
     $defaultContact = $object->getDefaultContact();
     $result = $defaultContact ? $this->rootProvider->getPhoneNumbers($defaultContact) : [];
     foreach ($object->getContacts() as $contact) {
         if ($contact !== $defaultContact) {
             $result = array_merge($result, $this->rootProvider->getPhoneNumbers($contact));
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 public function testProcessWithoutContactViewPermission()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->form->expects($this->once())->method('has')->with('contacts')->will($this->returnValue(false));
     $this->form->expects($this->never())->method('get');
     $this->assertTrue($this->handler->process($this->entity));
     $actualContacts = $this->entity->getContacts()->toArray();
     $this->assertCount(0, $actualContacts);
     $this->assertEquals(array(), $actualContacts);
 }
Ejemplo n.º 4
0
 /**
  * @Route("/widget/account-contacts/{id}", name="orocrm_account_widget_contacts", requirements={"id"="\d+"})
  * @AclAncestor("orocrm_contact_view")
  * @Template()
  */
 public function accountContactsAction(Account $account)
 {
     $defaultContact = $account->getDefaultContact();
     $contacts = $account->getContacts();
     $contactsWithoutDefault = array();
     if (empty($defaultContact)) {
         $contactsWithoutDefault = $contacts->toArray();
     } else {
         /** @var Contact $contact */
         foreach ($contacts as $contact) {
             if ($contact->getId() == $defaultContact->getId()) {
                 continue;
             }
             $contactsWithoutDefault[] = $contact;
         }
     }
     /**
      * Compare contacts to sort them alphabetically
      *
      * @param Contact $firstContact
      * @param Contact $secondContact
      * @return int
      */
     $compareFunction = function ($firstContact, $secondContact) {
         $first = $firstContact->getLastName() . $firstContact->getFirstName() . $firstContact->getMiddleName();
         $second = $secondContact->getLastName() . $secondContact->getFirstName() . $secondContact->getMiddleName();
         return strnatcasecmp($first, $second);
     };
     usort($contactsWithoutDefault, $compareFunction);
     return array('entity' => $account, 'defaultContact' => $defaultContact, 'contactsWithoutDefault' => $contactsWithoutDefault);
 }