本文整理汇总了PHP中CRM_Core_BAO_Location::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Location::add方法的具体用法?PHP CRM_Core_BAO_Location::add怎么用?PHP CRM_Core_BAO_Location::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Location
的用法示例。
在下文中一共展示了CRM_Core_BAO_Location::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: crm_update_location
/**
* Update a specified location with the provided property values.
*
* @param object $contact A valid Contact object (passed by reference).
* @param string $location_id Valid (db-level) id for location to be updated.
* @param Array $params Associative array of property name/value pairs to be updated
*
* @return Location object with updated property values
*
* @access public
*
*/
function crm_update_location(&$contact, $location_id, $params)
{
_crm_initialize();
if (!isset($contact->id)) {
return _crm_error('$contact is not valid contact datatype');
}
$locationId = (int) $location_id;
if ($locationId == 0) {
return _crm_error('missing or invalid $location_id');
}
// $locationNumber is the contact-level number of the location (1, 2, 3, etc.)
$locationNumber = null;
$locations =& crm_get_locations($contact);
foreach ($locations as $locNumber => $locValue) {
if ($locValue->id == $locationId) {
$locationNumber = $locNumber;
break;
}
}
if (!$locationNumber) {
return _crm_error('invalid $location_id');
}
$values = array('contact_id' => $contact->id, 'location' => array($locationNumber => array()));
$loc =& $values['location'][$locationNumber];
$loc['address'] = array();
require_once 'CRM/Core/DAO/Address.php';
$fields =& CRM_Core_DAO_Address::fields();
_crm_store_values($fields, $params, $loc['address']);
//$ids = array( 'county', 'country_id', 'state_province_id', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name' );
$ids = array('county', 'country_id', 'country', 'state_province_id', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name', 'street_address');
foreach ($ids as $id) {
if (array_key_exists($id, $params)) {
$loc['address'][$id] = $params[$id];
}
}
if (is_numeric($loc['address']['state_province'])) {
$loc['address']['state_province'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($loc['address']['state_province']);
}
if (is_numeric($loc['address']['country'])) {
$loc['address']['country'] = CRM_Core_PseudoConstant::countryIsoCode($loc['address']['country']);
}
if (array_key_exists('location_type_id', $params)) {
$loc['location_type_id'] = $params['location_type_id'];
}
if (array_key_exists('location_type', $params)) {
$locTypes =& CRM_Core_PseudoConstant::locationType();
$loc['location_type_id'] = CRM_Utils_Array::key($params['location_type'], $locTypes);
}
if (array_key_exists('name', $params)) {
$loc['name'] = $params['name'];
}
if (array_key_exists('is_primary', $params)) {
$loc['is_primary'] = (int) $params['is_primary'];
}
$loc['id'] = $locationId;
$blocks = array('Email', 'Phone', 'IM');
foreach ($blocks as $block) {
$name = strtolower($block);
$loc[$name] = array();
if ($params[$name]) {
$count = 1;
foreach ($params[$name] as $val) {
CRM_Core_DAO::storeValues($val, $loc[$name][$count++]);
}
}
}
$par = array('id' => $contact->id, 'contact_id' => $contact->id);
$contact = CRM_Contact_BAO_Contact::retrieve($par, $defaults, $ids);
CRM_Contact_BAO_Contact::resolveDefaults($values, true);
$location = CRM_Core_BAO_Location::add($values, $ids, $locationNumber);
return $location;
}
示例2: postProcess
/**
* Process the form when submitted
*
* @return void
* @access public
*/
function postProcess()
{
require_once 'CRM/Core/BAO/Domain.php';
$params = array();
$params = $this->exportValues();
$params['domain_id'] = $this->_id;
$domain = CRM_Core_BAO_Domain::edit($params, $this->_id);
$location = array();
for ($locationId = 1; $locationId <= CRM_CONTACT_FORM_DOMAIN_LOCATION_BLOCKS; $locationId++) {
// start of for loop for location
$location[$locationId] = CRM_Core_BAO_Location::add($params, $this->_ids, $locationId);
}
CRM_Core_Session::setStatus(ts('The Domain "%1" has been saved.', array(1 => $domain->name)));
}
示例3: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
function postProcess()
{
$emailAddress = null;
if ($this->_single) {
$emailAddress = $this->controller->exportValue('Email', 'to');
}
if ($this->_noEmails) {
$emailAddress = $this->controller->exportValue('Email', 'emailAddress');
// for adding the email-id to the primary address
$cid = CRM_Utils_Request::retrieve('cid', $this, false);
if ($cid) {
$location =& CRM_Contact_BAO_Contact::getEmailDetails($cid);
if ($location[3]) {
$locationID = $location[3];
$email =& new CRM_Core_DAO_Email();
$email->location_id = $locationID;
$email->is_primary = 1;
$email->email = $emailAddress;
$email->save();
} else {
require_once 'CRM/Core/BAO/LocationType.php';
$ids = $params = $locID = array();
$params['contact_id'] = $cid;
$locType = CRM_Core_BAO_LocationType::getDefault();
$params['location'][1]['location_type_id'] = $locType->id;
$params['location'][1]['is_primary'] = 1;
$params['location'][1]['email'][1]['email'] = $emailAddress;
CRM_Core_BAO_Location::add($params, $ids, 1);
}
}
}
$subject = $this->controller->exportValue('Email', 'subject');
$message = $this->controller->exportValue('Email', 'message');
require_once 'CRM/Core/BAO/EmailHistory.php';
list($total, $sent, $notSent) = CRM_Core_BAO_EmailHistory::sendEmail($this->_contactIds, $subject, $message, $emailAddress);
$status = array('', ts('Total Selected Contact(s): %1', array(1 => $total)));
if ($sent) {
$status[] = ts('Email sent to contact(s): %1', array(1 => $sent));
}
if ($notSent) {
$status[] = ts('Email not sent to contact(s) (no email address on file or communication preferences specify DO NOT EMAIL): %1', array(1 => $notSent));
}
CRM_Core_Session::setStatus($status);
}
示例4: str_replace
/**
* 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 array $ids the array that holds all the db ids
* @param int $maxLocationBlocks the maximum number of location blocks to process
*
* @return object CRM_Contact_BAO_Contact object
* @access public
* @static
*/
function &create(&$params, &$ids, $maxLocationBlocks)
{
require_once 'CRM/Utils/Hook.php';
if (CRM_Utils_Array::value('contact', $ids)) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $ids['contact'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params);
}
CRM_Core_DAO::transaction('BEGIN');
$contact = CRM_Contact_BAO_Contact::add($params, $ids);
$params['contact_id'] = $contact->id;
// invoke the add operator on the contact_type class
require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_BAO_" . $params['contact_type']) . ".php";
eval('$contact->contact_type_object =& CRM_Contact_BAO_' . $params['contact_type'] . '::add($params, $ids);');
$location = array();
for ($locationId = 1; $locationId <= $maxLocationBlocks; $locationId++) {
// start of for loop for location
$location[$locationId] = CRM_Core_BAO_Location::add($params, $ids, $locationId);
}
$contact->location = $location;
// add notes
if (CRM_Utils_Array::value('note', $params)) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note']);
CRM_Core_BAO_Note::add($noteParams);
}
} else {
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $params['note']);
CRM_Core_BAO_Note::add($noteParams);
}
}
// update the UF email if that has changed
require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::updateUFEmail($contact->id);
// add custom field values
if (CRM_Utils_Array::value('custom', $params)) {
foreach ($params['custom'] as $customValue) {
$cvParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $contact->id, 'value' => $customValue['value'], 'type' => $customValue['type'], 'custom_field_id' => $customValue['custom_field_id']);
if ($customValue['id']) {
$cvParams['id'] = $customValue['id'];
}
CRM_Core_BAO_CustomValue::create($cvParams);
}
}
// make a civicrm_subscription_history entry only on contact create (CRM-777)
if (!CRM_Utils_Array::value('contact', $ids)) {
$subscriptionParams = array('contact_id' => $contact->id, 'status' => 'Added', 'method' => 'Admin');
CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams);
}
CRM_Core_DAO::transaction('COMMIT');
if (CRM_Utils_Array::value('contact', $ids)) {
CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact);
} else {
CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact);
}
$contact->contact_type_display = CRM_Contact_DAO_Contact::tsEnum('contact_type', $contact->contact_type);
return $contact;
}