當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法代碼示例

本文整理匯總了PHP中CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法的具體用法?PHP CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer怎麽用?PHP CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CRM_Contact_BAO_Contact_Utils的用法示例。


在下文中一共展示了CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: add


//.........這裏部分代碼省略.........
             $params['contact_sub_type'] = 'null';
         } else {
             if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'], TRUE)) {
                 // we'll need to fix tests to handle this
                 // CRM-7925
                 CRM_Core_Error::fatal(ts('The Contact Sub Type does not match the Contact type for this record'));
             }
             if (is_array($params['contact_sub_type'])) {
                 $params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
             } else {
                 $params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . trim($params['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
             }
         }
     } else {
         // Reset the value.
         // CRM-101XX.
         $params['contact_sub_type'] = 'null';
     }
     // Fixed contact source.
     if (isset($params['contact_source'])) {
         $params['source'] = $params['contact_source'];
     }
     // Fix for preferred communication method.
     $prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
     if ($prefComm && is_array($prefComm)) {
         unset($params['preferred_communication_method']);
         $newPref = array();
         foreach ($prefComm as $k => $v) {
             if ($v) {
                 $newPref[$k] = $v;
             }
         }
         $prefComm = $newPref;
         if (is_array($prefComm) && !empty($prefComm)) {
             $prefComm = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($prefComm)) . CRM_Core_DAO::VALUE_SEPARATOR;
             $contact->preferred_communication_method = $prefComm;
         } else {
             $contact->preferred_communication_method = '';
         }
     }
     $allNull = $contact->copyValues($params);
     $contact->id = CRM_Utils_Array::value('contact_id', $params);
     if ($contact->contact_type == 'Individual') {
         $allNull = FALSE;
         // Format individual fields.
         CRM_Contact_BAO_Individual::format($params, $contact);
     } elseif ($contact->contact_type == 'Household') {
         if (isset($params['household_name'])) {
             $allNull = FALSE;
             $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
         }
     } elseif ($contact->contact_type == 'Organization') {
         if (isset($params['organization_name'])) {
             $allNull = FALSE;
             $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
         }
     }
     $privacy = CRM_Utils_Array::value('privacy', $params);
     if ($privacy && is_array($privacy) && !empty($privacy)) {
         $allNull = FALSE;
         foreach (self::$_commPrefs as $name) {
             $contact->{$name} = CRM_Utils_Array::value($name, $privacy, FALSE);
         }
     }
     // Since hash was required, make sure we have a 0 value for it (CRM-1063).
     // @todo - does this mean we can remove this block?
     // Fixed in 1.5 by making hash optional, only do this in create mode, not update.
     if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
         $allNull = FALSE;
         $contact->hash = md5(uniqid(rand(), TRUE));
     }
     // Even if we don't need $employerId, it's important to call getFieldValue() before
     // the contact is saved because we want the existing value to be cached.
     // createCurrentEmployerRelationship() needs the old value not the updated one. CRM-10788
     $employerId = empty($contact->id) ? NULL : CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id');
     if (!$allNull) {
         $contact->save();
         CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id);
     }
     if ($contact->contact_type == 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) {
         // Create current employer.
         $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params);
         $newContact = FALSE;
         if (empty($params['contact_id'])) {
             $newContact = TRUE;
         }
         if ($newEmployer) {
             CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact);
         } else {
             if ($employerId) {
                 CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
             }
         }
     }
     // Update cached employer name.
     if ($contact->contact_type == 'Organization') {
         CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id);
     }
     return $contact;
 }
開發者ID:JSProffitt,項目名稱:civicrm-website-org,代碼行數:101,代碼來源:Contact.php

示例2: add

 /**
  * takes an associative array and creates a contact object
  *
  * the function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Contact_BAO_Contact object
  * @access public
  * @static
  */
 static function add(&$params)
 {
     $contact =& new CRM_Contact_DAO_Contact();
     if (empty($params)) {
         return;
     }
     //fixed contact source
     if (isset($params['contact_source'])) {
         $params['source'] = $params['contact_source'];
     }
     //fix for preferred communication method
     $prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
     if ($prefComm && is_array($prefComm)) {
         unset($params['preferred_communication_method']);
         $newPref = array();
         foreach ($prefComm as $k => $v) {
             if ($v) {
                 $newPref[$k] = $v;
             }
         }
         $prefComm = $newPref;
         if (is_array($prefComm) && !empty($prefComm)) {
             $prefComm = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($prefComm)) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
             $contact->preferred_communication_method = $prefComm;
         } else {
             $contact->preferred_communication_method = '';
         }
     }
     $allNull = $contact->copyValues($params);
     $contact->id = CRM_Utils_Array::value('contact_id', $params);
     if ($contact->contact_type == 'Individual') {
         $allNull = false;
         //format individual fields
         require_once "CRM/Contact/BAO/Individual.php";
         CRM_Contact_BAO_Individual::format($params, $contact);
     } else {
         if ($contact->contact_type == 'Household') {
             if (isset($params['household_name'])) {
                 $allNull = false;
                 $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
             }
         } else {
             if ($contact->contact_type == 'Organization') {
                 if (isset($params['organization_name'])) {
                     $allNull = false;
                     $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
                 }
             }
         }
     }
     // privacy block
     $privacy = CRM_Utils_Array::value('privacy', $params);
     if ($privacy && is_array($privacy) && !empty($privacy)) {
         $allNull = false;
         foreach (self::$_commPrefs as $name) {
             $contact->{$name} = CRM_Utils_Array::value($name, $privacy, false);
         }
     }
     // since hash was required, make sure we have a 0 value for it, CRM-1063
     // fixed in 1.5 by making hash optional
     // only do this in create mode, not update
     if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
         $allNull = false;
         $contact->hash = md5(uniqid(rand(), true));
     }
     if (!$allNull) {
         $contact->save();
         require_once 'CRM/Core/BAO/Log.php';
         CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id);
     }
     if ($contact->contact_type == 'Individual' && array_key_exists('current_employer', $params)) {
         // create current employer
         if ($params['current_employer']) {
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $params['current_employer']);
         } else {
             //unset if employer id exits
             if ($employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id')) {
                 require_once 'CRM/Contact/BAO/Contact/Utils.php';
                 CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
             }
         }
     }
     //update cached employee name
     if ($contact->contact_type == 'Organization') {
         require_once 'CRM/Contact/BAO/Contact/Utils.php';
         CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id);
//.........這裏部分代碼省略.........
開發者ID:ksecor,項目名稱:civicrm,代碼行數:101,代碼來源:Contact.php


注:本文中的CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。