本文整理汇总了PHP中CRM_Core_BAO_Preferences::valueOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Preferences::valueOptions方法的具体用法?PHP CRM_Core_BAO_Preferences::valueOptions怎么用?PHP CRM_Core_BAO_Preferences::valueOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Preferences
的用法示例。
在下文中一共展示了CRM_Core_BAO_Preferences::valueOptions方法的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: 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);
}
示例5: 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();
}
示例6: 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');
}
示例7: getLocBlock
function getLocBlock()
{
// i wish i could retrieve loc block info based on loc_block_id,
// Anyway, lets retrieve an event which has loc_block_id set to 'lbid'.
if ($_POST['lbid']) {
$params = array('1' => array($_POST['lbid'], 'Integer'));
$eventId = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_event WHERE loc_block_id=%1 LIMIT 1', $params);
}
// now lets use the event-id obtained above, to retrieve loc block information.
if ($eventId) {
$params = array('entity_id' => $eventId, 'entity_table' => 'civicrm_event');
require_once 'CRM/Core/BAO/Location.php';
// second parameter is of no use, but since required, lets use the same variable.
$location = CRM_Core_BAO_Location::getValues($params, $params);
}
$result = array();
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
// lets output only required fields.
foreach ($addressOptions as $element => $isSet) {
if ($isSet && !in_array($element, array('im', 'openid'))) {
if (in_array($element, array('country', 'state_province', 'county'))) {
$element .= '_id';
} else {
if ($element == 'address_name') {
$element = 'name';
}
}
$fld = "address[1][{$element}]";
$value = CRM_Utils_Array::value($element, $location['address'][1]);
$value = $value ? $value : "";
$result[str_replace(array('][', '[', "]"), array('_', '_', ''), $fld)] = $value;
}
}
foreach (array('email', 'phone_type_id', 'phone') as $element) {
$block = $element == 'phone_type_id' ? 'phone' : $element;
for ($i = 1; $i < 3; $i++) {
$fld = "{$block}[{$i}][{$element}]";
$value = CRM_Utils_Array::value($element, $location[$block][$i]);
$value = $value ? $value : "";
$result[str_replace(array('][', '[', "]"), array('_', '_', ''), $fld)] = $value;
}
}
// set the message if loc block is being used by more than one event.
require_once 'CRM/Event/BAO/Event.php';
$result['count_loc_used'] = CRM_Event_BAO_Event::countEventsUsingLocBlockId($_POST['lbid']);
echo json_encode($result);
exit;
}
示例8: validateAddressOptions
/**
* Validate the address fields based on the address options enabled
* in the Address Settings
*
* @param array $fields an array of importable/exportable contact fields
*
* @return array $fields an array of contact fields and only the enabled address options
* @access public
* @static
*/
function validateAddressOptions($fields)
{
static $addressOptions = null;
if (!$addressOptions) {
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
}
if (is_array($fields) && !empty($fields)) {
foreach ($addressOptions as $key => $value) {
if (!$value && isset($fields[$key])) {
unset($fields[$key]);
}
}
}
return $fields;
}
示例9: 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;
//.........这里部分代码省略.........
示例10: 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();
//.........这里部分代码省略.........
示例11: 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')) {
//.........这里部分代码省略.........
示例12: run
function run()
{
session_start();
require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton();
require_once 'Console/Getopt.php';
$shortOptions = "n:p:s:e:k:g:parse";
$longOptions = array('name=', 'pass=', 'key=', 'start=', 'end=', 'geocoding=', 'parse=');
$getopt = new Console_Getopt();
$args = $getopt->readPHPArgv();
array_shift($args);
list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
$vars = array('start' => 's', 'end' => 'e', 'name' => 'n', 'pass' => 'p', 'key' => 'k', 'geocoding' => 'g', 'parse' => 'ap');
foreach ($vars as $var => $short) {
${$var} = null;
foreach ($valid as $v) {
if ($v[0] == $short || $v[0] == "--{$var}") {
${$var} = $v[1];
break;
}
}
if (!${$var}) {
${$var} = CRM_Utils_Array::value($var, $_REQUEST);
}
$_REQUEST[$var] = ${$var};
}
// this does not return on failure
// require_once 'CRM/Utils/System.php';
CRM_Utils_System::authenticateScript(true, $name, $pass);
// do check for geocoding.
$processGeocode = false;
if (empty($config->geocodeMethod)) {
if ($geocoding == 'true') {
echo ts('Error: You need to set a mapping provider under Global Settings');
exit;
}
} else {
$processGeocode = true;
// user might want to over-ride.
if ($geocoding == 'false') {
$processGeocode = false;
}
}
// do check for parse street address.
require_once 'CRM/Core/BAO/Preferences.php';
$parseAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Preferences::valueOptions('address_options'), false);
$parseStreetAddress = false;
if (!$parseAddress) {
if ($parse == 'true') {
echo ts('Error: You need to enable Street Address Parsing under Global Settings >> Address Settings.');
exit;
}
} else {
$parseStreetAddress = true;
// user might want to over-ride.
if ($parse == 'false') {
$parseStreetAddress = false;
}
}
// don't process.
if (!$parseStreetAddress && !$processGeocode) {
echo ts('Error: Both Geocode mapping as well as Street Address Parsing are disabled. You must configure one or both options to use this script.');
exit;
}
$config->userFramework = 'Soap';
$config->userFrameworkClass = 'CRM_Utils_System_Soap';
$config->userHookClass = 'CRM_Utils_Hook_Soap';
// we have an exclusive lock - run the mail queue
processContacts($config, $processGeocode, $parseStreetAddress, $start, $end);
}
示例13: buildUserDashBoard
/**
* Function to build user dashboard
*
* @return none
* @access public
*/
function buildUserDashBoard()
{
//build component selectors
$dashboardElements = array();
$config =& CRM_Core_Config::singleton();
require_once 'CRM/Core/BAO/Preferences.php';
$this->_userOptions = CRM_Core_BAO_Preferences::valueOptions('user_dashboard_options');
$components = CRM_Core_Component::getEnabledComponents();
foreach ($components as $name => $component) {
$elem = $component->getUserDashboardElement();
if (!$elem) {
continue;
}
if (CRM_Utils_Array::value($name, $this->_userOptions) && (CRM_Core_Permission::access($component->name) || CRM_Core_Permission::check($elem['perm'][0]))) {
$userDashboard = $component->getUserDashboardObject();
$dashboardElements[] = array('templatePath' => $userDashboard->getTemplateFileName(), 'sectionTitle' => $elem['title'], 'weight' => $elem['weight']);
$userDashboard->run();
}
}
$sectionName = 'Permissioned Orgs';
if ($this->_userOptions[$sectionName]) {
$dashboardElements[] = array('templatePath' => 'CRM/Contact/Page/View/Relationship.tpl', 'sectionTitle' => ts('Your Contacts / Organizations'), 'weight' => 40);
$links =& self::links();
$currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, $links, null, true);
$this->assign('currentRelationships', $currentRelationships);
}
if ($this->_userOptions['PCP']) {
require_once 'CRM/Contribute/BAO/PCP.php';
$dashboardElements[] = array('templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl', 'sectionTitle' => ts('Personal Campaign Pages'), 'weight' => 40);
list($pcpBlock, $pcpInfo) = CRM_Contribute_BAO_PCP::getPcpDashboardInfo($this->_contactId);
$this->assign('pcpBlock', $pcpBlock);
$this->assign('pcpInfo', $pcpInfo);
}
require_once 'CRM/Utils/Sort.php';
usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
$this->assign('dashboardElements', $dashboardElements);
if ($this->_userOptions['Groups']) {
$this->assign('showGroup', true);
//build group selector
require_once "CRM/Contact/Page/View/UserDashBoard/GroupContact.php";
$gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
$gContact->run();
} else {
$this->assign('showGroup', false);
}
}
示例14: formRule
/**
* global validation rules for the form
*
* @param array $fields posted values of the form
* @param array $errors list of errors to be posted back to the form
* @param int $contactId contact id if doing update.
*
* @return $primaryID emal/openId
* @static
* @access public
*/
static function formRule($fields, &$errors, $contactId = null)
{
$config = CRM_Core_Config::singleton();
// validations.
//1. for each block only single value can be marked as is_primary = true.
//2. location type id should be present if block data present.
//3. check open id across db and other each block for duplicate.
//4. at least one location should be primary.
//5. also get primaryID from email or open id block.
// take the location blocks.
$blocks = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options', true, null, false, 'name', true, 'AND v.filter = 1');
$otherEditOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options', true, null, false, 'name', true, 'AND v.filter = 0');
//get address block inside.
if (array_key_exists('Address', $otherEditOptions)) {
$blocks['Address'] = $otherEditOptions['Address'];
}
$openIds = array();
$primaryID = false;
foreach ($blocks as $name => $label) {
$hasData = $hasPrimary = array();
$name = strtolower($name);
if (CRM_Utils_Array::value($name, $fields) && is_array($fields[$name])) {
foreach ($fields[$name] as $instance => $blockValues) {
$dataExists = self::blockDataExists($blockValues);
if (!$dataExists && $name == 'address') {
$dataExists = CRM_Utils_Array::value('use_shared_address', $fields['address'][$instance]);
}
if ($dataExists) {
// skip remaining checks for website
if ($name == 'website') {
continue;
}
$hasData[] = $instance;
if (CRM_Utils_Array::value('is_primary', $blockValues)) {
$hasPrimary[] = $instance;
if (!$primaryID && in_array($name, array('email', 'openid')) && CRM_Utils_Array::value($name, $blockValues)) {
$primaryID = $blockValues[$name];
}
}
if (!CRM_Utils_Array::value('location_type_id', $blockValues)) {
$errors["{$name}[{$instance}][location_type_id]"] = ts('The Location Type should be set if there is %1 information.', array(1 => $label));
}
}
if ($name == 'openid' && CRM_Utils_Array::value($name, $blockValues)) {
require_once 'CRM/Core/DAO/OpenID.php';
$oid = new CRM_Core_DAO_OpenID();
$oid->openid = $openIds[$instance] = CRM_Utils_Array::value($name, $blockValues);
$cid = isset($contactId) ? $contactId : 0;
if ($oid->find(true) && $oid->contact_id != $cid) {
$errors["{$name}[{$instance}][openid]"] = ts('%1 already exist.', array(1 => $blocks['OpenID']));
}
}
}
if (empty($hasPrimary) && !empty($hasData)) {
$errors["{$name}[1][is_primary]"] = ts('One %1 should be marked as primary.', array(1 => $label));
}
if (count($hasPrimary) > 1) {
$errors["{$name}[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one %1 can be marked as primary.', array(1 => $label));
}
}
}
//do validations for all opend ids they should be distinct.
if (!empty($openIds) && count(array_unique($openIds)) != count($openIds)) {
foreach ($openIds as $instance => $value) {
if (!array_key_exists($instance, array_unique($openIds))) {
$errors["openid[{$instance}][openid]"] = ts('%1 already used.', array(1 => $blocks['OpenID']));
}
}
}
// street number should be digit + suffix, CRM-5450
$parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Preferences::valueOptions('address_options'));
if ($parseStreetAddress) {
if (is_array($fields['address'])) {
$invalidStreetNumbers = array();
foreach ($fields['address'] as $cnt => $address) {
if ($streetNumber = CRM_Utils_Array::value('street_number', $address)) {
$parsedAddress = CRM_Core_BAO_Address::parseStreetAddress($address['street_number']);
if (!CRM_Utils_Array::value('street_number', $parsedAddress)) {
$invalidStreetNumbers[] = $cnt;
}
}
}
if (!empty($invalidStreetNumbers)) {
$first = $invalidStreetNumbers[0];
foreach ($invalidStreetNumbers as &$num) {
$num = CRM_Contact_Form_Contact::ordinalNumber($num);
}
$errors["address[{$first}][street_number]"] = ts('The street number you entered for the %1 address block(s) is not in an expected format. Street numbers may include numeric digit(s) followed by other characters. You can still enter the complete street address (unparsed) by clicking "Edit Complete Street Address".', array(1 => implode(', ', $invalidStreetNumbers)));
}
//.........这里部分代码省略.........
示例15: location
static function location(&$form)
{
$form->addElement('hidden', 'hidden_location', 1);
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('street_address' => array(ts('Street Address'), $attributes['street_address'], null, null), 'city' => array(ts('City'), $attributes['city'], null, null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null, null), 'county' => array(ts('County'), $attributes['county_id'], 'county', false), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', true), 'country' => array(ts('Country'), $attributes['country_id'], 'country', false), 'address_name' => array(ts('Address Name'), $attributes['address_name'], null, null));
foreach ($elements as $name => $v) {
list($title, $attributes, $select, $multiSelect) = $v;
if (!$addressOptions[$name]) {
continue;
}
if (!$attributes) {
$attributes = $attributes[$name];
}
if ($select) {
$selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
$element = $form->addElement('select', $name, $title, $selectElements);
if ($multiSelect) {
$element->setMultiple(true);
}
} else {
$form->addElement('text', $name, $title, $attributes);
}
if ($addressOptions['postal_code']) {
$form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes));
$form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes));
}
// select for state province
$stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince();
}
$worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion();
$form->addElement('select', 'world_region', ts('World Region'), $worldRegions);
// checkboxes for location type
$location_type = array();
$locationType = CRM_Core_PseudoConstant::locationType();
foreach ($locationType as $locationTypeID => $locationTypeName) {
$location_type[] = HTML_QuickForm::createElement('checkbox', $locationTypeID, null, $locationTypeName);
}
$form->addGroup($location_type, 'location_type', ts('Location Types'), ' ');
}