Пример #1
0
 public function emitContactsSyncSettingUI(Vtiger_Request $request)
 {
     $user = Users_Record_Model::getCurrentUserModel();
     $connector = new Google_Contacts_Connector(FALSE);
     $fieldMappping = Google_Utils_Helper::getFieldMappingForUser();
     $oauth2 = new Google_Oauth2_Connector($request->get('sourcemodule'));
     if ($oauth2->hasStoredToken()) {
         $controller = new Google_Contacts_Controller($user);
         $connector = $controller->getTargetConnector();
         $groups = $connector->pullGroups();
     }
     $targetFields = $connector->getFields();
     $selectedGroup = Google_Utils_Helper::getSelectedContactGroupForUser();
     $syncDirection = Google_Utils_Helper::getSyncDirectionForUser($user);
     $contactsModuleModel = Vtiger_Module_Model::getInstance($request->get('sourcemodule'));
     $mandatoryMapFields = array('salutationtype', 'firstname', 'lastname', 'title', 'account_id', 'birthday', 'email', 'secondaryemail', 'mobile', 'phone', 'homephone', 'mailingstreet', 'otherstreet', 'mailingpobox', 'otherpobox', 'mailingcity', 'othercity', 'mailingstate', 'otherstate', 'mailingzip', 'otherzip', 'mailingcountry', 'othercountry', 'otheraddress', 'description', 'mailingaddress', 'otheraddress');
     $customFieldMapping = array();
     $contactsFields = $contactsModuleModel->getFields();
     foreach ($fieldMappping as $vtFieldName => $googleFieldDetails) {
         if (!in_array($vtFieldName, $mandatoryMapFields) && $contactsFields[$vtFieldName]->isViewable()) {
             $customFieldMapping[$vtFieldName] = $googleFieldDetails;
         }
     }
     $skipFields = array('reference', 'contact_id', 'leadsource', 'assigned_user_id', 'donotcall', 'notify_owner', 'emailoptout', 'createdtime', 'modifiedtime', 'contact_no', 'modifiedby', 'isconvertedfromlead', 'created_user_id', 'portal', 'support_start_date', 'support_end_date', 'imagename');
     $emailFields = $phoneFields = $urlFields = $otherFields = array();
     $disAllowedFieldTypes = array('reference', 'picklist', 'multipicklist');
     foreach ($contactsFields as $contactFieldModel) {
         if ($contactFieldModel->isViewable() && !in_array($contactFieldModel->getFieldName(), array_merge($mandatoryMapFields, $skipFields))) {
             if ($contactFieldModel->getFieldDataType() == 'email') {
                 $emailFields[$contactFieldModel->getFieldName()] = $contactFieldModel->get('label');
             } else {
                 if ($contactFieldModel->getFieldDataType() == 'phone') {
                     $phoneFields[$contactFieldModel->getFieldName()] = $contactFieldModel->get('label');
                 } else {
                     if ($contactFieldModel->getFieldDataType() == 'url') {
                         $urlFields[$contactFieldModel->getFieldName()] = $contactFieldModel->get('label');
                     } else {
                         if (!in_array($contactFieldModel->getFieldDataType(), $disAllowedFieldTypes)) {
                             $otherFields[$contactFieldModel->getFieldName()] = $contactFieldModel->get('label');
                         }
                     }
                 }
             }
         }
     }
     $viewer = $this->getViewer($request);
     $viewer->assign('MODULENAME', $request->getModule());
     $viewer->assign('SOURCE_MODULE', $request->get('sourcemodule'));
     $viewer->assign('SELECTED_GROUP', $selectedGroup);
     $viewer->assign('SYNC_DIRECTION', $syncDirection);
     $viewer->assign('GOOGLE_GROUPS', $groups);
     $viewer->assign('GOOGLE_FIELDS', $targetFields);
     $viewer->assign('FIELD_MAPPING', $fieldMappping);
     $viewer->assign('CUSTOM_FIELD_MAPPING', $customFieldMapping);
     $viewer->assign('VTIGER_EMAIL_FIELDS', $emailFields);
     $viewer->assign('VTIGER_PHONE_FIELDS', $phoneFields);
     $viewer->assign('VTIGER_URL_FIELDS', $urlFields);
     $viewer->assign('VTIGER_OTHER_FIELDS', $otherFields);
     echo $viewer->view('ContactsSyncSettings.tpl', $request->getModule(), true);
 }
Пример #2
0
 /**
  * Function to add detail to entry element
  * @param <SimpleXMLElement> $entry
  * @param <Google_Contacts_Model> $entity
  * @param <Users_Record_Model> $user
  */
 protected function addEntityDetailsToAtomEntry(&$entry, $entity, $user)
 {
     $gdNS = $this->NS['gd'];
     $gdName = $entry->addChild("name", '', $gdNS);
     if ($entity->get('salutationtype')) {
         $gdName->addChild("namePrefix", $entity->get('salutationtype'), $gdNS);
     }
     if ($entity->get('firstname')) {
         $gdName->addChild("givenName", $entity->get('firstname'), $gdNS);
     }
     if ($entity->get('lastname')) {
         $gdName->addChild("familyName", $entity->get('lastname'), $gdNS);
     }
     $gdRel = $gdNS . '#';
     if ($entity->get('account_id') || $entity->get('title')) {
         $gdOrganization = $entry->addChild("organization", null, $gdNS);
         $gdOrganization->addAttribute("rel", "http://schemas.google.com/g/2005#other");
         if ($entity->get('account_id')) {
             $gdOrganization->addChild("orgName", $entity->get('account_id'), $gdNS);
         }
         if ($entity->get('title')) {
             $gdOrganization->addChild("orgTitle", $entity->get('title'), $gdNS);
         }
     }
     if (!isset($this->fieldMapping)) {
         $this->fieldMapping = Google_Utils_Helper::getFieldMappingForUser($user);
     }
     foreach ($this->fieldMapping as $vtFieldName => $googleFieldDetails) {
         if (in_array($googleFieldDetails['google_field_name'], array('gd:givenName', 'gd:familyName', 'gd:orgTitle', 'gd:orgName', 'gd:namePrefix'))) {
             continue;
         }
         switch ($googleFieldDetails['google_field_name']) {
             case 'gd:email':
                 if ($entity->get($vtFieldName)) {
                     $gdEmail = $entry->addChild("email", '', $gdNS);
                     if ($googleFieldDetails['google_field_type'] == 'custom') {
                         $gdEmail->addAttribute("label", $this->mbEncode(decode_html($googleFieldDetails['google_custom_label'])));
                     } else {
                         $gdEmail->addAttribute("rel", $gdRel . $googleFieldDetails['google_field_type']);
                     }
                     $gdEmail->addAttribute("address", $entity->get($vtFieldName));
                     if ($vtFieldName == 'email') {
                         $gdEmail->addAttribute("primary", 'true');
                     }
                 }
                 break;
             case 'gContact:birthday':
                 if ($entity->get('birthday')) {
                     $gContactNS = $this->NS['gContact'];
                     $gContactBirthday = $entry->addChild("birthday", '', $gContactNS);
                     $gContactBirthday->addAttribute("when", $entity->get('birthday'));
                 }
                 break;
             case 'gd:phoneNumber':
                 if ($entity->get($vtFieldName)) {
                     $gdPhoneMobile = $entry->addChild("phoneNumber", $entity->get($vtFieldName), $gdNS);
                     if ($googleFieldDetails['google_field_type'] == 'custom') {
                         $gdPhoneMobile->addAttribute("label", $this->mbEncode(decode_html($googleFieldDetails['google_custom_label'])));
                     } else {
                         $gdPhoneMobile->addAttribute("rel", $gdRel . $googleFieldDetails['google_field_type']);
                     }
                 }
                 break;
             case 'gd:structuredPostalAddress':
                 if ($vtFieldName == 'mailingaddress') {
                     if ($entity->get('mailingstreet') || $entity->get('mailingpobox') || $entity->get('mailingzip') || $entity->get('mailingcity') || $entity->get('mailingstate') || $entity->get('mailingcountry')) {
                         $gdAddressHome = $entry->addChild("structuredPostalAddress", null, $gdNS);
                         if ($googleFieldDetails['google_field_type'] == 'custom') {
                             $gdAddressHome->addAttribute("label", $this->mbEncode(decode_html($googleFieldDetails['google_custom_label'])));
                         } else {
                             $gdAddressHome->addAttribute("rel", $gdRel . $googleFieldDetails['google_field_type']);
                         }
                         if ($entity->get('mailingstreet')) {
                             $gdAddressHome->addChild("street", $entity->get('mailingstreet'), $gdNS);
                         }
                         if ($entity->get('mailingpobox')) {
                             $gdAddressHome->addChild("pobox", $entity->get('mailingpobox'), $gdNS);
                         }
                         if ($entity->get('mailingzip')) {
                             $gdAddressHome->addChild("postcode", $entity->get('mailingzip'), $gdNS);
                         }
                         if ($entity->get('mailingcity')) {
                             $gdAddressHome->addChild("city", $entity->get('mailingcity'), $gdNS);
                         }
                         if ($entity->get('mailingstate')) {
                             $gdAddressHome->addChild("region", $entity->get('mailingstate'), $gdNS);
                         }
                         if ($entity->get('mailingcountry')) {
                             $gdAddressHome->addChild("country", $entity->get('mailingcountry'), $gdNS);
                         }
                     }
                 } else {
                     if ($entity->get('otherstreet') || $entity->get('otherpobox') || $entity->get('otherzip') || $entity->get('othercity') || $entity->get('otherstate') || $entity->get('othercountry')) {
                         $gdAddressWork = $entry->addChild("structuredPostalAddress", null, $gdNS);
                         if ($googleFieldDetails['google_field_type'] == 'custom') {
                             $gdAddressWork->addAttribute("label", $this->mbEncode(decode_html($googleFieldDetails['google_custom_label'])));
                         } else {
                             $gdAddressWork->addAttribute("rel", $gdRel . $googleFieldDetails['google_field_type']);
                         }
                         if ($entity->get('otherstreet')) {
                             $gdAddressWork->addChild("street", $entity->get('otherstreet'), $gdNS);
                         }
                         if ($entity->get('otherpobox')) {
                             $gdAddressWork->addChild("pobox", $entity->get('otherpobox'), $gdNS);
                         }
                         if ($entity->get('otherzip')) {
                             $gdAddressWork->addChild("postcode", $entity->get('otherzip'), $gdNS);
                         }
                         if ($entity->get('othercity')) {
                             $gdAddressWork->addChild("city", $entity->get('othercity'), $gdNS);
                         }
                         if ($entity->get('otherstate')) {
                             $gdAddressWork->addChild("region", $entity->get('otherstate'), $gdNS);
                         }
                         if ($entity->get('othercountry')) {
                             $gdAddressWork->addChild("country", $entity->get('othercountry'), $gdNS);
                         }
                     }
                 }
                 break;
             case 'content':
                 if ($entity->get($vtFieldName)) {
                     $entry->addChild('content', $entity->get($vtFieldName));
                 }
                 break;
             case 'gContact:userDefinedField':
                 if ($entity->get($vtFieldName) && $googleFieldDetails['google_custom_label']) {
                     $userDefinedField = $entry->addChild('userDefinedField', '', $this->NS['gContact']);
                     $userDefinedField->addAttribute('key', $this->mbEncode(decode_html($googleFieldDetails['google_custom_label'])));
                     $userDefinedField->addAttribute('value', $this->mbEncode($entity->get($vtFieldName)));
                 }
                 break;
             case 'gContact:website':
                 if ($entity->get($vtFieldName)) {
                     $websiteField = $entry->addChild('website', '', $this->NS['gContact']);
                     if ($googleFieldDetails['google_field_type'] == 'custom') {
                         $websiteField->addAttribute('label', $this->mbEncode(decode_html($googleFieldDetails['google_custom_label'])));
                     } else {
                         $websiteField->addAttribute('rel', $googleFieldDetails['google_field_type']);
                     }
                     $websiteField->addAttribute('href', $this->mbEncode($entity->get($vtFieldName)));
                 }
                 break;
         }
     }
 }