本文整理汇总了PHP中CRM_Core_BAO_Location::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Location::create方法的具体用法?PHP CRM_Core_BAO_Location::create怎么用?PHP CRM_Core_BAO_Location::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Location
的用法示例。
在下文中一共展示了CRM_Core_BAO_Location::create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLocBlockgetValues
/**
* GetValues() method
* get the values of various location elements
*/
public function testLocBlockgetValues()
{
$contactId = $this->individualCreate();
//create various element of location block
//like address, phone, email, openid, im.
$params = array('address' => array('1' => array('street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', 'city' => 'Newark', 'postal_code' => '01903', 'country_id' => 1228, 'state_province_id' => 1029, 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', 'is_primary' => 1, 'location_type_id' => 1)), 'email' => array('1' => array('email' => 'john.smith@example.org', 'is_primary' => 1, 'location_type_id' => 1)), 'phone' => array('1' => array('phone_type_id' => 1, 'phone' => '303443689', 'is_primary' => 1, 'location_type_id' => 1), '2' => array('phone_type_id' => 2, 'phone' => '9833910234', 'location_type_id' => 1)), 'openid' => array('1' => array('openid' => 'http://civicrm.org/', 'location_type_id' => 1, 'is_primary' => 1)), 'im' => array('1' => array('name' => 'jane.doe', 'provider_id' => 1, 'location_type_id' => 1, 'is_primary' => 1)));
$params['contact_id'] = $contactId;
//create location elements.
CRM_Core_BAO_Location::create($params);
//get the values from DB
$values = CRM_Core_BAO_Location::getValues($params);
//Now check values of address
$this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['address']), CRM_Utils_Array::value('1', $values['address']));
//Now check values of email
$this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['email']), CRM_Utils_Array::value('1', $values['email']));
//Now check values of phone
$this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['phone']), CRM_Utils_Array::value('1', $values['phone']));
//Now check values of mobile
$this->assertAttributesEquals(CRM_Utils_Array::value('2', $params['phone']), CRM_Utils_Array::value('2', $values['phone']));
//Now check values of openid
$this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['openid']), CRM_Utils_Array::value('1', $values['openid']));
//Now check values of im
$this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['im']), CRM_Utils_Array::value('1', $values['im']));
$this->contactDelete($contactId);
}
示例2: _civicrm_location_update
/**
*
* @param <type> $params
* @param <type> $locationArray
* @return <type>
*/
function _civicrm_location_update($params, $locations)
{
// convert api params to 3.0 format.
if ('3.0' != CRM_Utils_Array::value('version', $params)) {
_civicrm_format_params_v2_to_v3($params);
}
$contact = array('contact_id' => $params['contact_id']);
$primary = $billing = array();
// copy params value in contact array.
foreach (array('email', 'phone', 'im', 'openid') as $name) {
if (CRM_Utils_Array::value($name, $params) && is_array($params[$name])) {
$blockCount = 0;
$contact[$name] = array();
foreach ($params[$name] as $val) {
$contact[$name][++$blockCount] = $val;
// check for primary and billing.
if (CRM_Utils_Array::value('is_primary', $val)) {
$primary[$name][$blockCount] = true;
}
if (CRM_Utils_Array::value('is_billing', $val)) {
$primary[$name][$blockCount] = true;
}
}
} else {
// get values from db blocks so we dont lose them.
if (!CRM_Utils_Array::value($name, $locations) || !is_array($locations[$name])) {
continue;
}
$contact[$name] = $locations[$name];
}
}
$addressCount = 1;
if (CRM_Utils_Array::value(1, $params['address']) && !empty($params['address'][1])) {
$contact['address'][$addressCount] = $params['address'][1];
// check for primary and billing address.
if (CRM_Utils_Array::value('is_primary', $params['address'][1])) {
$primary['address'][$addressCount] = true;
}
if (CRM_Utils_Array::value('is_billing', $params['address'][1])) {
$billing['address'][$addressCount] = true;
}
// format state and country.
foreach (array('state_province', 'country') as $field) {
$fName = $field == 'state_province' ? 'stateProvinceAbbreviation' : 'countryIsoCode';
if (CRM_Utils_Array::value($field, $contact['address'][$addressCount]) && is_numeric($contact['address'][$addressCount][$field])) {
$fValue =& $contact['address'][$addressCount][$field];
eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );');
//kill the reference.
unset($fValue);
}
}
}
//handle primary and billing reset.
foreach (array('email', 'phone', 'im', 'address', 'openid') as $name) {
if (!array_key_exists($name, $contact) || CRM_Utils_System::isNull($contact[$name])) {
continue;
}
$errorMsg = null;
$primaryBlockIndex = $billingBlockIndex = 0;
if (array_key_exists($name, $primary)) {
if (count($primary[$name]) > 1) {
$errorMsg .= ts("<br />Multiple Primary %1.", array(1 => $name));
} else {
$primaryBlockIndex = key($primary[$name]);
}
}
if (array_key_exists($name, $billing)) {
if (count($billing[$name]) > 1) {
$errorMsg .= ts("<br />Multiple Billing %1.", array(1 => $name));
} else {
$billingBlockIndex = key($billing[$name]);
}
}
if ($errorMsg) {
return civicrm_create_error($errorMsg);
}
foreach ($contact[$name] as $count => &$values) {
if ($primaryBlockIndex && $count != $primaryBlockIndex) {
$values['is_primary'] = false;
}
if ($billingBlockIndex && $count != $billingBlockIndex) {
$values['is_billing'] = false;
}
// kill the reference.
unset($values);
}
}
// get all ids if not present.
require_once 'CRM/Contact/BAO/Contact.php';
CRM_Contact_BAO_Contact::resolveDefaults($contact, true);
$location = CRM_Core_BAO_Location::create($contact);
if (empty($location)) {
return civicrm_create_error(ts("Location not created"));
}
//.........这里部分代码省略.........
示例3: foreach
/**
* Create contact.
*
* takes an associative array and creates a contact object and all the associated
* derived objects (i.e. individual, location, email, phone etc)
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param bool $fixAddress
* If we need to fix address.
* @param bool $invokeHooks
* If we need to invoke hooks.
*
* @param bool $skipDelete
* Unclear parameter, passed to website create
*
* @todo explain this parameter
*
* @throws Exception
* @return CRM_Contact_BAO_Contact|CRM_Core_Error
* Created or updated contribution object. We are deprecating returning an error in
* favour of exceptions
*/
public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE, $skipDelete = FALSE)
{
$contact = NULL;
if (empty($params['contact_type']) && empty($params['contact_id'])) {
return $contact;
}
$isEdit = TRUE;
if ($invokeHooks) {
if (!empty($params['contact_id'])) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params);
$isEdit = FALSE;
}
}
$config = CRM_Core_Config::singleton();
// CRM-6942: set preferred language to the current language if it’s unset (and we’re creating a contact).
if (empty($params['contact_id']) && empty($params['preferred_language'])) {
$params['preferred_language'] = $config->lcMessages;
}
// CRM-9739: set greeting & addressee if unset and we’re creating a contact.
if (empty($params['contact_id'])) {
foreach (self::$_greetingTypes as $greeting) {
if (empty($params[$greeting . '_id'])) {
if ($defaultGreetingTypeId = CRM_Contact_BAO_Contact_Utils::defaultGreeting($params['contact_type'], $greeting)) {
$params[$greeting . '_id'] = $defaultGreetingTypeId;
}
}
}
}
$transaction = new CRM_Core_Transaction();
$contact = self::add($params);
if (!$contact) {
// Not dying here is stupid, since we get into wierd situation and into a bug that
// is impossible to figure out for the user or for us
// CRM-7925
CRM_Core_Error::fatal();
}
$params['contact_id'] = $contact->id;
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) {
// Enabling multisite causes the contact to be added to the domain group.
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (!empty($domainGroupID)) {
if (!empty($params['group']) && is_array($params['group'])) {
$params['group'][$domainGroupID] = 1;
} else {
$params['group'] = array($domainGroupID => 1);
}
}
}
if (array_key_exists('group', $params)) {
$contactIds = array($params['contact_id']);
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
} elseif ($flag == -1) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
}
}
}
// Add location Block data.
$blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
foreach ($blocks as $name => $value) {
$contact->{$name} = $value;
}
//add website
CRM_Core_BAO_Website::create($params['website'], $contact->id, $skipDelete);
//get userID from session
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
// add notes
if (!empty($params['note'])) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$contactId = $contact->id;
//.........这里部分代码省略.........
示例4: postProcess
/**
* Process the form when submitted.
*
* @return void
*/
public function postProcess()
{
$params = $this->exportValues();
$params['entity_id'] = $this->_id;
$params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
$domain = CRM_Core_BAO_Domain::edit($params, $this->_id);
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
if (isset($this->_locationDefaults['address'][1]['location_type_id'])) {
$params['address'][1]['location_type_id'] = $this->_locationDefaults['address'][1]['location_type_id'];
} else {
$params['address'][1]['location_type_id'] = $defaultLocationType->id;
}
if (isset($this->_locationDefaults['phone'][1]['location_type_id'])) {
$params['phone'][1]['location_type_id'] = $this->_locationDefaults['phone'][1]['location_type_id'];
} else {
$params['phone'][1]['location_type_id'] = $defaultLocationType->id;
}
if (isset($this->_locationDefaults['email'][1]['location_type_id'])) {
$params['email'][1]['location_type_id'] = $this->_locationDefaults['email'][1]['location_type_id'];
} else {
$params['email'][1]['location_type_id'] = $defaultLocationType->id;
}
$params += array('contact_id' => $this->_contactId);
$contactParams = array('sort_name' => $domain->name, 'display_name' => $domain->name, 'legal_name' => $domain->name, 'organization_name' => $domain->name, 'contact_id' => $this->_contactId, 'contact_type' => 'Organization');
if ($this->_contactId) {
$contactParams['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
}
CRM_Contact_BAO_Contact::add($contactParams);
CRM_Core_BAO_Location::create($params, TRUE);
CRM_Core_BAO_Domain::edit($params, $this->_id);
//set domain from email address, CRM-3552
$emailName = '"' . $params['email_name'] . '" <' . $params['email_address'] . '>';
$emailParams = array('label' => $emailName, 'description' => $params['description'], 'is_active' => 1, 'is_default' => 1);
$groupParams = array('name' => 'from_email_address');
//get the option value wt.
if ($this->_fromEmailId) {
$action = $this->_action;
$emailParams['weight'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_fromEmailId, 'weight');
} else {
//add from email address.
$action = CRM_Core_Action::ADD;
$grpId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'from_email_address', 'id', 'name');
$fieldValues = array('option_group_id' => $grpId);
$emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
}
//reset default within domain.
$emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
CRM_Core_OptionValue::addOptionValue($emailParams, $groupParams, $action, $this->_fromEmailId);
CRM_Core_Session::setStatus(ts("Domain information for '%1' has been saved.", array(1 => $domain->name)), ts('Saved'), 'success');
$session = CRM_Core_Session::singleton();
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
示例5: postProcess
/**
* Process the form when submitted
*
* @return void
* @access public
*/
public function postProcess()
{
require_once 'CRM/Core/BAO/Domain.php';
$params = array();
$params = $this->exportValues();
$params['entity_id'] = $this->_id;
$params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
$domain = CRM_Core_BAO_Domain::edit($params, $this->_id);
require_once 'CRM/Core/BAO/LocationType.php';
$defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
$location = array();
$params['address'][1]['location_type_id'] = $defaultLocationType->id;
$params['phone'][1]['location_type_id'] = $defaultLocationType->id;
$params['email'][1]['location_type_id'] = $defaultLocationType->id;
$location = CRM_Core_BAO_Location::create($params, true, 'domain');
$params['loc_block_id'] = $location['id'];
require_once 'CRM/Core/BAO/Domain.php';
CRM_Core_BAO_Domain::edit($params, $this->_id);
//set domain from email address, CRM-3552
$emailName = '"' . $params['email_name'] . '"<' . $params['email_address'] . '>';
$emailParams = array('label' => $emailName, 'description' => $params['description'], 'is_active' => 1, 'is_default' => 1);
$groupParams = array('name' => 'from_email_address');
//get the option value wt.
if ($this->_fromEmailId) {
$action = $this->_action;
$emailParams['weight'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_fromEmailId, 'weight');
} else {
//add from email address.
$action = CRM_Core_Action::ADD;
require_once 'CRM/Utils/Weight.php';
$grpId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'from_email_address', 'id', 'name');
$fieldValues = array('option_group_id' => $grpId);
$emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
}
require_once 'CRM/Core/OptionValue.php';
//reset default within domain.
$emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
CRM_Core_OptionValue::addOptionValue($emailParams, $groupParams, $action, $this->_fromEmailId);
CRM_Core_Session::setStatus(ts('Domain information for \'%1\' has been saved.', array(1 => $domain->name)));
$session =& CRM_Core_Session::singleton();
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
示例6: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
$params = $this->exportValues();
$delteOldBlock = false;
// if 'use existing location' option is selected -
if ($params['location_option'] == 2 && CRM_Utils_Array::value('loc_event_id', $params) && $params['loc_event_id'] != $this->_oldLocBlockId) {
// if new selected loc is different from old loc, update the loc_block_id
// so that loc update would affect the selected loc and not the old one.
$delteOldBlock = true;
CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id, 'loc_block_id', $params['loc_event_id']);
}
// if 'create new loc' option is selected, set the loc_block_id for this event to null
// so that an update would result in creating a new loc.
if ($this->_oldLocBlockId && $params['location_option'] == 1) {
$delteOldBlock = true;
CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id, 'loc_block_id', 'null');
}
// if 'create new loc' optioin is selected OR selected new loc is different
// from old one, go ahead and delete the old loc provided thats not being
// used by any other event
if ($this->_oldLocBlockId && $delteOldBlock) {
CRM_Event_BAO_Event::deleteEventLocBlock($this->_oldLocBlockId, $this->_id);
}
// get ready with location block params
$params['entity_table'] = 'civicrm_event';
$params['entity_id'] = $this->_id;
require_once 'CRM/Core/BAO/LocationType.php';
$defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
foreach (array('address', 'phone', 'email') as $block) {
if (!CRM_Utils_Array::value($block, $params) || !is_array($params[$block])) {
continue;
}
foreach ($params[$block] as $count => &$values) {
if ($count == 1) {
$values['is_primary'] = 1;
}
$values['location_type_id'] = $defaultLocationType->id ? $defaultLocationType->id : 1;
}
}
// create/update event location
require_once 'CRM/Core/BAO/Location.php';
$location = CRM_Core_BAO_Location::create($params, true, 'event');
$params['loc_block_id'] = $location['id'];
// finally update event params
$params['id'] = $this->_id;
require_once 'CRM/Event/BAO/Event.php';
CRM_Event_BAO_Event::add($params);
parent::endPostProcess();
}
示例7: civicrm_api3_volunteer_project_savelocblock
/**
* Saves/creates an entire location block with a single call instead of
* requiring a handful of calls/promises/resolutions from angular
*
* @param $params
* @return array
*
*/
function civicrm_api3_volunteer_project_savelocblock($params)
{
$locBlockData = array();
//Address 1
if (array_key_exists("address", $params) && is_array($params['address'])) {
$locBlockData['address'][1] = $params['address'];
if (!array_key_exists("location_type_id", $locBlockData['address'][1])) {
$locBlockData['address'][1]['location_type_id'] = 1;
}
}
//Address 2
if (array_key_exists("address_2", $params) && is_array($params['address_2'])) {
$locBlockData['address'][2] = $params['address_2'];
if (!array_key_exists("location_type_id", $locBlockData['address'][2])) {
$locBlockData['address'][2]['location_type_id'] = 2;
}
}
//Email 1
if (array_key_exists("email", $params) && is_array($params['email'])) {
$locBlockData['email'][1] = $params['email'];
if (!array_key_exists("location_type_id", $locBlockData['email'][1])) {
$locBlockData['email'][1]['location_type_id'] = 1;
}
}
//Email 2
if (array_key_exists("email_2", $params) && is_array($params['email_2'])) {
$locBlockData['email'][2] = $params['email_2'];
if (!array_key_exists("location_type_id", $locBlockData['email'][2])) {
$locBlockData['email'][2]['location_type_id'] = 2;
}
}
//Phone 1
if (array_key_exists("phone", $params) && is_array($params['phone'])) {
$locBlockData['phone'][1] = $params['phone'];
if (!array_key_exists("location_type_id", $locBlockData['phone'][1])) {
$locBlockData['phone'][1]['location_type_id'] = 1;
}
}
//Phone 2
if (array_key_exists("phone_2", $params) && is_array($params['phone_2'])) {
$locBlockData['phone'][2] = $params['phone_2'];
if (!array_key_exists("location_type_id", $locBlockData['phone'][2])) {
$locBlockData['phone'][2]['location_type_id'] = 2;
}
}
if (array_key_exists("id", $params) && is_array($params['id']) && !$params['id'] == 0) {
$locBlockData['id'] = $params['id'];
}
$locBlockData['entity_table'] = 'civicrm_volunteer_project';
$locBlockData['entity_id'] = $params['entity_id'];
//Todo: Check Permissions
$location = CRM_Core_BAO_Location::create($locBlockData, TRUE, 'VolunteerProject');
return civicrm_api3_create_success($location['id'], "VolunteerProject", "SaveLocBlock", $params);
}
示例8: CRM_Core_Transaction
/**
* Function to create contact
* takes an associative array and creates a contact object and all the associated
* derived objects (i.e. individual, location, email, phone etc)
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param boolean $fixAddress if we need to fix address
* @param boolean $invokeHooks if we need to invoke hooks
*
* @return object CRM_Contact_BAO_Contact object
* @access public
* @static
*/
static function &create(&$params, $fixAddress = true, $invokeHooks = true)
{
$contact = null;
if (!CRM_Utils_Array::value('contact_type', $params) && !CRM_Utils_Array::value('contact_id', $params)) {
return $contact;
}
$isEdit = true;
if ($invokeHooks) {
require_once 'CRM/Utils/Hook.php';
if (CRM_Utils_Array::value('contact_id', $params)) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params);
$isEdit = false;
}
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$contact = self::add($params);
$params['contact_id'] = $contact->id;
if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
// in order to make sure that every contact must be added to a group (CRM-4613) -
require_once 'CRM/Core/BAO/Domain.php';
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (CRM_Utils_Array::value('group', $params) && is_array($params['group'])) {
$grpFlp = array_flip($params['group']);
if (!array_key_exists(1, $grpFlp)) {
$params['group'][$domainGroupID] = 1;
}
} else {
$params['group'] = array($domainGroupID => 1);
}
}
if (array_key_exists('group', $params)) {
require_once 'CRM/Contact/BAO/GroupContact.php';
$contactIds = array($params['contact_id']);
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
} else {
if ($flag == -1) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
}
}
}
}
//add location Block data
$blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
foreach ($blocks as $name => $value) {
$contact->{$name} = $value;
}
//get userID from session
$session =& CRM_Core_Session::singleton();
$userID = $session->get('userID');
// add notes
if (CRM_Utils_Array::value('note', $params)) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note'], 'subject' => $note['subject'], 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
} else {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $params['note'], 'subject' => CRM_Utils_Array::value('subject', $params), 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
}
// update the UF user_unique_id if that has changed
require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::updateUFName($contact->id);
//.........这里部分代码省略.........
示例9: CRM_Core_Transaction
/**
* Function to create contact
* takes an associative array and creates a contact object and all the associated
* derived objects (i.e. individual, location, email, phone etc)
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param boolean $fixAddress if we need to fix address
* @param boolean $invokeHooks if we need to invoke hooks
*
* @return object CRM_Contact_BAO_Contact object
* @access public
* @static
*/
static function &create(&$params, $fixAddress = true, $invokeHooks = true)
{
$contact = null;
if (!CRM_Utils_Array::value('contact_type', $params) && !CRM_Utils_Array::value('contact_id', $params)) {
return $contact;
}
$isEdit = true;
if ($invokeHooks) {
require_once 'CRM/Utils/Hook.php';
if (CRM_Utils_Array::value('contact_id', $params)) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params);
$isEdit = false;
}
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$contact = self::add($params);
if (!$contact) {
// CRM_Core_Error::fatal( ts( 'THe contact was not created, not set up to handle error' ) );
}
$params['contact_id'] = $contact->id;
if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
// in order to make sure that every contact must be added to a group (CRM-4613) -
require_once 'CRM/Core/BAO/Domain.php';
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (CRM_Utils_Array::value('group', $params) && is_array($params['group'])) {
$grpFlp = array_flip($params['group']);
if (!array_key_exists(1, $grpFlp)) {
$params['group'][$domainGroupID] = 1;
}
} else {
$params['group'] = array($domainGroupID => 1);
}
}
if (array_key_exists('group', $params)) {
require_once 'CRM/Contact/BAO/GroupContact.php';
$contactIds = array($params['contact_id']);
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
} else {
if ($flag == -1) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
}
}
}
}
$config = CRM_Core_Config::singleton();
if (!$config->doNotResetCache) {
// Note: doNotResetCache flag is currently set by import contact process, since resetting and
// rebuilding cache could be expensive (for many contacts). We might come out with better
// approach in future.
// clear acl cache if any.
require_once 'CRM/ACL/BAO/Cache.php';
CRM_ACL_BAO_Cache::resetCache();
}
//add location Block data
$blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
foreach ($blocks as $name => $value) {
$contact->{$name} = $value;
}
//get userID from session
$session =& CRM_Core_Session::singleton();
$userID = $session->get('userID');
// add notes
if (CRM_Utils_Array::value('note', $params)) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note'], 'subject' => $note['subject'], 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
} else {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
//.........这里部分代码省略.........
示例10: synchronizeIndividualAddresses
/**
* This function synchronizes (updates) the address of individuals,
* sharing the address of the passed household-contact-ID.
* @param integer $householdContactID the household contact id.
*
* @return void
* @access public
* @static
*/
static function synchronizeIndividualAddresses($householdContactID)
{
require_once 'api/v2/Location.php';
require_once 'CRM/Core/BAO/Location.php';
$locValues =& _civicrm_location_get(array('version' => '3.0', 'contact_id' => $householdContactID));
$query = "\nSELECT cc.id as id,ca.id address_id \nFROM civicrm_contact cc LEFT JOIN civicrm_address ca ON cc.id = ca.contact_id \nWHERE mail_to_household_id = {$householdContactID};";
$contact = CRM_Core_DAO::executeQuery($query);
$query = "UPDATE civicrm_address ca, civicrm_contact cc\nSET is_primary = 0 \nWHERE ca.contact_id = cc.id AND mail_to_household_id = {$householdContactID};";
$update = CRM_Core_DAO::singleValueQuery($query);
if (CRM_Utils_Array::value('address', $locValues) && count($locValues['address'])) {
while ($contact->fetch()) {
$locParams = array('contact_id' => $contact->id, 'address' => array(1 => $locValues['address'][1]));
// removing unwanted ids from the params array
foreach (array('timezone', 'contact_id') as $fld) {
if (isset($locParams['address'][1][$fld])) {
unset($locParams['address'][1][$fld]);
}
}
$locParams['address'][1]['id'] = $contact->address_id;
CRM_Core_BAO_Location::create($locParams);
}
}
}