本文整理汇总了PHP中CRM_Core_BAO_Preferences类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Preferences类的具体用法?PHP CRM_Core_BAO_Preferences怎么用?PHP CRM_Core_BAO_Preferences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_BAO_Preferences类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaultValues
/**
* This function sets the default values for the form.
* default values are retrieved from the database
*
* @access public
* @return None
*/
function setDefaultValues()
{
if (!$this->_defaults) {
$this->_defaults = array();
$formArray = array('Component', 'Localization');
$formMode = false;
if (in_array($this->_name, $formArray)) {
$formMode = true;
}
require_once "CRM/Core/BAO/Setting.php";
CRM_Core_BAO_Setting::retrieve($this->_defaults);
require_once "CRM/Core/Config/Defaults.php";
CRM_Core_Config_Defaults::setValues($this->_defaults, $formMode);
require_once "CRM/Core/OptionGroup.php";
$list = array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options', false, false, true, null, 'name'));
require_once "CRM/Core/BAO/Preferences.php";
$listEnabled = CRM_Core_BAO_Preferences::valueOptions('contact_autocomplete_options');
$autoSearchFields = array();
if (!empty($list) && !empty($listEnabled)) {
$autoSearchFields = array_combine($list, $listEnabled);
}
//Set sort_name for default
$this->_defaults['autocompleteContactSearch'] = array('1' => 1) + $autoSearchFields;
}
return $this->_defaults;
}
示例2: buildQuickForm
/**
* build form for address input fields
*
* @param object $form - CRM_Core_Form (or subclass)
* @param array reference $location - location array
* @param int $locationId - location id whose block needs to be built.
* @return none
*
* @access public
* @static
*/
static function buildQuickForm(&$form)
{
$blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
$config =& CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->applyFilter('__ALL__', 'trim');
$js = array('onChange' => 'checkLocation( this.id );');
$form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js);
$js = array('id' => "Address_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
$js = array('id' => "Address_" . $blockId . "_IsBilling", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], null), 'street_address' => array(ts('Street Address'), $attributes['street_address'], null), 'supplemental_address_1' => array(ts('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), null));
$stateCountryMap = array();
foreach ($elements as $name => $v) {
list($title, $attributes, $select) = $v;
$nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name;
if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
continue;
}
if (!$attributes) {
$attributes = $attributes[$name];
}
//build normal select if country is not present in address block
if ($name == 'state_province_id' && !$addressOptions['country']) {
$select = 'stateProvince';
}
if (!$select) {
if ($name == 'country_id' || $name == 'state_province_id') {
if ($name == 'country_id') {
$stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
} else {
$stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
if ($countryDefault) {
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
} else {
$selectOptions = array('' => ts('- select a country -'));
}
}
$form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
} else {
if ($name == 'address_name') {
$name = "name";
}
$form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
}
} else {
$form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
}
}
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
}
示例3: getContactList
static function getContactList(&$config)
{
require_once 'CRM/Core/BAO/Preferences.php';
$name = CRM_Utils_Type::escape($_GET['s'], 'String');
$limit = '10';
$list = array_keys(CRM_Core_BAO_Preferences::valueOptions('contact_autocomplete_options'), '1');
$select = array('sort_name');
$where = '';
$from = array();
foreach ($list as $value) {
$suffix = substr($value, 0, 2) . substr($value, -1);
switch ($value) {
case 'street_address':
case 'city':
$selectText = $value;
$value = "address";
$suffix = 'sts';
case 'phone':
case 'email':
$select[] = $value == 'address' ? $selectText : $value;
$from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) ";
break;
case 'country':
case 'state_province':
$select[] = "{$suffix}.name";
if (!in_array('address', $from)) {
$from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) ';
}
$from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id ) ";
break;
}
}
$select = implode(', ', $select);
$from = implode(' ', $from);
if (CRM_Utils_Array::value('limit', $_GET)) {
$limit = CRM_Utils_Type::escape($_GET['limit'], 'Positive');
}
// add acl clause here
require_once 'CRM/Contact/BAO/Contact/Permission.php';
list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
if ($aclWhere) {
$where .= " AND {$aclWhere} ";
}
$query = "\nSELECT DISTINCT(cc.id) as id, CONCAT_WS( ' :: ', {$select} ) as data\nFROM civicrm_contact cc {$from}\n{$aclFrom}\nWHERE sort_name LIKE '%{$name}%' {$where} \nORDER BY sort_name\nLIMIT 0, {$limit}\n";
// send query to hook to be modified if needed
require_once 'CRM/Utils/Hook.php';
CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Array::value('context', $_GET), CRM_Utils_Array::value('id', $_GET));
$dao = CRM_Core_DAO::executeQuery($query);
$contactList = null;
while ($dao->fetch()) {
echo $contactList = "{$dao->data}|{$dao->id}\n";
}
exit;
}
示例4: checkAddress
static function checkAddress(&$values)
{
if (!isset($values['street_address']) || !isset($values['city']) && !isset($values['state_province']) && !isset($values['postal_code'])) {
return false;
}
require_once 'CRM/Core/BAO/Preferences.php';
$userID = CRM_Core_BAO_Preferences::value('address_standardization_userid');
$url = CRM_Core_BAO_Preferences::value('address_standardization_url');
if (empty($userID) || empty($url)) {
return false;
}
$address2 = str_replace(',', '', $values['street_address']);
$XMLQuery = '<AddressValidateRequest USERID="' . $userID . '"><Address ID="0"><Address1>' . $values['supplemental_address_1'] . '</Address1><Address2>' . $address2 . '</Address2><City>' . $values['city'] . '</City><State>' . $values['state_province'] . '</State><Zip5>' . $values['postal_code'] . '</Zip5><Zip4>' . $values['postal_code_suffix'] . '</Zip4></Address></AddressValidateRequest>';
require_once 'HTTP/Request.php';
$request =& new HTTP_Request();
$request->setURL($url);
$request->addQueryString('API', 'Verify');
$request->addQueryString('XML', $XMLQuery);
$response = $request->sendRequest();
$session =& CRM_Core_Session::singleton();
$code = $request->getResponseCode();
if ($code != 200) {
$session->setStatus(ts('USPS Address Lookup Failed with HTTP status code: $code'));
return false;
}
$responseBody = $request->getResponseBody();
$xml = simplexml_load_string($responseBody);
if (is_null($xml) || is_null($xml->Address)) {
$session->setStatus(ts('Your USPS API Lookup has Failed.'));
return false;
}
if ($xml->Number == '80040b1a') {
$session->setStatus(ts('Your USPS API Authorization has Failed.'));
return false;
}
if (array_key_exists('Error', $xml->Address)) {
$session->setStatus(ts('Address not found in USPS database.'));
return false;
}
$values['street_address'] = (string) $xml->Address->Address2;
$values['city'] = (string) $xml->Address->City;
$values['state_province'] = (string) $xml->Address->State;
$values['postal_code'] = (string) $xml->Address->Zip5;
$values['postal_code_suffix'] = (string) $xml->Address->Zip4;
if (array_key_exists('Address1', $xml->Address)) {
$values['supplemental_address_1'] = (string) $xml->Address->Address1;
}
return true;
}
示例5: preProcess
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/
function preProcess()
{
/*
* initialize the task and row fields
*/
parent::preProcess();
//get the contact read only fields to display.
require_once 'CRM/Core/BAO/Preferences.php';
$readOnlyFields = array_merge(array('sort_name' => ts('Name')), CRM_Core_BAO_Preferences::valueOptions('contact_autocomplete_options', true, null, false, 'name', true));
//get the read only field data.
$returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
require_once 'CRM/Contact/BAO/Contact/Utils.php';
$contactDetails = CRM_Contact_BAO_Contact_Utils::contactDetails($this->_contributionIds, 'CiviContribute', $returnProperties);
$this->assign('contactDetails', $contactDetails);
$this->assign('readOnlyFields', $readOnlyFields);
}
示例6: buildQuickForm
/**
* Build the form
*
* @access public
* @return void
*/
function buildQuickForm()
{
// text for sort_name or email criteria
$this->add('text', 'sort_name', ts('Name or Email'));
require_once 'CRM/Core/BAO/Preferences.php';
$searchOptions = CRM_Core_BAO_Preferences::valueOptions('advanced_search_options');
if (CRM_Utils_Array::value('contactType', $searchOptions)) {
require_once 'CRM/Contact/BAO/ContactType.php';
$contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements();
$this->add('select', 'contact_type', ts('is...'), $contactTypes);
}
if (CRM_Utils_Array::value('groups', $searchOptions)) {
$config = CRM_Core_Config::singleton();
if ($config->groupTree) {
$this->add('hidden', 'group', null, array('id' => 'group'));
$group = CRM_Utils_Array::value('group', $this->_formValues);
$selectedGroups = explode(',', $group);
if (is_array($selectedGroups)) {
$groupNames = null;
$groupIds = array();
foreach ($selectedGroups as $groupId) {
if ($groupNames) {
$groupNames .= '<br/>';
}
$groupNames .= $this->_group[$groupId];
}
$groupIds[] = $groupId;
}
$this->assign('groupIds', implode(',', $groupIds));
$this->assign('groupNames', $groupNames);
} else {
// add select for groups
$group = array('' => ts('- any group -')) + $this->_group;
$this->_groupElement =& $this->addElement('select', 'group', ts('in'), $group);
}
}
if (CRM_Utils_Array::value('tags', $searchOptions)) {
// tag criteria
if (!empty($this->_tag)) {
$tag = array('' => ts('- any tag -')) + $this->_tag;
$this->_tagElement =& $this->addElement('select', 'tag', ts('with'), $tag);
}
}
parent::buildQuickForm();
}
示例7: browse
/**
* Browse all activities for a particular contact
*
* @return none
*
* @access public
*/
function browse()
{
require_once 'CRM/Core/Selector/Controller.php';
$output = CRM_Core_Selector_Controller::SESSION;
require_once 'CRM/Activity/Selector/Activity.php';
$selector =& new CRM_Activity_Selector_Activity($this->_contactId, $this->_permission);
$sortID = null;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION));
}
$controller =& new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, $output);
$controller->setEmbedded(true);
$controller->run();
$controller->moveFromSessionToTemplate();
// check if case is enabled
require_once 'CRM/Core/BAO/Preferences.php';
$viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true, null, true);
$enableCase = false;
if (CRM_Utils_Array::value('CiviCase', $viewOptions)) {
$enableCase = true;
}
$this->assign('enableCase', $enableCase);
$this->assign('context', 'activity');
}
示例8: fixAndStoreDirAndURL
/**
* @param $params
*/
static function fixAndStoreDirAndURL(&$params)
{
$sql = "\nSELECT v.name as valueName, g.name as optionName\nFROM civicrm_option_value v,\n civicrm_option_group g\nWHERE ( g.name = 'directory_preferences'\nOR g.name = 'url_preferences' )\nAND v.option_group_id = g.id\nAND v.is_active = 1\n";
$dirParams = array();
$urlParams = array();
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
if (!isset($params[$dao->valueName])) {
continue;
}
if ($dao->optionName == 'directory_preferences') {
$dirParams[$dao->valueName] = CRM_Utils_Array::value($dao->valueName, $params, '');
} else {
$urlParams[$dao->valueName] = CRM_Utils_Array::value($dao->valueName, $params, '');
}
unset($params[$dao->valueName]);
}
if (!empty($dirParams)) {
CRM_Core_BAO_Preferences::storeDirectoryOrURLPreferences($dirParams, 'directory');
}
if (!empty($urlParams)) {
CRM_Core_BAO_Preferences::storeDirectoryOrURLPreferences($urlParams, 'url');
}
}
示例9: browse
/**
* Browse all activities for a particular contact
*
* @return none
*
* @access public
*/
function browse($contactId, $admin)
{
$config =& CRM_Core_Config::singleton();
if (!$config->civiHRD) {
require_once 'CRM/Core/Selector/Controller.php';
$output = CRM_Core_Selector_Controller::SESSION;
require_once 'CRM/Activity/Selector/Activity.php';
$selector =& new CRM_Activity_Selector_Activity($contactId, $this->_permission, $admin, 'home');
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION));
$controller =& new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, $output);
$controller->setEmbedded(true);
$controller->run();
$controller->moveFromSessionToTemplate();
$displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'display_name');
$this->assign('contactId', $contactId);
$this->assign('display_name', $displayName);
$this->assign('context', 'home');
// check if case is enabled
require_once 'CRM/Core/BAO/Preferences.php';
$viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true, null, true);
$enableCase = false;
if ($viewOptions[ts('CiviCase')]) {
$enableCase = true;
}
$this->assign('enableCase', $enableCase);
}
}
示例10: buildProfile
/**
* Function to build profile form
*
* @params object $form form object
* @params array $field array field properties
* @params int $mode profile mode
* @params int $contactID contact id
*
* @return null
* @static
* @access public
*/
static function buildProfile(&$form, &$field, $mode, $contactId = null, $online = false)
{
require_once "CRM/Profile/Form.php";
require_once "CRM/Core/OptionGroup.php";
require_once 'CRM/Core/BAO/UFField.php';
require_once 'CRM/Contact/BAO/ContactType.php';
$defaultValues = array();
$fieldName = $field['name'];
$title = $field['title'];
$attributes = $field['attributes'];
$rule = $field['rule'];
$view = $field['is_view'];
$required = $mode == CRM_Profile_Form::MODE_SEARCH ? false : $field['is_required'];
$search = $mode == CRM_Profile_Form::MODE_SEARCH ? true : false;
// do not display view fields in drupal registration form
// CRM-4632
if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
return;
}
if ($contactId && !$online) {
$name = "field[{$contactId}][{$fieldName}]";
} else {
$name = $fieldName;
}
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
if (substr($fieldName, 0, 14) === 'state_province') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
} else {
if (substr($fieldName, 0, 7) === 'country') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
$config =& CRM_Core_Config::singleton();
if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
$defaultValues[$name] = $config->defaultContactCountry;
$form->setDefaults($defaultValues);
}
} else {
if (substr($fieldName, 0, 6) === 'county') {
if ($addressOptions['county']) {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(), $required);
}
} else {
if (substr($fieldName, 0, 2) === 'im') {
if (!$contactId) {
$form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
$form->freeze($name . "-provider_id");
}
}
$form->add('text', $name, $title, $attributes, $required);
} else {
if ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
$form->addDate($name, $title, $required, array('formatType' => 'birth'));
} else {
if (in_array($fieldName, array("membership_start_date", "membership_end_date", "join_date"))) {
$form->addDate($name, $title, $required, array('formatType' => 'custom'));
} else {
if ($field['name'] == 'membership_type_id') {
require_once 'CRM/Member/PseudoConstant.php';
$form->add('select', 'membership_type_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipType(), $required);
} else {
if ($field['name'] == 'status_id') {
require_once 'CRM/Member/PseudoConstant.php';
$form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(), $required);
} else {
if ($fieldName === 'gender') {
$genderOptions = array();
$gender = CRM_Core_PseudoConstant::gender();
foreach ($gender as $key => $var) {
$genderOptions[$key] = HTML_QuickForm::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');
}
} else {
if ($fieldName === 'individual_prefix') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
} else {
if ($fieldName === 'individual_suffix') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
} else {
if ($fieldName === 'contact_sub_type') {
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
$profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : null;
$setSubtype = false;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$setSubtype = $profileType;
//.........这里部分代码省略.........
示例11: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return void
*/
public function postProcess()
{
$fv = $this->controller->exportValues($this->_name);
$config =& CRM_Core_Config::singleton();
$locName = null;
//get the address format sequence from the config file
require_once 'CRM/Core/BAO/Preferences.php';
$sequence = CRM_Core_BAO_Preferences::value('mailing_sequence');
foreach ($sequence as $v) {
$address[$v] = 1;
}
if (array_key_exists('postal_code', $address)) {
$address['postal_code_suffix'] = 1;
}
//build the returnproperties
$returnProperties = array('display_name' => 1);
$mailingFormat = CRM_Core_BAO_Preferences::value('mailing_format');
$mailingFormatProperties = array();
if ($mailingFormat) {
$mailingFormatProperties = self::getReturnProperties($mailingFormat);
$returnProperties = array_merge($returnProperties, $mailingFormatProperties);
}
$customFormatProperties = array();
if (stristr($mailingFormat, 'custom_')) {
foreach ($mailingFormatProperties as $token => $true) {
if (substr($token, 0, 7) == 'custom_') {
if (!CRM_Utils_Array::value($token, $customFormatProperties)) {
$customFormatProperties[$token] = $mailingFormatProperties[$token];
}
}
}
}
if (!empty($customFormatProperties)) {
$returnProperties = array_merge($returnProperties, $customFormatProperties);
}
//get the contacts information
$params = array();
if (CRM_Utils_Array::value('location_type_id', $fv)) {
$locType = CRM_Core_PseudoConstant::locationType();
$locName = $locType[$fv['location_type_id']];
$location = array('location' => array("{$locName}" => $address));
$returnProperties = array_merge($returnProperties, $location);
$params[] = array('location_type', '=', array($fv['location_type_id'] => 1), 0, 0);
} else {
$returnProperties = array_merge($returnProperties, $address);
}
$rows = array();
foreach ($this->_contactIds as $key => $contactID) {
$params[] = array(CRM_Core_Form::CB_PREFIX . $contactID, '=', 1, 0, 0);
}
// fix for CRM-2651
if (CRM_Utils_Array::value('do_not_mail', $fv)) {
$params[] = array('do_not_mail', '=', 0, 0, 0);
}
// fix for CRM-2613
$params[] = array('is_deceased', '=', 0, 0, 0);
$custom = array();
foreach ($returnProperties as $name => $dontCare) {
$cfID = CRM_Core_BAO_CustomField::getKeyID($name);
if ($cfID) {
$custom[] = $cfID;
}
}
//get the total number of contacts to fetch from database.
$numberofContacts = count($this->_contactIds);
require_once 'CRM/Contact/BAO/Query.php';
$query =& new CRM_Contact_BAO_Query($params, $returnProperties);
$details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);
// also get all token values
require_once 'CRM/Utils/Hook.php';
CRM_Utils_Hook::tokenValues($details[0], $this->_contactIds);
$tokens = array();
CRM_Utils_Hook::tokens($tokens);
$tokenFields = array();
foreach ($tokens as $category => $catTokens) {
foreach ($catTokens as $token) {
$tokenFields[] = $token;
}
}
foreach ($this->_contactIds as $value) {
foreach ($custom as $cfID) {
if (isset($details[0][$value]["custom_{$cfID}"])) {
$details[0][$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::getDisplayValue($details[0][$value]["custom_{$cfID}"], $cfID, $details[1]);
}
}
$contact = CRM_Utils_Array::value($value, $details['0']);
if (is_a($contact, 'CRM_Core_Error')) {
return null;
}
// we need to remove all the "_id"
unset($contact['contact_id']);
if ($locName && CRM_Utils_Array::value($locName, $contact)) {
// If location type is not primary, $contact contains
// one more array as "$contact[$locName] = array( values... )"
//.........这里部分代码省略.........
示例12: buildQuickForm
/**
* Function to actually build the form
*
* @return void
* @access public
*/
public function buildQuickForm()
{
if ($this->_action & CRM_Core_Action::DELETE) {
$this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
return;
}
if (isset($this->_id)) {
$params = array('id' => $this->_id);
CRM_Core_BAO_UFField::retrieve($params, $defaults);
// set it to null if so (avoids crappy E_NOTICE errors below
$defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
$specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name');
if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) {
$defaults['location_type_id'] = 0;
}
$defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
$this->_gid = $defaults['uf_group_id'];
} else {
$defaults['is_active'] = 1;
}
if ($this->_action & CRM_Core_Action::ADD) {
$fieldValues = array('uf_group_id' => $this->_gid);
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
}
// lets trim all the whitespace
$this->applyFilter('__ALL__', 'trim');
//hidden field to catch the group id in profile
$this->add('hidden', 'group_id', $this->_gid);
//hidden field to catch the field id in profile
$this->add('hidden', 'field_id', $this->_id);
$fields = array();
$fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true);
$fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true);
$fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true);
// add current employer for individuals
$fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
// unset unwanted fields
$unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id');
foreach ($unsetFieldArray as $value) {
unset($fields['Individual'][$value]);
unset($fields['Household'][$value]);
unset($fields['Organization'][$value]);
}
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
if (!$addressOptions['county']) {
unset($fields['Individual']['county']);
unset($fields['Household']['county']);
unset($fields['Organization']['county']);
}
//build the common contact fields array CRM-3037.
foreach ($fields['Individual'] as $key => $value) {
if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) {
$fields['Contact'][$key] = $value;
//as we move common fields to contacts. There fore these fields
//are unset from resoective array's.
unset($fields['Individual'][$key]);
unset($fields['Household'][$key]);
unset($fields['Organization'][$key]);
}
}
// add current employer for individuals
$fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID'));
unset($fields['Contact']['contact_type']);
// since we need a hierarchical list to display contact types & subtypes,
// this is what we going to display in first selector
$contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false);
unset($contactTypes['']);
// include Subtypes For Profile
$subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
foreach ($subTypes as $name => $val) {
//custom fields for sub type
$subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name);
if (array_key_exists($val['parent'], $fields)) {
$fields[$name] = $fields[$val['parent']] + $subTypeFields;
} else {
$fields[$name] = $subTypeFields;
}
}
unset($subTypes);
if (CRM_Core_Permission::access('Quest')) {
require_once 'CRM/Quest/BAO/Student.php';
$fields['Student'] =& CRM_Quest_BAO_Student::exportableFields();
}
if (CRM_Core_Permission::access('CiviContribute')) {
$contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
if (!empty($contribFields)) {
unset($contribFields['is_test']);
unset($contribFields['is_pay_later']);
unset($contribFields['contribution_id']);
$fields['Contribution'] =& $contribFields;
}
}
if (CRM_Core_Permission::access('CiviEvent')) {
//.........这里部分代码省略.........
示例13: view
/**
* View summary details of a contact
*
* @return void
* @access public
*/
function view()
{
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
$session->pushUserContext($url);
$params = array();
$defaults = array();
$ids = array();
$params['id'] = $params['contact_id'] = $this->_contactId;
$params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = true;
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true);
$communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'website' => array('type' => 'websiteType', 'id' => 'website_type'), 'address' => array('skip' => true, 'customData' => 1), 'email' => array('skip' => true), 'openid' => array('skip' => true));
foreach ($communicationType as $key => $value) {
if (CRM_Utils_Array::value($key, $defaults)) {
foreach ($defaults[$key] as &$val) {
CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false);
if (!CRM_Utils_Array::value('skip', $value)) {
eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );');
CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false);
}
}
if (isset($value['customData'])) {
foreach ($defaults[$key] as $blockId => $blockVal) {
$groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $blockVal['id']);
// we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
$defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, false, null, "dnc_");
}
// reset template variable since that won't be of any use, and could be misleading
$this->assign("dnc_viewCustomData", null);
}
}
}
if (CRM_Utils_Array::value('gender_id', $defaults)) {
$gender = CRM_Core_PseudoConstant::gender();
$defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
}
// to make contact type label available in the template -
$contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type'];
$defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(true, $contactType);
// get contact tags
require_once 'CRM/Core/BAO/EntityTag.php';
$contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
if (!empty($contactTags)) {
$defaults['contactTag'] = implode(', ', $contactTags);
}
$defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
//Show blocks only if they are visible in edit form
require_once 'CRM/Core/BAO/Preferences.php';
$this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options');
$configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes');
foreach ($configItems as $c => $t) {
$varName = '_show' . $c;
$this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions);
$this->assign(substr($varName, 1), $this->{$varName});
}
// get contact name of shared contact names
$sharedAddresses = array();
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
foreach ($defaults['address'] as $key => $addressValue) {
if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
$sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
}
}
$this->assign('sharedAddresses', $sharedAddresses);
//get the current employer name
if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
if ($contact->employer_id && $contact->organization_name) {
$defaults['current_employer'] = $contact->organization_name;
$defaults['current_employer_id'] = $contact->employer_id;
}
//for birthdate format with respect to birth format set
$this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
}
$this->assign($defaults);
// also assign the last modifed details
require_once 'CRM/Core/BAO/Log.php';
$lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
$this->assign_by_ref('lastModified', $lastModified);
$allTabs = array();
$weight = 10;
$this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true);
$changeLog = $this->_viewOptions['log'];
$this->assign_by_ref('changeLog', $changeLog);
require_once 'CRM/Core/Component.php';
$components = CRM_Core_Component::getEnabledComponents();
foreach ($components as $name => $component) {
if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) {
$elem = $component->registerTab();
// FIXME: not very elegant, probably needs better approach
// allow explicit id, if not defined, use keyword instead
if (array_key_exists('id', $elem)) {
$i = $elem['id'];
} else {
$i = $component->getKeyword();
//.........这里部分代码省略.........
示例14: maxLocations
/**
* Function to get the count of contact loctions
*
* @param int $contactId contact id
*
* @return int $locationCount max locations for the contact
* @static
* @access public
*/
static function maxLocations($contactId)
{
// find the system config related location blocks
require_once 'CRM/Core/BAO/Preferences.php';
$locationCount = CRM_Core_BAO_Preferences::value('location_count');
$contactLocations = array();
// find number of location blocks for this contact and adjust value accordinly
// get location type from email
$query = "\n( SELECT location_type_id FROM civicrm_email WHERE contact_id = {$contactId} )\nUNION\n( SELECT location_type_id FROM civicrm_phone WHERE contact_id = {$contactId} )\nUNION\n( SELECT location_type_id FROM civicrm_im WHERE contact_id = {$contactId} )\nUNION\n( SELECT location_type_id FROM civicrm_address WHERE contact_id = {$contactId} )\n";
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
$locCount = $dao->N;
if ($locCount && $locationCount < $locCount) {
$locationCount = $locCount;
}
return $locationCount;
}
示例15: getContactList
static function getContactList(&$config)
{
require_once 'CRM/Core/BAO/Preferences.php';
$name = CRM_Utils_Array::value('s', $_GET);
$name = CRM_Utils_Type::escape($name, 'String');
$limit = '10';
$list = array_keys(CRM_Core_BAO_Preferences::valueOptions('contact_autocomplete_options'), '1');
$select = array('sort_name');
$where = '';
$from = array();
foreach ($list as $value) {
$suffix = substr($value, 0, 2) . substr($value, -1);
switch ($value) {
case 'street_address':
case 'city':
$selectText = $value;
$value = "address";
$suffix = 'sts';
case 'phone':
case 'email':
$select[] = $value == 'address' ? $selectText : $value;
$from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) ";
break;
case 'country':
case 'state_province':
$select[] = "{$suffix}.name";
if (!in_array('address', $from)) {
$from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) ';
}
$from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id ) ";
break;
}
}
$select = implode(', ', $select);
$from = implode(' ', $from);
if (CRM_Utils_Array::value('limit', $_GET)) {
$limit = CRM_Utils_Type::escape($_GET['limit'], 'Positive');
}
// add acl clause here
require_once 'CRM/Contact/BAO/Contact/Permission.php';
list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
if ($aclWhere) {
$where .= " AND {$aclWhere} ";
}
if (CRM_Utils_Array::value('org', $_GET)) {
$where .= " AND contact_type = \"Organization\"";
//set default for current_employer
if ($orgId = CRM_Utils_Array::value('id', $_GET)) {
$where .= " AND cc.id = {$orgId}";
}
}
//contact's based of relationhip type
$relType = null;
if (isset($_GET['rel'])) {
$relation = explode('_', $_GET['rel']);
$relType = CRM_Utils_Type::escape($relation[0], 'Integer');
$rel = CRM_Utils_Type::escape($relation[2], 'String');
}
$config =& CRM_Core_Config::singleton();
if ($config->includeWildCardInName) {
$strSearch = "%{$name}%";
} else {
$strSearch = "{$name}%";
}
$whereClause = " WHERE sort_name LIKE '{$strSearch}' {$where} ";
$additionalFrom = '';
if ($relType) {
$additionalFrom = "\n INNER JOIN civicrm_relationship_type r ON ( \n r.id = {$relType}\n AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL )\n AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL )\n )";
}
$query = "\nSELECT DISTINCT(cc.id) as id, CONCAT_WS( ' :: ', {$select} ) as data\nFROM civicrm_contact cc {$from}\n{$aclFrom}\n{$additionalFrom}\n{$whereClause} \nORDER BY sort_name\nLIMIT 0, {$limit}\n";
// send query to hook to be modified if needed
require_once 'CRM/Utils/Hook.php';
CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Array::value('context', $_GET), CRM_Utils_Array::value('id', $_GET));
$dao = CRM_Core_DAO::executeQuery($query);
$contactList = null;
while ($dao->fetch()) {
echo $contactList = "{$dao->data}|{$dao->id}\n";
}
//return organization name if doesn't exist in db
if (!$contactList) {
if (CRM_Utils_Array::value('org', $_GET)) {
echo CRM_Utils_Array::value('s', $_GET);
} else {
if (CRM_Utils_Array::value('context', $_GET) == 'customfield') {
echo "{$name}|{$name}\n";
}
}
}
exit;
}