本文整理汇总了PHP中CRM_Contact_BAO_Contact_Utils::processGreetingTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Contact_Utils::processGreetingTemplate方法的具体用法?PHP CRM_Contact_BAO_Contact_Utils::processGreetingTemplate怎么用?PHP CRM_Contact_BAO_Contact_Utils::processGreetingTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Contact_Utils
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Contact_Utils::processGreetingTemplate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processGreetings
/**
* Process greetings and cache.
*
* @param object $contact
* Contact object after save.
* @param bool $useDefaults
* Use default greeting values.
*/
public static function processGreetings(&$contact, $useDefaults = FALSE)
{
if ($useDefaults) {
//retrieve default greetings
$defaultGreetings = CRM_Core_PseudoConstant::greetingDefaults();
$contactDefaults = $defaultGreetings[$contact->contact_type];
}
// note that contact object not always has required greeting related
// fields that are required to calculate greeting and
// also other fields used in tokens etc,
// hence we need to retrieve it again.
if ($contact->_query !== FALSE) {
$contact->find(TRUE);
}
// store object values to an array
$contactDetails = array();
CRM_Core_DAO::storeValues($contact, $contactDetails);
$contactDetails = array(array($contact->id => $contactDetails));
$emailGreetingString = $postalGreetingString = $addresseeString = NULL;
$updateQueryString = array();
//cache email and postal greeting to greeting display
if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
$emailGreetingString = $contact->email_greeting_custom;
} elseif ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) {
// the filter value for Individual contact type is set to 1
$filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting');
$emailGreeting = CRM_Core_PseudoConstant::greeting($filter);
$emailGreetingString = $emailGreeting[$contact->email_greeting_id];
$updateQueryString[] = " email_greeting_custom = NULL ";
} else {
if ($useDefaults) {
reset($contactDefaults['email_greeting']);
$emailGreetingID = key($contactDefaults['email_greeting']);
$emailGreetingString = $contactDefaults['email_greeting'][$emailGreetingID];
$updateQueryString[] = " email_greeting_id = {$emailGreetingID} ";
$updateQueryString[] = " email_greeting_custom = NULL ";
} elseif ($contact->email_greeting_custom) {
$updateQueryString[] = " email_greeting_display = NULL ";
}
}
if ($emailGreetingString) {
CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($emailGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
$emailGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($emailGreetingString));
$updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
}
//postal greetings
if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
$postalGreetingString = $contact->postal_greeting_custom;
} elseif ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) {
$filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting');
$postalGreeting = CRM_Core_PseudoConstant::greeting($filter);
$postalGreetingString = $postalGreeting[$contact->postal_greeting_id];
$updateQueryString[] = " postal_greeting_custom = NULL ";
} else {
if ($useDefaults) {
reset($contactDefaults['postal_greeting']);
$postalGreetingID = key($contactDefaults['postal_greeting']);
$postalGreetingString = $contactDefaults['postal_greeting'][$postalGreetingID];
$updateQueryString[] = " postal_greeting_id = {$postalGreetingID} ";
$updateQueryString[] = " postal_greeting_custom = NULL ";
} elseif ($contact->postal_greeting_custom) {
$updateQueryString[] = " postal_greeting_display = NULL ";
}
}
if ($postalGreetingString) {
CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($postalGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
$postalGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($postalGreetingString));
$updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
}
// addressee
if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
$addresseeString = $contact->addressee_custom;
} elseif ($contact->addressee_id != 'null' && $contact->addressee_id) {
$filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'addressee');
$addressee = CRM_Core_PseudoConstant::greeting($filter);
$addresseeString = $addressee[$contact->addressee_id];
$updateQueryString[] = " addressee_custom = NULL ";
} else {
if ($useDefaults) {
reset($contactDefaults['addressee']);
$addresseeID = key($contactDefaults['addressee']);
$addresseeString = $contactDefaults['addressee'][$addresseeID];
$updateQueryString[] = " addressee_id = {$addresseeID} ";
$updateQueryString[] = " addressee_custom = NULL ";
} elseif ($contact->addressee_custom) {
$updateQueryString[] = " addressee_display = NULL ";
}
}
if ($addresseeString) {
CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($addresseeString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
$addresseeString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($addresseeString));
$updateQueryString[] = " addressee_display = '{$addresseeString}'";
//.........这里部分代码省略.........
示例2: updateGreeting
//.........这里部分代码省略.........
$filter = CRM_Utils_Array::key($contactType, $contactTypeFilters);
$defaulValueID = CRM_Core_OptionGroup::values($greeting, NULL, NULL, NULL, " AND is_default = 1 AND ( filter = {$filter} OR filter = 0 )", "value");
$valueID = array_pop($defaulValueID);
}
$filter = array('contact_type' => $contactType, 'greeting_type' => $greeting);
$allGreetings = CRM_Core_PseudoConstant::greeting($filter);
$originalGreetingString = $greetingString = CRM_Utils_Array::value($valueID, $allGreetings);
if (!$greetingString) {
CRM_Core_Error::fatal(ts('Incorrect greeting value id %1.', array(1 => $valueID)));
}
// build return properties based on tokens
require_once 'CRM/Utils/Token.php';
$greetingTokens = CRM_Utils_Token::getTokens($greetingString);
$tokens = CRM_Utils_Array::value('contact', $greetingTokens);
$greetingsReturnProperties = array();
if (is_array($tokens)) {
$greetingsReturnProperties = array_fill_keys(array_values($tokens), 1);
}
//process all contacts only when force pass.
$force = CRM_Utils_Request::retrieve('force', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
$processAll = $processOnlyIdSet = FALSE;
if (in_array($force, array(1, 'true'))) {
$processAll = TRUE;
} elseif ($force == 2) {
$processOnlyIdSet = TRUE;
}
//FIXME : apiQuery should handle these clause.
$filterContactFldIds = $filterIds = array();
if (!$processAll) {
$idFldName = $displayFldName = NULL;
if ($greeting == 'email_greeting' || $greeting == 'postal_greeting' || $greeting == 'addressee') {
$idFldName = $greeting . '_id';
$displayFldName = $greeting . '_display';
}
if ($idFldName) {
$sql = "\nSELECT DISTINCT id, {$idFldName}\n FROM civicrm_contact\n WHERE contact_type = %1\n AND ( {$idFldName} IS NULL OR\n ( {$idFldName} IS NOT NULL AND {$displayFldName} IS NULL ) )\n ";
$dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($contactType, 'String')));
while ($dao->fetch()) {
$filterContactFldIds[$dao->id] = $dao->{$idFldName};
if (!CRM_Utils_System::isNull($dao->{$idFldName})) {
$filterIds[$dao->id] = $dao->{$idFldName};
}
}
}
if (empty($filterContactFldIds)) {
$filterContactFldIds[] = 0;
}
}
if (empty($filterContactFldIds)) {
return;
}
// retrieve only required contact information
require_once 'CRM/Utils/Token.php';
$extraParams[] = array('contact_type', '=', $contactType, 0, 0);
// we do token replacement in the replaceGreetingTokens hook
list($greetingDetails) = CRM_Utils_Token::getTokenDetails(array_keys($filterContactFldIds), $greetingsReturnProperties, FALSE, FALSE, $extraParams);
// perform token replacement and build update SQL
$contactIds = array();
$cacheFieldQuery = "UPDATE civicrm_contact SET {$greeting}_display = CASE id ";
foreach ($greetingDetails as $contactID => $contactDetails) {
if (!$processAll && !array_key_exists($contactID, $filterContactFldIds)) {
continue;
}
if ($processOnlyIdSet) {
if (!array_key_exists($contactID, $filterIds)) {
continue;
}
if ($id) {
$greetingString = $originalGreetingString;
$contactIds[] = $contactID;
} else {
if ($greetingBuffer = CRM_Utils_Array::value($filterContactFldIds[$contactID], $allGreetings)) {
$greetingString = $greetingBuffer;
}
}
$allContactIds[] = $contactID;
} else {
$greetingString = $originalGreetingString;
if ($greetingBuffer = CRM_Utils_Array::value($filterContactFldIds[$contactID], $allGreetings)) {
$greetingString = $greetingBuffer;
} else {
$contactIds[] = $contactID;
}
}
CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($greetingString, $contactDetails, $contactID, 'CRM_UpdateGreeting');
$greetingString = CRM_Core_DAO::escapeString($greetingString);
$cacheFieldQuery .= " WHEN {$contactID} THEN '{$greetingString}' ";
$allContactIds[] = $contactID;
}
if (!empty($allContactIds)) {
$cacheFieldQuery .= " ELSE {$greeting}_display\n END;";
if (!empty($contactIds)) {
// need to update greeting _id field.
$queryString = "\nUPDATE civicrm_contact\n SET {$greeting}_id = {$valueID}\n WHERE id IN (" . implode(',', $contactIds) . ")";
CRM_Core_DAO::executeQuery($queryString);
}
// now update cache field
CRM_Core_DAO::executeQuery($cacheFieldQuery);
}
}