本文整理汇总了PHP中CRM_Core_BAO_Address类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Address类的具体用法?PHP CRM_Core_BAO_Address怎么用?PHP CRM_Core_BAO_Address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_BAO_Address类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preProcess
/**
* Function to set variables up before form is built
*
* @return void
*/
function preProcess(&$form)
{
$form->_addBlockName = CRM_Utils_Request::retrieve('block', 'String', CRM_Core_DAO::$_nullObject);
$additionalblockCount = CRM_Utils_Request::retrieve('count', 'Positive', CRM_Core_DAO::$_nullObject);
$form->assign("addBlock", false);
if ($form->_addBlockName && $additionalblockCount) {
$form->assign("addBlock", true);
$form->assign("blockName", $form->_addBlockName);
$form->assign("blockId", $additionalblockCount);
$form->set($form->_addBlockName . "_Block_Count", $additionalblockCount);
}
$className = CRM_Utils_System::getClassName($form);
if (in_array($className, array('CRM_Event_Form_ManageEvent_Location', 'CRM_Contact_Form_Domain'))) {
$form->_blocks = array('Address' => ts('Address'), 'Email' => ts('Email'), 'Phone' => ts('Phone'));
}
$form->assign('blocks', $form->_blocks);
$form->assign('className', $className);
// get address sequence.
if (!($addressSequence = $form->get('addressSequence'))) {
require_once 'CRM/Core/BAO/Address.php';
$addressSequence = CRM_Core_BAO_Address::addressSequence();
$form->set('addressSequence', $addressSequence);
}
$form->assign('addressSequence', $addressSequence);
}
示例2: create
/**
* Function to create various elements of location block
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param boolean $fixAddress true if you need to fix (format) address values
* before inserting in db
*
* @param null $entity
*
* @return array $location
* @access public
* @static
*/
static function create(&$params, $fixAddress = TRUE, $entity = NULL)
{
$location = array();
if (!self::dataExists($params)) {
return $location;
}
// create location blocks.
foreach (self::$blocks as $block) {
if ($block != 'address') {
$location[$block] = CRM_Core_BAO_Block::create($block, $params, $entity);
} else {
$location[$block] = CRM_Core_BAO_Address::create($params, $fixAddress, $entity);
}
}
if ($entity) {
// this is a special case for adding values in location block table
$entityElements = array('entity_table' => $params['entity_table'], 'entity_id' => $params['entity_id']);
$location['id'] = self::createLocBlock($location, $entityElements);
} else {
// when we come from a form which displays all the location elements (like the edit form or the inline block
// elements, we can skip the below check. The below check adds quite a feq queries to an already overloaded
// form
if (!CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE)) {
// make sure contact should have only one primary block, CRM-5051
self::checkPrimaryBlocks(CRM_Utils_Array::value('contact_id', $params));
}
}
return $location;
}
示例3: run
/**
* Run the page.
*
* This method is called after the page is created.
*/
public function run()
{
// get the emails for this contact
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
$locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
$addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
$address = array();
if ($addressId > 0) {
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name'));
$entityBlock = array('id' => $addressId);
$address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
if (!empty($address)) {
foreach ($address as $key => &$value) {
$value['location_type'] = $locationTypes[$value['location_type_id']];
}
}
}
// we just need current address block
$currentAddressBlock['address'][$locBlockNo] = array_pop($address);
if (!empty($currentAddressBlock['address'][$locBlockNo])) {
// get contact name of shared contact names
$sharedAddresses = array();
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
foreach ($currentAddressBlock['address'] as $key => $addressValue) {
if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
$sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
}
}
$idValue = $currentAddressBlock['address'][$locBlockNo]['id'];
if (!empty($currentAddressBlock['address'][$locBlockNo]['master_id'])) {
$idValue = $currentAddressBlock['address'][$locBlockNo]['master_id'];
}
// add custom data of type address
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $this, $idValue);
// we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
$currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
$this->assign("dnc_viewCustomData", NULL);
$this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
$this->assign('sharedAddresses', $sharedAddresses);
}
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contactId;
$contact->find(TRUE);
$privacy = array();
foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) {
if (isset($contact->{$name})) {
$privacy[$name] = $contact->{$name};
}
}
$this->assign('contactId', $contactId);
$this->assign('locationIndex', $locBlockNo);
$this->assign('addressId', $addressId);
$this->assign('privacy', $privacy);
// check logged in user permission
CRM_Contact_Page_View::checkUserPermission($this, $contactId);
// finally call parent
parent::run();
}
示例4: add
/**
* takes an associative array and creates a contact object
*
* the function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
* @param array $locationId
*
* @return object CRM_Core_BAO_Address object
* @access public
* @static
*/
function add(&$params, &$ids, $locationId)
{
if (!CRM_Core_BAO_Address::dataExists($params, $locationId, $ids)) {
return null;
}
$address =& new CRM_Core_BAO_Address();
$address->location_id = $params['location'][$locationId]['id'];
$address->id = CRM_Utils_Array::value('address', $ids['location'][$locationId]);
CRM_Core_BAO_Address::fixAddress($params['location'][$locationId]['address']);
if ($address->copyValues($params['location'][$locationId]['address'])) {
// we copied only null stuff, so we delete the object
$address->delete();
return null;
}
return $address->save();
}
示例5: civicrm_api3_address_create
/**
* Add an Address for a contact.
*
* FIXME: Should be using basic_create util
*
* @param array $params
* Array per getfields metadata.
*
* @return array
* API result array
*/
function civicrm_api3_address_create(&$params)
{
_civicrm_api3_check_edit_permissions('CRM_Core_BAO_Address', $params);
/**
* If street_parsing, street_address has to be parsed into
* separate parts
*/
if (array_key_exists('street_parsing', $params)) {
if ($params['street_parsing'] == 1) {
if (array_key_exists('street_address', $params)) {
if (!empty($params['street_address'])) {
$parsedItems = CRM_Core_BAO_Address::parseStreetAddress($params['street_address']);
if (array_key_exists('street_name', $parsedItems)) {
$params['street_name'] = $parsedItems['street_name'];
}
if (array_key_exists('street_unit', $parsedItems)) {
$params['street_unit'] = $parsedItems['street_unit'];
}
if (array_key_exists('street_number', $parsedItems)) {
$params['street_number'] = $parsedItems['street_number'];
}
if (array_key_exists('street_number_suffix', $parsedItems)) {
$params['street_number_suffix'] = $parsedItems['street_number_suffix'];
}
}
}
}
}
if (!isset($params['check_permissions'])) {
$params['check_permissions'] = 0;
}
/**
* Create array for BAO (expects address params in as an
* element in array 'address'
*/
$addressBAO = CRM_Core_BAO_Address::add($params, TRUE);
if (empty($addressBAO)) {
return civicrm_api3_create_error("Address is not created or updated ");
} else {
$values = _civicrm_api3_dao_to_array($addressBAO, $params);
return civicrm_api3_create_success($values, $params, 'Address', $addressBAO);
}
}
示例6: preProcess
/**
* Set variables up before form is built.
*
* @param CRM_Core_Form $form
*
* @return void
*/
public static function preProcess(&$form)
{
$form->_addBlockName = CRM_Utils_Request::retrieve('block', 'String', CRM_Core_DAO::$_nullObject);
$additionalblockCount = CRM_Utils_Request::retrieve('count', 'Positive', CRM_Core_DAO::$_nullObject);
$form->assign('addBlock', FALSE);
if ($form->_addBlockName && $additionalblockCount) {
$form->assign('addBlock', TRUE);
$form->assign('blockName', $form->_addBlockName);
$form->assign('blockId', $additionalblockCount);
$form->set($form->_addBlockName . '_Block_Count', $additionalblockCount);
}
if (is_a($form, 'CRM_Event_Form_ManageEvent_Location') || is_a($form, 'CRM_Contact_Form_Domain')) {
$form->_blocks = array('Address' => ts('Address'), 'Email' => ts('Email'), 'Phone' => ts('Phone'));
}
$form->assign('blocks', $form->_blocks);
$form->assign('className', CRM_Utils_System::getClassName($form));
// get address sequence.
if (!($addressSequence = $form->get('addressSequence'))) {
$addressSequence = CRM_Core_BAO_Address::addressSequence();
$form->set('addressSequence', $addressSequence);
}
$form->assign('addressSequence', $addressSequence);
}
示例7: create
/**
* Function to create various elements of location block
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param boolean $fixAddress true if you need to fix (format) address values
* before inserting in db
*
* @return array $location
* @access public
* @static
*/
static function create(&$params, $fixAddress = true, $entity = null)
{
$location = array();
if (!self::dataExists($params)) {
return $location;
}
// create location blocks.
foreach (self::$blocks as $block) {
if ($block != 'address') {
eval('$location[$block] = CRM_Core_BAO_Block::create( $block, $params, $entity );');
} else {
$location[$block] = CRM_Core_BAO_Address::create($params, $fixAddress, $entity);
}
}
if ($entity) {
// this is a special case for adding values in location block table
$entityElements = array('entity_table' => $params['entity_table'], 'entity_id' => $params['entity_id']);
$location['id'] = self::createLocBlock($location, $entityElements);
} else {
// make sure contact should have only one primary block, CRM-5051
self::checkPrimaryBlocks(CRM_Utils_Array::value('contact_id', $params));
}
return $location;
}
示例8: buildCustom
/**
* Function to add the custom fields
*
* @param $id
* @param $name
* @param bool $viewOnly
* @param null $profileContactType
* @param null $fieldTypes
*
* @return void
* @access public
*/
function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
{
if ($id) {
$contactID = $this->getContactID();
// we don't allow conflicting fields to be
// configured via profile - CRM 2100
$fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
$fields = NULL;
if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
} else {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
}
if ($fields) {
// unset any email-* fields since we already collect it, CRM-2888
foreach (array_keys($fields) as $fieldName) {
if (substr($fieldName, 0, 6) == 'email-' && $profileContactType != 'honor') {
unset($fields[$fieldName]);
}
}
if (array_intersect_key($fields, $fieldsToIgnore)) {
$fields = array_diff_key($fields, $fieldsToIgnore);
CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
}
$fields = array_diff_assoc($fields, $this->_fields);
CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
$addCaptcha = FALSE;
foreach ($fields as $key => $field) {
if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
// ignore file upload fields
continue;
}
if ($profileContactType) {
//Since we are showing honoree name separately so we are removing it from honoree profile just for display
$honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
unset($fields[$field['name']]);
continue;
}
if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
$this->_fields[$profileContactType][$key] = $field;
} else {
unset($fields[$key]);
}
} else {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
$this->_fields[$key] = $field;
}
// CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
if ($field['add_captcha'] && !$this->_userID) {
$addCaptcha = TRUE;
}
}
$this->assign($name, $fields);
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->assign('isCaptcha', TRUE);
}
}
}
}
示例9: buildQuickForm
//.........这里部分代码省略.........
if ($membershipTypeID) {
$transactionID = $this->get('membership_trx_id');
$membershipAmount = $this->get('membership_amount');
$renewalMode = $this->get('renewal_mode');
$this->assign('membership_trx_id', $transactionID);
$this->assign('membership_amount', $membershipAmount);
$this->assign('renewal_mode', $renewalMode);
CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, FALSE, $membershipTypeID, TRUE, NULL, $this->_membershipContactID);
}
$this->_separateMembershipPayment = $this->get('separateMembershipPayment');
$this->assign("is_separate_payment", $this->_separateMembershipPayment);
$this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
$this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
$ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
$OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
$profileId = $OnBehalfProfile[0];
$fieldTypes = array('Contact', 'Organization');
$contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
$fieldTypes = array_merge($fieldTypes, $contactSubType);
if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
$fieldTypes = array_merge($fieldTypes, array('Membership'));
} else {
$fieldTypes = array_merge($fieldTypes, array('Contribution'));
}
$this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes);
}
$this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params));
$this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)));
$defaults = array();
$options = array();
$fields = array();
$removeCustomFieldTypes = array('Contribution');
foreach ($this->_fields as $name => $dontCare) {
if ($name == 'onbehalf') {
foreach ($dontCare as $key => $value) {
$fields['onbehalf'][$key] = 1;
}
} else {
$fields[$name] = 1;
}
}
$fields['state_province'] = $fields['country'] = $fields['email'] = 1;
$contact = $this->_params = $this->controller->exportValues('Main');
foreach ($fields as $name => $dontCare) {
if ($name == 'onbehalf') {
foreach ($dontCare as $key => $value) {
//$defaults[$key] = $contact['onbehalf'][$key];
if (isset($contact['onbehalf'][$key])) {
$defaults[$key] = $contact['onbehalf'][$key];
}
if (isset($contact['onbehalf']["{$key}_id"])) {
$defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"];
}
}
} elseif (isset($contact[$name])) {
$defaults[$name] = $contact[$name];
if (substr($name, 0, 7) == 'custom_') {
$timeField = "{$name}_time";
if (isset($contact[$timeField])) {
$defaults[$timeField] = $contact[$timeField];
}
} elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) {
$defaults[$name . '_custom'] = $contact[$name . '_custom'];
}
}
}
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
$this->_submitValues = array_merge($this->_submitValues, $defaults);
$this->setDefaults($defaults);
$values['entity_id'] = $this->_id;
$values['entity_table'] = 'civicrm_contribution_page';
CRM_Friend_BAO_Friend::retrieve($values, $data);
$tellAFriend = FALSE;
if ($this->_pcpId) {
if ($this->_pcpBlock['is_tellfriend_enabled']) {
$this->assign('friendText', ts('Tell a Friend'));
$subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
$tellAFriend = TRUE;
}
} elseif (CRM_Utils_Array::value('is_active', $data)) {
$friendText = $data['title'];
$this->assign('friendText', $friendText);
$subUrl = "eid={$this->_id}&pcomponent=contribute";
$tellAFriend = TRUE;
}
if ($tellAFriend) {
if ($this->_action & CRM_Core_Action::PREVIEW) {
$url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}");
} else {
$url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}");
}
$this->assign('friendURL', $url);
}
$this->freeze();
// can we blow away the session now to prevent hackery
// CRM-9491
$this->controller->reset();
}
示例10: run
/**
* Run the page.
*
* This method is called after the page is created.
*
* @return void
* @access public
*
*/
function run()
{
// get the emails for this contact
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
$locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
$addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
$address = array();
if ($addressId > 0) {
$locationTypes = CRM_Core_PseudoConstant::locationDisplayName();
$entityBlock = array('id' => $addressId);
$address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
if (!empty($address)) {
foreach ($address as $key => &$value) {
$value['location_type'] = $locationTypes[$value['location_type_id']];
}
}
}
// we just need current address block
$currentAddressBlock['address'][$locBlockNo] = array_pop($address);
if (!empty($currentAddressBlock['address'][$locBlockNo])) {
// get contact name of shared contact names
$sharedAddresses = array();
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
foreach ($currentAddressBlock['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']);
}
}
// add custom data of type address
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $this, $currentAddressBlock['address'][$locBlockNo]['id']);
// we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
$currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
$this->assign("dnc_viewCustomData", NULL);
$this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
$this->assign('sharedAddresses', $sharedAddresses);
}
$this->assign('contactId', $contactId);
$this->assign('locationIndex', $locBlockNo);
$this->assign('addressId', $addressId);
$appendBlockIndex = CRM_Core_BAO_Address::getAddressCount($contactId);
// check if we are adding new address, then only append add link
if ($appendBlockIndex == $locBlockNo) {
if ($appendBlockIndex) {
$appendBlockIndex++;
}
} else {
$appendBlockIndex = 0;
}
$this->assign('appendBlockIndex', $appendBlockIndex);
// check logged in user permission
CRM_Contact_Page_View::checkUserPermission($this, $contactId);
// finally call parent
parent::run();
}
示例11: preProcess
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/
function preProcess()
{
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
$this->_searchKey = CRM_Utils_Request::retrieve('key', 'String', $this);
// sort out whether it’s a delete-to-trash, delete-into-oblivion or restore (and let the template know)
$values = $this->controller->exportValues();
$this->_skipUndelete = (CRM_Core_Permission::check('access deleted contacts') and (CRM_Utils_Request::retrieve('skip_undelete', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::DELETE_PERMANENTLY));
$this->_restore = (CRM_Utils_Request::retrieve('restore', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::RESTORE);
if ($this->_restore && !CRM_Core_Permission::check('access deleted contacts')) {
CRM_Core_Error::fatal(ts('You do not have permission to access this contact.'));
} elseif (!CRM_Core_Permission::check('delete contacts')) {
CRM_Core_Error::fatal(ts('You do not have permission to delete this contact.'));
}
$this->assign('trash', CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL) and !$this->_skipUndelete);
$this->assign('restore', $this->_restore);
if ($this->_restore) {
CRM_Utils_System::setTitle(ts('Restore Contact'));
}
if ($cid) {
if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::fatal(ts('You do not have permission to delete this contact. Note: you can delete contacts if you can edit them.'));
} elseif (CRM_Contact_BAO_Contact::checkDomainContact($cid)) {
CRM_Core_Error::fatal(ts('This contact is a special one for the contact information associated with the CiviCRM installation for this domain. No one is allowed to delete it because the information is used for special system purposes.'));
}
$this->_contactIds = array($cid);
$this->_single = TRUE;
$this->assign('totalSelectedContacts', 1);
} else {
parent::preProcess();
}
$this->_sharedAddressMessage = $this->get('sharedAddressMessage');
if (!$this->_restore && !$this->_sharedAddressMessage) {
// we check for each contact for shared contact address
$sharedContactList = array();
$sharedAddressCount = 0;
foreach ($this->_contactIds as $contactId) {
// check if a contact that is being deleted has any shared addresses
$sharedAddressMessage = CRM_Core_BAO_Address::setSharedAddressDeleteStatus(NULL, $contactId, TRUE);
if ($sharedAddressMessage['count'] > 0) {
$sharedAddressCount += $sharedAddressMessage['count'];
$sharedContactList = array_merge($sharedContactList, $sharedAddressMessage['contactList']);
}
}
$this->_sharedAddressMessage = array('count' => $sharedAddressCount, 'contactList' => $sharedContactList);
if ($sharedAddressCount > 0) {
if (count($this->_contactIds) > 1) {
// more than one contact deleted
$message = ts('One of the selected contacts has an address record that is shared with 1 other contact.', array('plural' => 'One or more selected contacts have address records which are shared with %count other contacts.', 'count' => $sharedAddressCount));
} else {
// only one contact deleted
$message = ts('This contact has an address record which is shared with 1 other contact.', array('plural' => 'This contact has an address record which is shared with %count other contacts.', 'count' => $sharedAddressCount));
}
CRM_Core_Session::setStatus($message . ' ' . ts('Shared addresses will not be removed or altered but will no longer be shared.'), ts('Shared Addesses Owner'));
}
// set in form controller so that queries are not fired again
$this->set('sharedAddressMessage', $this->_sharedAddressMessage);
}
}
示例12: parseAddress
/**
* Parse all address blocks present in given params
* and return parse result for all address blocks,
* This function either parse street address in to child
* elements or build street address from child elements.
*
* @param array $params
* of key value consist of address blocks.
*
* @return array
* as array of success/fails for each address block
*/
public function parseAddress(&$params)
{
$parseSuccess = $parsedFields = array();
if (!is_array($params['address']) || CRM_Utils_System::isNull($params['address'])) {
return $parseSuccess;
}
foreach ($params['address'] as $instance => &$address) {
$buildStreetAddress = FALSE;
$parseFieldName = 'street_address';
foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
if (!empty($address[$fld])) {
$parseFieldName = 'street_number';
$buildStreetAddress = TRUE;
break;
}
}
// main parse string.
$parseString = CRM_Utils_Array::value($parseFieldName, $address);
// parse address field.
$parsedFields = CRM_Core_BAO_Address::parseStreetAddress($parseString);
if ($buildStreetAddress) {
//hack to ignore spaces between number and suffix.
//here user gives input as street_number so it has to
//be street_number and street_number_suffix, but
//due to spaces though preg detect string as street_name
//consider it as 'street_number_suffix'.
$suffix = $parsedFields['street_number_suffix'];
if (!$suffix) {
$suffix = $parsedFields['street_name'];
}
$address['street_number_suffix'] = $suffix;
$address['street_number'] = $parsedFields['street_number'];
$streetAddress = NULL;
foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
if (in_array($fld, array('street_name', 'street_unit'))) {
$streetAddress .= ' ';
}
$streetAddress .= CRM_Utils_Array::value($fld, $address);
}
$address['street_address'] = trim($streetAddress);
$parseSuccess[$instance] = TRUE;
} else {
$success = TRUE;
// consider address is automatically parseable,
// when we should found street_number and street_name
if (empty($parsedFields['street_name']) || empty($parsedFields['street_number'])) {
$success = FALSE;
}
// check for original street address string.
if (empty($parseString)) {
$success = TRUE;
}
$parseSuccess[$instance] = $success;
// we do not reset element values, but keep what we've parsed
// in case of partial matches: CRM-8378
// merge parse address in to main address block.
$address = array_merge($address, $parsedFields);
}
}
return $parseSuccess;
}
示例13: buildQuickForm
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm()
{
$this->add('hidden', 'gid', $this->_gid);
switch ($this->_mode) {
case self::MODE_CREATE:
case self::MODE_EDIT:
case self::MODE_REGISTER:
CRM_Utils_Hook::buildProfile($this->_ufGroup['name']);
break;
case self::MODE_SEARCH:
CRM_Utils_Hook::searchProfile($this->_ufGroup['name']);
break;
default:
}
//lets have single status message, CRM-4363
$return = FALSE;
$statusMessage = NULL;
if ($this->_multiRecord & CRM_Core_Action::ADD && $this->_maxRecordLimit) {
return;
}
if ($this->_multiRecord & CRM_Core_Action::DELETE) {
if (!$this->_recordExists) {
CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', array(1 => $this->_recordId)), ts('Record doesnot exists'), 'alert');
} else {
$this->assign('deleteRecord', TRUE);
}
return;
}
CRM_Core_BAO_Address::checkContactSharedAddressFields($this->_fields, $this->_id);
// we should not allow component and mix profiles in search mode
if ($this->_mode != self::MODE_REGISTER) {
//check for mix profile fields (eg: individual + other contact type)
if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
if ($this->_mode & self::MODE_EDIT && $this->_isContactActivityProfile) {
$errors = self::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
if (!empty($errors)) {
$statusMessage = array_pop($errors);
$return = TRUE;
}
} else {
$statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
$return = TRUE;
}
}
$profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
if ($this->_id) {
$contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
$contactType = $contactTypes[0];
array_shift($contactTypes);
$contactSubtypes = $contactTypes;
$profileSubType = FALSE;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileSubType = $profileType;
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
if ($profileType != 'Contact' && !$this->_isContactActivityProfile && ($profileSubType && !empty($contactSubtypes) && !in_array($profileSubType, $contactSubtypes) || $profileType != $contactType)) {
$return = TRUE;
if (!$statusMessage) {
$statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType));
}
}
}
if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
$return = TRUE;
if (!$statusMessage) {
$statusMessage = ts('Profile is not configured for the selected action.');
}
}
}
//lets have single status message,
$this->assign('statusMessage', $statusMessage);
if ($return) {
return FALSE;
}
$this->assign('id', $this->_id);
$this->assign('mode', $this->_mode);
$this->assign('action', $this->_action);
$this->assign('fields', $this->_fields);
$this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
// should we restrict what we display
$admin = TRUE;
if ($this->_mode == self::MODE_EDIT) {
$admin = FALSE;
// show all fields that are visibile:
// if we are a admin OR the same user OR acl-user with access to the profile
// or we have checksum access to this contact (i.e. the user without a login) - CRM-5909
if (CRM_Core_Permission::check('administer users') || $this->_id == $this->_currentUserID || $this->_isPermissionedChecksum || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id')))) {
$admin = TRUE;
}
}
// if false, user is not logged-in.
$anonUser = FALSE;
if (!$this->_currentUserID) {
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
$primaryLocationType = $defaultLocationType->id;
//.........这里部分代码省略.........
示例14: setDefaultValues
/**
* Set default values for address block.
*
* @param array $defaults
* Defaults associated array.
* @param CRM_Core_Form $form
* Form object.
*/
public static function setDefaultValues(&$defaults, &$form)
{
$addressValues = array();
if (isset($defaults['address']) && is_array($defaults['address']) && !CRM_Utils_System::isNull($defaults['address'])) {
// start of contact shared adddress defaults
$sharedAddresses = array();
$masterAddress = array();
// get contact name of shared contact names
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
foreach ($defaults['address'] as $key => $addressValue) {
if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
$master_cid = $shareAddressContactNames[$addressValue['master_id']]['contact_id'];
$sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'], 'options' => CRM_Core_BAO_Address::getValues(array('entity_id' => $master_cid, 'contact_id' => $master_cid)), 'master_id' => $addressValue['master_id']);
$defaults['address'][$key]['master_contact_id'] = $master_cid;
} else {
$defaults['address'][$key]['use_shared_address'] = 0;
}
//check if any address is shared by any other contacts
$masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']);
}
$form->assign('sharedAddresses', $sharedAddresses);
$form->assign('masterAddress', $masterAddress);
// end of shared address defaults
// start of parse address functionality
// build street address, CRM-5450.
if ($form->_parseStreetAddress) {
$parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
foreach ($defaults['address'] as $cnt => &$address) {
$streetAddress = NULL;
foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
if (in_array($fld, array('street_name', 'street_unit'))) {
$streetAddress .= ' ';
}
$streetAddress .= CRM_Utils_Array::value($fld, $address);
}
$streetAddress = trim($streetAddress);
if (!empty($streetAddress)) {
$address['street_address'] = $streetAddress;
}
if (isset($address['street_number'])) {
$address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address);
}
// build array for set default.
foreach ($parseFields as $field) {
$addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
}
// don't load fields, use js to populate.
foreach (array('street_number', 'street_name', 'street_unit') as $f) {
if (isset($address[$f])) {
unset($address[$f]);
}
}
}
$form->assign('allAddressFieldValues', json_encode($addressValues));
//hack to handle show/hide address fields.
$parsedAddress = array();
if ($form->_contactId && !empty($_POST['address']) && is_array($_POST['address'])) {
foreach ($_POST['address'] as $cnt => $values) {
$showField = 'streetAddress';
foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
if (!empty($values[$fld])) {
$showField = 'addressElements';
break;
}
}
$parsedAddress[$cnt] = $showField;
}
}
$form->assign('showHideAddressFields', $parsedAddress);
$form->assign('loadShowHideAddressFields', empty($parsedAddress) ? FALSE : TRUE);
}
// end of parse address functionality
}
}
示例15: buildCustom
/**
* Function to add the custom fields
*
* @return None
* @access public
*/
function buildCustom($id, $name, $viewOnly = FALSE, $onBehalf = FALSE, $fieldTypes = NULL)
{
$stateCountryMap = array();
if ($id) {
$contactID = $this->getContactID();
// we don't allow conflicting fields to be
// configured via profile - CRM 2100
$fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
$fields = NULL;
if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
} else {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
}
if ($fields) {
// unset any email-* fields since we already collect it, CRM-2888
foreach (array_keys($fields) as $fieldName) {
if (substr($fieldName, 0, 6) == 'email-') {
unset($fields[$fieldName]);
}
}
if (array_intersect_key($fields, $fieldsToIgnore)) {
$fields = array_diff_key($fields, $fieldsToIgnore);
CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
}
$fields = array_diff_assoc($fields, $this->_fields);
CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
$addCaptcha = FALSE;
foreach ($fields as $key => $field) {
if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
// ignore file upload fields
continue;
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $key;
}
if ($onBehalf) {
if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
$this->_fields['onbehalf'][$key] = $field;
} else {
unset($fields[$key]);
}
} else {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
$this->_fields[$key] = $field;
}
// CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
if ($field['add_captcha'] && !$this->_userID) {
$addCaptcha = TRUE;
}
}
$this->assign($name, $fields);
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->assign('isCaptcha', TRUE);
}
}
}
}