예제 #1
0
 /**
  * 
  * Add phone to the contact
  * @param string $number
  * @param int $phone_type
  * @param boolean $isMain
  * @author Seba
  */
 function addPhone($number, $phone_type, $isMain = false, $name = "")
 {
     $phone = new ContactTelephone();
     $phone->setNumber($number);
     $phone->setTelephoneTypeId(TelephoneTypes::getTelephoneTypeId($phone_type));
     $phone->setContactId($this->getId());
     $phone->setIsMain($isMain);
     $phone->setName($name);
     $phone->save();
 }
 function save_phones_addresses_webpages($contact_data, $contact)
 {
     //telephones
     $phones_data = array_var($contact_data, 'phone');
     if (is_array($phones_data)) {
         foreach ($phones_data as $data) {
             $obj = null;
             if ($data['id'] > 0) {
                 $obj = ContactTelephones::findById($data['id']);
             } else {
                 if (trim($data['number']) == '' && trim($data['name']) == '') {
                     continue;
                 }
             }
             if ($data['deleted'] && $obj instanceof ContactTelephone) {
                 $obj->delete();
                 continue;
             }
             if (!$obj instanceof ContactTelephone) {
                 $obj = new ContactTelephone();
                 $obj->setContactId($contact->getId());
             }
             $obj->setTelephoneTypeId($data['type']);
             $obj->setNumber($data['number']);
             $obj->setName($data['name']);
             $obj->save();
         }
     }
     //addresses
     $addresses_data = array_var($contact_data, 'address');
     if (is_array($addresses_data)) {
         foreach ($addresses_data as $data) {
             $obj = null;
             if ($data['id'] > 0) {
                 $obj = ContactAddresses::findById($data['id']);
             } else {
                 if (trim($data['street']) == '' && trim($data['city']) == '' && trim($data['state']) == '' && trim($data['zip_code']) == '' && trim($data['country']) == '') {
                     continue;
                 }
             }
             if ($data['deleted'] && $obj instanceof ContactAddress) {
                 $obj->delete();
                 continue;
             }
             if (!$obj instanceof ContactAddress) {
                 $obj = new ContactAddress();
                 $obj->setContactId($contact->getId());
             }
             $obj->setAddressTypeId($data['type']);
             $obj->setStreet($data['street']);
             $obj->setCity($data['city']);
             $obj->setState($data['state']);
             $obj->setZipCode($data['zip_code']);
             $obj->setCountry($data['country']);
             $obj->save();
         }
     }
     //webpages
     $webpages_data = array_var($contact_data, 'webpage');
     if (is_array($webpages_data)) {
         foreach ($webpages_data as $data) {
             $obj = null;
             if ($data['id'] > 0) {
                 $obj = ContactWebpages::findById($data['id']);
             } else {
                 if (trim($data['url']) == '') {
                     continue;
                 }
             }
             if ($data['deleted'] && $obj instanceof ContactWebpage) {
                 $obj->delete();
                 continue;
             }
             if (!$obj instanceof ContactWebpage) {
                 $obj = new ContactWebpage();
                 $obj->setContactId($contact->getId());
             }
             $obj->setWebTypeId($data['type']);
             $obj->setUrl($data['url']);
             $obj->save();
         }
     }
     return true;
 }