예제 #1
0
 /**
  * 
  * Add webpage to the contact
  * @param string $url
  * @param int $web_type
  * @author Seba
  */
 function addWebpage($url, $web_type)
 {
     $web = new ContactWebpage();
     $web->setUrl($url);
     $web->setWebTypeId(WebpageTypes::getWebpageTypeId($web_type));
     $web->setContactId($this->getId());
     $web->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;
 }