当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_PseudoConstant::greeting方法代码示例

本文整理汇总了PHP中CRM_Core_PseudoConstant::greeting方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_PseudoConstant::greeting方法的具体用法?PHP CRM_Core_PseudoConstant::greeting怎么用?PHP CRM_Core_PseudoConstant::greeting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_PseudoConstant的用法示例。


在下文中一共展示了CRM_Core_PseudoConstant::greeting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateGreeting

 public function updateGreeting()
 {
     $config = CRM_Core_Config::singleton();
     $contactType = CRM_Utils_Request::retrieve('ct', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
     if (!in_array($contactType, array('Individual', 'Household', 'Organization'))) {
         CRM_Core_Error::fatal(ts('Invalid Contact Type.'));
     }
     $greeting = CRM_Utils_Request::retrieve('gt', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
     if (!in_array($greeting, array('email_greeting', 'postal_greeting', 'addressee'))) {
         CRM_Core_Error::fatal(ts('Invalid Greeting Type.'));
     }
     if (in_array($greeting, array('email_greeting', 'postal_greeting')) && $contactType == 'Organization') {
         CRM_Core_Error::fatal(ts('You cannot use %1 for contact type %2.', array(1 => $greeting, 2 => $contactType)));
     }
     $valueID = $id = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
     // if valueID is not passed use default value
     if (!$valueID) {
         require_once 'CRM/Core/OptionGroup.php';
         $contactTypeFilters = array(1 => 'Individual', 2 => 'Household', 3 => 'Organization');
         $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 {
//.........这里部分代码省略.........
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:101,代码来源:UpdateGreeting.php

示例2: greeting

 /**
  * Get all types of Greetings.
  *
  * The static array of greeting is returned
  *
  * @access public
  * @static
  *
  * @param $filter - get All Email Greetings - default is to get only active ones.
  *
  * @return array - array reference of all greetings.
  *
  */
 public static function greeting($filter, $columnName = 'label')
 {
     $index = $filter['greeting_type'] . '_' . $columnName;
     // also add contactType to the array
     $contactType = CRM_Utils_Array::value('contact_type', $filter);
     if ($contactType) {
         $index .= '_' . $contactType;
     }
     if (NULL === self::$greeting) {
         self::$greeting = array();
     }
     if (!CRM_Utils_Array::value($index, self::$greeting)) {
         $filterCondition = NULL;
         if ($contactType) {
             $filterVal = 'v.filter =';
             switch ($contactType) {
                 case 'Individual':
                     $filterVal .= "1";
                     break;
                 case 'Household':
                     $filterVal .= "2";
                     break;
                 case 'Organization':
                     $filterVal .= "3";
                     break;
             }
             $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
         }
         self::$greeting[$index] = CRM_Core_OptionGroup::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
     }
     return self::$greeting[$index];
 }
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:45,代码来源:PseudoConstant.php

示例3: buildProfile


//.........这里部分代码省略.........
         $group = $form->addGroup($options, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         } else {
             $group->setAttribute('allowClear', TRUE);
         }
     } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
         $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         if ($usedFor == 'onbehalf') {
             $profileType = 'Organization';
         } elseif ($usedFor == 'honor') {
             $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
             if ($profileType == 'Contact') {
                 $profileType = 'Individual';
             }
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE));
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'));
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
开发者ID:rollox,项目名称:civicrm-core,代码行数:67,代码来源:UFGroup.php

示例4: isErrorInCoreData


//.........这里部分代码省略.........
                         }
                     }
                     break;
                 case 'geo_code_1':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_1']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) {
                                     continue;
                                 } else {
                                     self::addToErrorMsg(ts('Geo code 1'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_2':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_2']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) {
                                     continue;
                                 } else {
                                     self::addToErrorMsg(ts('Geo code 2'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                     //check for any error in email/postal greeting, addressee,
                     //custom email/postal greeting, custom addressee, CRM-4575
                 //check for any error in email/postal greeting, addressee,
                 //custom email/postal greeting, custom addressee, CRM-4575
                 case 'email_greeting':
                     $emailGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'email_greeting');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($emailGreetingFilter))) {
                         self::addToErrorMsg(ts('Email Greeting must be one of the configured format options. Check Administer >> Option Lists >> Email Greetings for valid values'), $errorMessage);
                     }
                     break;
                 case 'postal_greeting':
                     $postalGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'postal_greeting');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($postalGreetingFilter))) {
                         self::addToErrorMsg(ts('Postal Greeting must be one of the configured format options. Check Administer >> Option Lists >> Postal Greetings for valid values'), $errorMessage);
                     }
                     break;
                 case 'addressee':
                     $addresseeFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'addressee');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($addresseeFilter))) {
                         self::addToErrorMsg(ts('Addressee must be one of the configured format options. Check Administer >> Option Lists >> Addressee for valid values'), $errorMessage);
                     }
                     break;
                 case 'email_greeting_custom':
                     if (array_key_exists('email_greeting', $params)) {
                         $emailGreetingLabel = key(CRM_Core_OptionGroup::values('email_greeting', true, null, null, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('email_greeting', $params) != $emailGreetingLabel) {
                             self::addToErrorMsg(ts('Email Greeting - Custom'), $errorMessage);
                         }
                     }
                     break;
                 case 'postal_greeting_custom':
                     if (array_key_exists('postal_greeting', $params)) {
                         $postalGreetingLabel = key(CRM_Core_OptionGroup::values('postal_greeting', true, null, null, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('postal_greeting', $params) != $postalGreetingLabel) {
                             self::addToErrorMsg(ts('Postal Greeting - Custom'), $errorMessage);
                         }
                     }
开发者ID:bhirsch,项目名称:voipdev,代码行数:67,代码来源:Contact.php

示例5: restWhere


//.........这里部分代码省略.........
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'is_deceased') {
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'contact_id') {
         if (is_int($value)) {
             $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
         }
     } elseif ($name === 'name') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'current_employer') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
         $ceWhereClause = self::buildClause($wc, $op, $value);
         $ceWhereClause .= " AND contact_a.contact_type = 'Individual'";
         $this->_where[$grouping][] = $ceWhereClause;
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'email_greeting') {
         $filterCondition = array('greeting_type' => 'email_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting'));
     } elseif ($name === 'postal_greeting') {
         $filterCondition = array('greeting_type' => 'postal_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting'));
     } elseif ($name === 'addressee') {
         $filterCondition = array('greeting_type' => 'addressee');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee'));
     } elseif (substr($name, 0, 4) === 'url-') {
         $tName = 'civicrm_website';
         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = 'civicrm_website.url';
         $this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'contact_is_deleted') {
         $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } else {
         // sometime the value is an array, need to investigate and fix
         if (is_array($value)) {
             CRM_Core_Error::fatal();
         }
         if (!empty($field['where'])) {
             if ($op != 'IN') {
                 $value = $strtolower($value);
             }
             if ($wildcard) {
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:67,代码来源:Query.php

示例6: displayProfile

 /**
  * Function to build the array for display the profile fields
  *
  * @param array $params key value.
  * @param int $gid profile Id
  * @param array $groupTitle Profile Group Title.
  * @param array $values formatted array of key value
  *
  * @param array $profileFields
  *
  * @return void
  * @access public
  * @static
  */
 static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = array())
 {
     if ($gid) {
         $config = CRM_Core_Config::singleton();
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::ADD);
         }
         foreach ($fields as $v) {
             if (!empty($v['groupTitle'])) {
                 $groupTitle['groupTitle'] = $v['groupTitle'];
                 break;
             }
         }
         $customVal = '';
         $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             $skip = FALSE;
             // skip fields that should not be displayed separately
             if ($field['skipDisplay']) {
                 continue;
             }
             $index = $field['title'];
             if ($name === 'organization_name') {
                 $values[$index] = $params[$name];
             }
             if ('state_province' == substr($name, 0, 14)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif ('date' == substr($name, -4)) {
                 $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull);
             } elseif ('country' == substr($name, 0, 7)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::country($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif ('county' == substr($name, 0, 6)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::county($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix', 'communication_style'))) {
                 $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]);
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $filterCondition = array('greeting_type' => $name);
                 $greeting = CRM_Core_PseudoConstant::greeting($filterCondition);
                 $values[$index] = $greeting[$params[$name]];
             } elseif ($name === 'preferred_communication_method') {
                 $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
                 $compref = array();
                 $pref = $params[$name];
                 if (is_array($pref)) {
                     foreach ($pref as $k => $v) {
                         if ($v) {
                             $compref[] = $communicationFields[$k];
                         }
                     }
                 }
                 $values[$index] = implode(',', $compref);
             } elseif ($name == 'contact_sub_type') {
                 $values[$index] = implode(', ', $params[$name]);
             } elseif ($name == 'group') {
                 $groups = CRM_Contact_BAO_GroupContact::getGroupList();
                 $title = array();
                 foreach ($params[$name] as $gId => $dontCare) {
                     if ($dontCare) {
                         $title[] = $groups[$gId];
                     }
                 }
                 $values[$index] = implode(', ', $title);
             } elseif ($name == 'tag') {
                 $entityTags = $params[$name];
                 $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $title = array();
                 if (is_array($entityTags)) {
//.........这里部分代码省略.........
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:101,代码来源:Event.php

示例7: restWhere


//.........这里部分代码省略.........
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'is_deceased') {
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'contact_id') {
         if (is_int($value)) {
             $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
         }
     } elseif ($name === 'name') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'current_employer') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'email_greeting') {
         $filterCondition = array('greeting_type' => 'email_greeting');
         $emailGreetings = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $emailGreetings[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
     } elseif ($name === 'postal_greeting') {
         $filterCondition = array('greeting_type' => 'postal_greeting');
         $postalGreetings = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $postalGreetings[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
     } elseif ($name === 'addressee') {
         $filterCondition = array('greeting_type' => 'addressee');
         $addressee = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $addressee[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
     } elseif (substr($name, 0, 4) === 'url-') {
         $tName = 'civicrm_website';
         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:67,代码来源:Query.php

示例8: buildProfile


//.........这里部分代码省略.........
         $gender = CRM_Core_PseudoConstant::gender();
         foreach ($gender as $key => $var) {
             $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
         }
         $form->addGroup($genderOptions, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         }
     } elseif ($fieldName === 'individual_prefix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
     } elseif ($fieldName === 'individual_suffix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
         if ($onBehalf) {
             $profileType = 'Organization';
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $sel = $form->add('select', $name, $title, $subtypeList, $required);
         $sel->setMultiple(TRUE);
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::pcm();
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:67,代码来源:UFGroup.php

示例9: _civicrm_add_formatted_param

/**
 * This function adds the contact variable in $values to the
 * parameter list $params.  For most cases, $values should have length 1.  If
 * the variable being added is a child of Location, a location_type_id must
 * also be included.  If it is a child of phone, a phone_type must be included.
 *
 * @param array  $values    The variable(s) to be added
 * @param array  $params    The structured parameter list
 * 
 * @return bool|CRM_Utils_Error
 * @access public
 */
function _civicrm_add_formatted_param(&$values, &$params)
{
    /* Crawl through the possible classes: 
     * Contact 
     *      Individual 
     *      Household
     *      Organization
     *          Location 
     *              Address 
     *              Email 
     *              Phone 
     *              IM 
     *      Note
     *      Custom 
     */
    /* Cache the various object fields */
    static $fields = null;
    if ($fields == null) {
        $fields = array();
    }
    //first add core contact values since for other Civi modules they are not added
    require_once 'CRM/Contact/BAO/Contact.php';
    $contactFields =& CRM_Contact_DAO_Contact::fields();
    _civicrm_store_values($contactFields, $values, $params);
    if (isset($values['contact_type'])) {
        /* we're an individual/household/org property */
        $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields();
        _civicrm_store_values($fields[$values['contact_type']], $values, $params);
        return true;
    }
    if (isset($values['individual_prefix'])) {
        if ($params['prefix_id']) {
            $prefixes = array();
            $prefixes = CRM_Core_PseudoConstant::individualPrefix();
            $params['prefix'] = $prefixes[$params['prefix_id']];
        } else {
            $params['prefix'] = $values['individual_prefix'];
        }
        return true;
    }
    if (isset($values['individual_suffix'])) {
        if ($params['suffix_id']) {
            $suffixes = array();
            $suffixes = CRM_Core_PseudoConstant::individualSuffix();
            $params['suffix'] = $suffixes[$params['suffix_id']];
        } else {
            $params['suffix'] = $values['individual_suffix'];
        }
        return true;
    }
    //CRM-4575
    if (isset($values['email_greeting'])) {
        if ($params['email_greeting_id']) {
            $emailGreetings = array();
            $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'email_greeting');
            $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter);
            $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']];
        } else {
            $params['email_greeting'] = $values['email_greeting'];
        }
        return true;
    }
    if (isset($values['postal_greeting'])) {
        if ($params['postal_greeting_id']) {
            $postalGreetings = array();
            $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'postal_greeting');
            $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter);
            $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']];
        } else {
            $params['postal_greeting'] = $values['postal_greeting'];
        }
        return true;
    }
    if (isset($values['addressee'])) {
        if ($params['addressee_id']) {
            $addressee = array();
            $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'addressee');
            $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter);
            $params['addressee'] = $addressee[$params['addressee_id']];
        } else {
            $params['addressee'] = $values['addressee'];
        }
        return true;
    }
    if (isset($values['gender'])) {
        if ($params['gender_id']) {
            $genders = array();
            $genders = CRM_Core_PseudoConstant::gender();
//.........这里部分代码省略.........
开发者ID:ksecor,项目名称:civicrm,代码行数:101,代码来源:utils.php

示例10: exportComponents


//.........这里部分代码省略.........
                                                                             if ($datavalue['location_type_id']) {
                                                                                 if ($colkey == 'im') {
                                                                                     $output = $datavalue['name'];
                                                                                 } else {
                                                                                     $output = $datavalue[$colkey];
                                                                                 }
                                                                             } else {
                                                                                 $output = '';
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                     if ($is_valid) {
                                                         $row[] = $output;
                                                     } else {
                                                         $row[] = '';
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey) && $is_valid) {
                                             $row[] = $custom_data;
                                         } else {
                                             if ($query->_fields[$relationkey]['name'] && $is_valid) {
                                                 if ($query->_fields[$relationkey]['name'] == 'gender') {
                                                     $getGenders =& CRM_Core_PseudoConstant::gender();
                                                     $gender = array_search($data->gender_id, array_flip($getGenders));
                                                     $row[] = $gender;
                                                 } else {
                                                     if ($query->_fields[$relationkey]['name'] == 'greeting_type') {
                                                         $getgreeting =& CRM_Core_PseudoConstant::greeting();
                                                         $greeting = array_search($data->greeting_type_id, array_flip($getgreeting));
                                                         $row[] = $greeting;
                                                     } else {
                                                         $colValue = $query->_fields[$relationkey]['name'];
                                                         $row[] = $data->{$colValue};
                                                     }
                                                 }
                                             } else {
                                                 if ($customData && $is_valid) {
                                                     $row[] = $customData;
                                                 } else {
                                                     $row[] = '';
                                                 }
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (isset($fieldValue) && $fieldValue != '') {
                                     //check for custom data
                                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) {
                                         $row[$field] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $query->_options);
                                     } else {
                                         if (array_key_exists($field, $multipleSelectFields)) {
                                             //option group fixes
                                             $paramsNew = array($field => $fieldValue);
                                             if ($field == 'test_tutoring') {
                                                 $name = array($field => array('newName' => $field, 'groupName' => 'test'));
                                             } else {
                                                 if (substr($field, 0, 4) == 'cmr_') {
                                                     //for  readers group
开发者ID:ksecor,项目名称:civicrm,代码行数:67,代码来源:Export.php

示例11: buildQuickForm

 /**
  * build the form elements for Communication Preferences object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $privacy = $commPreff = $commPreference = array();
     $privacyOptions = CRM_Core_SelectValues::privacy();
     foreach ($privacyOptions as $name => $label) {
         $privacy[] = HTML_QuickForm::createElement('advcheckbox', $name, null, $label);
     }
     $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
     // preferred communication method
     require_once 'CRM/Core/PseudoConstant.php';
     $comm = CRM_Core_PseudoConstant::pcm();
     foreach ($comm as $value => $title) {
         $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $value, null, $title);
     }
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     if (!empty($privacyOptions)) {
         $commPreference['privacy'] = $privacyOptions;
     }
     if (!empty($comm)) {
         $commPreference['preferred_communication_method'] = $comm;
     }
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
     $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
     $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
     foreach ($greetings as $greeting => $fields) {
         $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
         //add addressee in Contact form
         $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
         if (!empty($greetingTokens)) {
             $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
             //custom addressee
             $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
         }
     }
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:52,代码来源:CommunicationPreferences.php

示例12: processGreetings

 /**
  * Function to process greetings and cache
  *
  */
 static function processGreetings(&$contact)
 {
     // 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();
     require_once 'CRM/Activity/BAO/Activity.php';
     //email greeting
     if ($contact->contact_type == 'Individual' || $contact->contact_type == 'Household') {
         if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
             $emailGreetingString = $contact->email_greeting_custom;
         } else {
             if ($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];
             } else {
                 $updateQueryString[] = " email_greeting_display = NULL ";
             }
         }
         if ($emailGreetingString) {
             CRM_Activity_BAO_Activity::replaceGreetingTokens($emailGreetingString, $contactDetails, $contact->id);
             $emailGreetingString = CRM_Core_DAO::escapeString($emailGreetingString);
             $updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
         }
         //postal greetings
         if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
             $postalGreetingString = $contact->postal_greeting_custom;
         } else {
             if ($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];
             } elseif ($contact->postal_greeting_custom) {
                 $updateQueryString[] = " postal_greeting_display = NULL ";
             }
         }
         if ($postalGreetingString) {
             CRM_Activity_BAO_Activity::replaceGreetingTokens($postalGreetingString, $contactDetails, $contact->id);
             $postalGreetingString = CRM_Core_DAO::escapeString($postalGreetingString);
             $updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
         }
     }
     // addressee
     if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
         $addresseeString = $contact->addressee_custom;
     } else {
         if ($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];
         } else {
             $updateQueryString[] = " addressee_display = NULL ";
         }
     }
     if ($addresseeString) {
         CRM_Activity_BAO_Activity::replaceGreetingTokens($addresseeString, $contactDetails, $contact->id);
         $addresseeString = CRM_Core_DAO::escapeString($addresseeString);
         $updateQueryString[] = " addressee_display = '{$addresseeString}'";
     }
     if (!empty($updateQueryString)) {
         $updateQueryString = implode(',', $updateQueryString);
         $queryString = "UPDATE civicrm_contact SET {$updateQueryString} WHERE id = {$contact->id}";
         CRM_Core_DAO::executeQuery($queryString);
     }
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:73,代码来源:Contact.php

示例13: restWhere


//.........这里部分代码省略.........
                                             $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                         }
                                     } else {
                                         if ($name === 'is_deceased') {
                                             $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                         } else {
                                             if ($name === 'contact_id') {
                                                 if (is_int($value)) {
                                                     $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                 }
                                             } else {
                                                 if ($name === 'name') {
                                                     $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                     if ($wildcard) {
                                                         $value = "%{$value}%";
                                                         $op = 'LIKE';
                                                     }
                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                 } else {
                                                     if ($name === 'current_employer') {
                                                         $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                         if ($wildcard) {
                                                             $value = "%{$value}%";
                                                             $op = 'LIKE';
                                                         }
                                                         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
                                                         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
                                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                     } else {
                                                         if ($name === 'email_greeting') {
                                                             $filterCondition = array('greeting_type' => 'email_greeting');
                                                             $emailGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                             if (is_numeric($value)) {
                                                                 $value = $emailGreetings[(int) $value];
                                                             }
                                                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                             $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
                                                         } else {
                                                             if ($name === 'postal_greeting') {
                                                                 $filterCondition = array('greeting_type' => 'postal_greeting');
                                                                 $postalGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                 if (is_numeric($value)) {
                                                                     $value = $postalGreetings[(int) $value];
                                                                 }
                                                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                 $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
                                                             } else {
                                                                 if ($name === 'addressee') {
                                                                     $filterCondition = array('greeting_type' => 'addressee');
                                                                     $addressee =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                     if (is_numeric($value)) {
                                                                         $value = $addressee[(int) $value];
                                                                     }
                                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                     $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
                                                                 } else {
                                                                     // sometime the value is an array, need to investigate and fix
                                                                     if (is_array($value)) {
                                                                         CRM_Core_Error::fatal();
开发者ID:ksecor,项目名称:civicrm,代码行数:67,代码来源:Query.php

示例14: _civicrm_greeting_format_params

/**
 * Validate the addressee or email or postal greetings 
 *
 * @param  $params                   Associative array of property name/value
 *                                   pairs to insert in new contact.
 * 
 * @return array (reference )        null on success, error message otherwise
 *
 * @access public
 */
function _civicrm_greeting_format_params( &$params ) 
{
    $greetingParams = array( '', '_id', '_custom' );
    foreach ( array( 'email', 'postal', 'addressee' ) as $key ) {
        $greeting = '_greeting';
        if ( $key == 'addressee' ) {
            $greeting = '';   
        } 

        $formatParams = false;
        // unset display value from params.
        if ( isset( $params["{$key}{$greeting}_display"] ) ) {
            unset( $params["{$key}{$greeting}_display"] );  
        }

        // check if greetings are present in present
        foreach ( $greetingParams as $greetingValues ) {
            if ( array_key_exists( "{$key}{$greeting}{$greetingValues}", $params ) ) {
                $formatParams = true;
                break;
            }
        }

        if ( !$formatParams ) continue;
    
        // format params
        if ( CRM_Utils_Array::value( 'contact_type', $params ) == 'Organization' && $key != 'addressee' ) {
            return civicrm_create_error( ts( 'You cannot use email/postal greetings for contact type %1.', 
                                             array( 1 => $params['contact_type'] ) ) );
        }
        
        $nullValue      = false; 
        $filter         = array( 'contact_type'  => $params['contact_type'],
                                 'greeting_type' => "{$key}{$greeting}" );
        
        $greetings      = CRM_Core_PseudoConstant::greeting( $filter );
        $greetingId     = CRM_Utils_Array::value( "{$key}{$greeting}_id",     $params );
        $greetingVal    = CRM_Utils_Array::value( "{$key}{$greeting}",        $params );
        $customGreeting = CRM_Utils_Array::value( "{$key}{$greeting}_custom", $params );
        
        if ( !$greetingId && $greetingVal ) {
            $params["{$key}{$greeting}_id"] = CRM_Utils_Array::key( $params["{$key}{$greeting}"], $greetings );
        }
        
        if ( $customGreeting && $greetingId &&
             ( $greetingId != array_search( 'Customized', $greetings ) ) ) {
            return civicrm_create_error( ts( 'Provide either %1 greeting id and/or %1 greeting or custom %1 greeting',
                                             array( 1 => $key ) ) );
        }
        
        if ( $greetingVal && $greetingId &&
             ( $greetingId != CRM_Utils_Array::key( $greetingVal, $greetings ) ) ) {
            return civicrm_create_error( ts( 'Mismatch in %1 greeting id and %1 greeting',
                                             array( 1 => $key ) ) );
        } 
        
        if ( $greetingId ) {

            if ( !array_key_exists( $greetingId, $greetings ) ) {
                return civicrm_create_error( ts( 'Invalid %1 greeting Id', array( 1 => $key ) ) );
            }
            
            if ( !$customGreeting && ( $greetingId == array_search( 'Customized', $greetings ) ) ) {
                return civicrm_create_error( ts( 'Please provide a custom value for %1 greeting', 
                                                 array( 1 => $key ) ) );
            }
                        
        } else if ( $greetingVal ) {

            if ( !in_array( $greetingVal, $greetings ) ) {
                return civicrm_create_error( ts( 'Invalid %1 greeting', array( 1 => $key ) ) );
            }

            $greetingId = CRM_Utils_Array::key( $greetingVal, $greetings );
        }
                     
        if ( $customGreeting ) {
            $greetingId = CRM_Utils_Array::key( 'Customized', $greetings );
        }

        $customValue = $params['contact_id'] ? CRM_Core_DAO::getFieldValue( 'CRM_Contact_DAO_Contact', 
                                                                            $params['contact_id'], 
                                                                            "{$key}{$greeting}_custom" ) : false;
                
        if ( array_key_exists( "{$key}{$greeting}_id", $params ) && empty( $params["{$key}{$greeting}_id"] ) ) {
            $nullValue = true;
        } else if ( array_key_exists( "{$key}{$greeting}", $params ) && empty( $params["{$key}{$greeting}"] ) ) {
            $nullValue = true;
        } else if ( $customValue && array_key_exists( "{$key}{$greeting}_custom", $params ) 
                    && empty( $params["{$key}{$greeting}_custom"] ) ) {
//.........这里部分代码省略.........
开发者ID:ryanrd,项目名称:DW-Campaigns,代码行数:101,代码来源:Contact.php

示例15: 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}'";
//.........这里部分代码省略.........
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:101,代码来源:Contact.php


注:本文中的CRM_Core_PseudoConstant::greeting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。