本文整理汇总了PHP中CRM_Contact_BAO_Contact::retrieve方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Contact::retrieve方法的具体用法?PHP CRM_Contact_BAO_Contact::retrieve怎么用?PHP CRM_Contact_BAO_Contact::retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Contact
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Contact::retrieve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* View summary details of a contact
*
* @return void
* @access public
*/
function view()
{
$params = array();
$defaults = array();
$ids = array();
$params['id'] = $params['contact_id'] = $this->_contactId;
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
$this->assign('pageTitle', $contact->sort_name);
return parent::view();
}
示例2: preProcess
public function preProcess()
{
$params = $defaults = $ids = array();
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$params['id'] = $params['contact_id'] = $this->_contactId;
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
$this->_displayName = $contact->display_name;
$this->_email = $contact->email;
CRM_Utils_System::setTitle(ts('Create User Record for %1', array(1 => $this->_displayName)));
}
示例3: delete
/**
* @param bool $useWhere
*
* @return mixed|void
*/
public function delete($useWhere = FALSE)
{
$this->load_associations();
$contacts_to_delete = array();
foreach ($this->participants as $participant) {
$defaults = array();
$params = array('id' => $participant->contact_id);
$temporary_contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults);
if ($temporary_contact->is_deleted) {
$contacts_to_delete[$temporary_contact->id] = 1;
}
$participant->delete();
}
foreach (array_keys($contacts_to_delete) as $contact_id) {
CRM_Contact_BAO_Contact::deleteContact($contact_id);
}
return parent::delete();
}
示例4: testRetrieve
/**
* test case for retrieve( )
* test with all values.
*/
function testRetrieve()
{
//take the common contact params
$params = $this->contactParams();
$params['note'] = 'test note';
$params['create_employer'] = 'Yahoo';
require_once 'CRM/Contact/BAO/Contact.php';
//create the contact with given params.
$contact = CRM_Contact_BAO_Contact::create($params);
//Now check $contact is object of contact DAO..
$this->assertType('CRM_Contact_DAO_Contact', $contact, 'Check for created object');
$contactId = $contact->id;
//create employee of relationship.
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contactId, $params['create_employer']);
//retrieve the contact values from database.
$values = array();
$searchParams = array('contact_id' => $contactId);
$retrieveContact = CRM_Contact_BAO_Contact::retrieve($searchParams, $values);
//Now check $retrieveContact is object of contact DAO..
$this->assertType('CRM_Contact_DAO_Contact', $retrieveContact, 'Check for retrieve object');
//Now check the ids.
$this->assertEquals($contactId, $retrieveContact->id, 'Check for contact id');
//Now check values retrieve from database with params.
$this->assertEquals($params['first_name'], $values['first_name'], 'Check for first name creation.');
$this->assertEquals($params['last_name'], $values['last_name'], 'Check for last name creation.');
$this->assertEquals($params['contact_type'], $values['contact_type'], 'Check for contact type creation.');
//Now check values of address
// $this->assertAttributesEquals( CRM_Utils_Array::value( 'address', $params ),
// CRM_Utils_Array::value( 'address', $values ) );
//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']));
//Now check values of Note Count.
$this->assertEquals(1, $values['noteTotalCount'], 'Check for total note count');
foreach ($values['note'] as $key => $val) {
$retrieveNote = CRM_Utils_Array::value('note', $val);
//check the note value
$this->assertEquals($params['note'], $retrieveNote, 'Check for note');
}
//Now check values of Relationship Count.
$this->assertEquals(1, $values['relationship']['totalCount'], 'Check for total relationship count');
foreach ($values['relationship']['data'] as $key => $val) {
//Now check values of Relationship organization.
$this->assertEquals($params['create_employer'], $val['name'], 'Check for organization');
//Now check values of Relationship type.
$this->assertEquals('Employee of', $val['relation'], 'Check for relationship type');
//delete the organization.
Contact::delete(CRM_Utils_Array::value('cid', $val));
}
//cleanup DB by deleting the contact
Contact::delete($contactId);
}
示例5: preProcess
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/
function preProcess()
{
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add');
$this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
$this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
$session =& CRM_Core_Session::singleton();
if ($this->_action == CRM_Core_Action::ADD) {
// check for add contacts permissions
require_once 'CRM/Core/Permission.php';
if (!CRM_Core_Permission::check('add contacts')) {
CRM_Utils_System::permissionDenied();
return;
}
$this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, true, null, 'REQUEST');
if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) {
CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
}
$this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this);
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, false, null, 'GET');
$this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, false, null, 'GET');
if ($this->_contactSubType) {
CRM_Utils_System::setTitle(ts('New %1', array(1 => $this->_contactSubType)));
} else {
$title = ts('New Individual');
if ($this->_contactType == 'Household') {
$title = ts('New Household');
} else {
if ($this->_contactType == 'Organization') {
$title = ts('New Organization');
}
}
CRM_Utils_System::setTitle($title);
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
$this->_contactId = null;
} else {
//update mode
if (!$this->_contactId) {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true);
}
if ($this->_contactId) {
require_once 'CRM/Contact/BAO/Contact.php';
$contact =& new CRM_Contact_DAO_Contact();
$contact->id = $this->_contactId;
if (!$contact->find(true)) {
CRM_Core_Error::statusBounce(ts('contact does not exist: %1', array(1 => $this->_contactId)));
}
$this->_contactType = $contact->contact_type;
$this->_contactSubType = $contact->contact_sub_type;
// check for permissions
require_once 'CRM/Contact/BAO/Contact/Permission.php';
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
}
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId));
$values = $this->get('values');
// get contact values.
if (!empty($values)) {
$this->_values = $values;
} else {
$params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId);
$contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, true);
$this->set('values', $this->_values);
}
} else {
CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
}
}
$this->_editOptions = $this->get('contactEditOptions');
if (CRM_Utils_System::isNull($this->_editOptions)) {
require_once 'CRM/Core/BAO/Preferences.php';
$this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options', true, null, false, 'name', true, 'AND v.filter = 0');
$this->set('contactEditOptions', $this->_editOptions);
}
// build demographics only for Individual contact type
if ($this->_contactType != 'Individual' && array_key_exists('Demographics', $this->_editOptions)) {
unset($this->_editOptions['Demographics']);
}
// in update mode don't show notes
if ($this->_contactId && array_key_exists('Notes', $this->_editOptions)) {
unset($this->_editOptions['Notes']);
}
$this->assign('editOptions', $this->_editOptions);
$this->assign('contactType', $this->_contactType);
$this->assign('contactSubType', $this->_contactSubType);
// get the location blocks.
$this->_blocks = $this->get('blocks');
if (CRM_Utils_System::isNull($this->_blocks)) {
$this->_blocks = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options', true, null, false, 'name', true, 'AND v.filter = 1');
$this->set('blocks', $this->_blocks);
}
$this->assign('blocks', $this->_blocks);
//.........这里部分代码省略.........
示例6: formatParams
/**
* format params for update and fill mode
*
* @param $params array referance to an array containg all the
* values for import
* @param $onDuplicate int
* @param $cid int contact id
*/
function formatParams(&$params, $onDuplicate, $cid)
{
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
return;
}
$contactParams = array('contact_id' => $cid);
$defaults = array();
$contactObj = CRM_Contact_BAO_Contact::retrieve($contactParams, $defaults);
$modeUpdate = $modeFill = false;
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
$modeUpdate = true;
}
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) {
$modeFill = true;
}
require_once 'CRM/Core/BAO/CustomGroup.php';
$groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], CRM_Core_DAO::$_nullObject, $cid, 0, null);
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, false, false);
$contact = get_object_vars($contactObj);
$location = null;
foreach ($params as $key => $value) {
if ($key == 'id' || $key == 'contact_type') {
continue;
}
if ($key == 'location') {
$location = true;
} else {
if (in_array($key, array('email_greeting', 'postal_greeting', 'addressee'))) {
// CRM-4575, need to null custom
if ($params["{$key}_id"] != 4) {
$params["{$key}_custom"] = 'null';
}
unset($params[$key]);
} else {
if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) {
$custom = true;
} else {
$getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $key);
if ($key == 'contact_source') {
$params['source'] = $params[$key];
unset($params[$key]);
}
if ($modeFill && isset($getValue)) {
unset($params[$key]);
}
}
}
}
}
if ($location) {
for ($loc = 1; $loc <= count($params['location']); $loc++) {
//if location block is already present for the contact
//then do not fill any data for that location type, CRM-4424
if ($modeFill) {
foreach ($contact['location'] as $location => $locationDetails) {
$getValue = CRM_Utils_Array::value('location_type_id', $locationDetails);
if (isset($getValue) && $getValue == $params['location'][$loc]['location_type_id']) {
unset($params['location'][$loc]);
break;
}
}
}
if (array_key_exists('address', $contact['location'][$loc])) {
$fields = array('street_address', 'city', 'state_province_id', 'postal_code', 'postal_code_suffix', 'country_id');
foreach ($fields as $field) {
$getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc]['address'], $field);
if ($modeFill && isset($getValue)) {
unset($params['location'][$loc]['address'][$field]);
}
}
}
$fields = array('email' => 'email', 'phone' => 'phone', 'im' => 'name');
foreach ($fields as $key => $field) {
if (array_key_exists($key, $contact['location'][$loc])) {
for ($c = 1; $c <= count($params['location'][$loc][$key]); $c++) {
$getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc][$key][$c], $field);
if ($modeFill && isset($getValue)) {
unset($params['location'][$loc][$key][$c][$field]);
}
}
}
}
}
}
}
示例7: run
/**
* Heart of the vCard data assignment process.
*
* The runner gets all the metadata for the contact and calls the writeVcard method to output the vCard
* to the user.
*/
public function run()
{
$this->preProcess();
$params = array();
$defaults = array();
$ids = array();
$params['id'] = $params['contact_id'] = $this->_contactId;
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
// now that we have the contact's data - let's build the vCard
// TODO: non-US-ASCII support (requires changes to the Contact_Vcard_Build class)
$vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name'));
$vcard = new Contact_Vcard_Build('2.1');
if ($defaults['contact_type'] == 'Individual') {
$vcard->setName(CRM_Utils_Array::value('last_name', $defaults), CRM_Utils_Array::value('first_name', $defaults), CRM_Utils_Array::value('middle_name', $defaults), CRM_Utils_Array::value('prefix', $defaults), CRM_Utils_Array::value('suffix', $defaults));
$organizationName = CRM_Utils_Array::value('organization_name', $defaults);
if ($organizationName !== NULL) {
$vcard->addOrganization($organizationName);
}
} elseif ($defaults['contact_type'] == 'Organization') {
$vcard->setName($defaults['organization_name'], '', '', '', '');
} elseif ($defaults['contact_type'] == 'Household') {
$vcard->setName($defaults['household_name'], '', '', '', '');
}
$vcard->setFormattedName($defaults['display_name']);
$vcard->setSortString($defaults['sort_name']);
if (!empty($defaults['nick_name'])) {
$vcard->addNickname($defaults['nick_name']);
}
if (!empty($defaults['job_title'])) {
$vcard->setTitle($defaults['job_title']);
}
if (!empty($defaults['birth_date_display'])) {
$vcard->setBirthday(CRM_Utils_Array::value('birth_date_display', $defaults));
}
if (!empty($defaults['home_URL'])) {
$vcard->setURL($defaults['home_URL']);
}
// TODO: $vcard->setGeo($lat, $lon);
if (!empty($defaults['address'])) {
$stateProvices = CRM_Core_PseudoConstant::stateProvince();
$countries = CRM_Core_PseudoConstant::country();
foreach ($defaults['address'] as $location) {
// we don't keep PO boxes in separate fields
$pob = '';
$extend = CRM_Utils_Array::value('supplemental_address_1', $location);
if (!empty($location['supplemental_address_2'])) {
$extend .= ', ' . $location['supplemental_address_2'];
}
$street = CRM_Utils_Array::value('street_address', $location);
$locality = CRM_Utils_Array::value('city', $location);
$region = NULL;
if (!empty($location['state_province_id'])) {
$region = $stateProvices[CRM_Utils_Array::value('state_province_id', $location)];
}
$country = NULL;
if (!empty($location['country_id'])) {
$country = $countries[CRM_Utils_Array::value('country_id', $location)];
}
$postcode = CRM_Utils_Array::value('postal_code', $location);
if (!empty($location['postal_code_suffix'])) {
$postcode .= '-' . $location['postal_code_suffix'];
}
$vcard->addAddress($pob, $extend, $street, $locality, $region, $postcode, $country);
$vcardName = $vcardNames[$location['location_type_id']];
if ($vcardName) {
$vcard->addParam('TYPE', $vcardName);
}
if (!empty($location['is_primary'])) {
$vcard->addParam('TYPE', 'PREF');
}
}
}
if (!empty($defaults['phone'])) {
foreach ($defaults['phone'] as $phone) {
$vcard->addTelephone($phone['phone']);
$vcardName = $vcardNames[$phone['location_type_id']];
if ($vcardName) {
$vcard->addParam('TYPE', $vcardName);
}
if ($phone['is_primary']) {
$vcard->addParam('TYPE', 'PREF');
}
}
}
if (!empty($defaults['email'])) {
foreach ($defaults['email'] as $email) {
$vcard->addEmail($email['email']);
$vcardName = $vcardNames[$email['location_type_id']];
if ($vcardName) {
$vcard->addParam('TYPE', $vcardName);
}
if ($email['is_primary']) {
$vcard->addParam('TYPE', 'PREF');
}
//.........这里部分代码省略.........
示例8: postProcess
function postProcess()
{
if (!array_key_exists('event', $this->_submitValues)) {
return;
}
// XXX de facto primary key
$email_to_contact_id = array();
foreach ($this->_submitValues['event'] as $event_id => $participants) {
foreach ($participants['participant'] as $participant_id => $fields) {
if (array_key_exists($fields['email'], $email_to_contact_id)) {
$contact_id = $email_to_contact_id[$fields['email']];
} else {
$contact_id = self::find_or_create_contact($this->getContactID(), $fields);
$email_to_contact_id[$fields['email']] = $contact_id;
}
$participant = $this->cart->get_event_in_cart_by_event_id($event_id)->get_participant_by_id($participant_id);
if ($participant->contact_id && $contact_id != $participant->contact_id) {
$defaults = array();
$params = array('id' => $participant->contact_id);
$temporary_contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults);
foreach ($this->cart->get_subparticipants($participant) as $subparticipant) {
$subparticipant->contact_id = $contact_id;
$subparticipant->save();
}
$participant->contact_id = $contact_id;
$participant->save();
if ($temporary_contact->is_deleted) {
#ARGH a permissions check prevents us from using skipUndelete,
#so we potentially leave records pointing to this contact for now
#CRM_Contact_BAO_Contact::deleteContact($temporary_contact->id);
$temporary_contact->delete();
}
}
//TODO security check that participant ids are already in this cart
$participant_params = array('id' => $participant_id, 'cart_id' => $this->cart->id, 'event_id' => $event_id, 'contact_id' => $contact_id, 'email' => $fields['email']);
$participant = new CRM_Event_Cart_BAO_MerParticipant($participant_params);
$participant->save();
$this->cart->add_participant_to_cart($participant);
if (array_key_exists('field', $this->_submitValues) && array_key_exists($participant_id, $this->_submitValues['field'])) {
$custom_fields = array_merge($participant->get_form()->get_participant_custom_data_fields());
CRM_Contact_BAO_Contact::createProfileContact($this->_submitValues['field'][$participant_id], $custom_fields, $contact_id);
}
}
}
$this->cart->save();
}
示例9: preProcess
/**
* Heart of the viewing process. The runner gets all the meta data for
* the contact and calls the appropriate type of page to view.
*
* @return void
* @access public
*
*/
function preProcess()
{
parent::preProcess();
// we need to retrieve privacy preferences
// to (un)display the 'Send an Email' link
$params = array();
$defaults = array();
$ids = array();
$params['id'] = $params['contact_id'] = $this->_contactId;
CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
CRM_Contact_BAO_Contact::resolveDefaults($defaults);
$this->assign($defaults);
}
示例10: exportComponents
//.........这里部分代码省略.........
foreach ($value as $ltype => $val) {
foreach (array_keys($val) as $fld) {
$type = explode('-', $fld);
$fldValue = "{$ltype}-" . $type[0];
if (CRM_Utils_Array::value(1, $type)) {
$fldValue .= "-" . $type[1];
}
$row[$fldValue] = $dao->{$fldValue};
}
}
} else {
if (array_key_exists($field, $contactRelationshipTypes)) {
list($id, $direction) = explode('_', $field, 2);
require_once 'api/v2/Relationship.php';
require_once 'CRM/Contact/BAO/Contact.php';
require_once 'CRM/Core/BAO/CustomValueTable.php';
require_once 'CRM/Core/BAO/CustomQuery.php';
$params['relationship_type_id'] = $contactRelationshipTypes[$field];
$contact_id['contact_id'] = $dao->contact_id;
//Get relationships
$val = civicrm_contact_relationship_get($contact_id, null, $params);
if (is_array($val['result'])) {
asort($val['result']);
}
$is_valid = null;
$data = null;
if ($val['result']) {
foreach ($val['result'] as $k => $v) {
//consider only active relationships
if ($v['is_active'] && $v['rtype'] == $direction) {
$cID['contact_id'] = $v['cid'];
if ($cID) {
//Get Contact Details
$data = CRM_Contact_BAO_Contact::retrieve($cID, $defaults);
}
$is_valid = true;
break;
}
}
}
$relCustomIDs = array();
foreach ($value as $relationkey => $relationvalue) {
if ($val['result'] && ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey))) {
foreach ($val['result'] as $k1 => $v1) {
$contID = $v1['cid'];
$param1 = array('entityID' => $contID, $relationkey => 1);
$getcustomValue = CRM_Core_BAO_CustomValueTable::getValues($param1);
$custom_ID = CRM_Core_BAO_CustomField::getKeyID($relationkey);
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey)) {
if (empty($query->_options)) {
$relCustomIDs[$cfID] = array();
$relQuery = new CRM_Core_BAO_CustomQuery($relCustomIDs);
$relQuery->query();
$relOptions = $relQuery->_options;
} else {
$relOptions = $query->_options;
}
$custom_data = CRM_Core_BAO_CustomField::getDisplayValue($getcustomValue[$relationkey], $cfID, $relOptions);
} else {
$custom_data = '';
}
}
}
//Get all relationships type custom fields
list($id, $atype, $btype) = explode('_', $field);
$relCustomData = CRM_Core_BAO_CustomField::getFields('Relationship', null, null, $id, null, null);
示例11: setDefaultValues
function setDefaultValues()
{
if ($this->_cdType) {
return CRM_Custom_Form_CustomData::setDefaultValues($this);
}
$defaults = $this->_values;
//set defaults for pledge payment.
if ($this->_ppID) {
$defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']);
$defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues);
$defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues);
$defaults['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_pledgeValues);
$defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues);
$defaults['option_type'] = 1;
}
$fields = array();
if ($this->_action & CRM_Core_Action::DELETE) {
return $defaults;
}
// set soft credit defaults
CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this);
if ($this->_mode) {
$config = CRM_Core_Config::singleton();
// set default country from config if no country set
if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) {
$defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
}
if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $defaults)) {
$defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
}
$billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
$defaults = array_merge($defaults, $billingDefaults);
// now fix all state country selectors, set correct state based on country
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
}
if ($this->_id) {
$this->_contactID = $defaults['contact_id'];
}
// Set $newCredit variable in template to control whether link to credit card mode is included
CRM_Core_Payment::allowBackofficeCreditCard($this);
// fix the display of the monetary value, CRM-4038
if (isset($defaults['total_amount'])) {
$defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
}
if (isset($defaults['non_deductible_amount'])) {
$defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a');
}
if (isset($defaults['fee_amount'])) {
$defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a');
}
if (isset($defaults['net_amount'])) {
$defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a');
}
if ($this->_contributionType) {
$defaults['financial_type_id'] = $this->_contributionType;
}
if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) {
$defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
}
if (CRM_Utils_Array::value('is_test', $defaults)) {
$this->assign('is_test', TRUE);
}
if (isset($defaults['honor_contact_id'])) {
$honorDefault = $ids = array();
$this->_honorID = $defaults['honor_contact_id'];
$honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
$idParams = array('id' => $defaults['honor_contact_id'], 'contact_id' => $defaults['honor_contact_id']);
CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids);
$defaults['honor_prefix_id'] = CRM_Utils_Array::value('prefix_id', $honorDefault);
$defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault);
$defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault);
$defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]);
$defaults['honor_type'] = $honorType[$defaults['honor_type_id']];
}
$this->assign('showOption', TRUE);
// for Premium section
if ($this->_premiumID) {
$this->assign('showOption', FALSE);
$options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
if (!$options) {
$this->assign('showOption', TRUE);
}
$options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options);
if ($options_key) {
$defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key));
} else {
$defaults['product_name'] = array($this->_productDAO->product_id);
}
if ($this->_productDAO->fulfilled_date) {
list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date);
}
}
if (isset($this->userEmail)) {
$this->assign('email', $this->userEmail);
}
if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
$this->assign('is_pay_later', TRUE);
}
$this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
$dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
//.........这里部分代码省略.........
示例12: setDefaultValues
function setDefaultValues()
{
if ($this->_cdType) {
return CRM_Custom_Form_CustomData::setDefaultValues($this);
}
$defaults = $this->_values;
//set defaults for pledge payment.
if ($this->_ppID) {
$defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']);
$defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues);
$defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues);
$defaults['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_pledgeValues);
}
$fields = array();
if ($this->_action & CRM_Core_Action::DELETE) {
return $defaults;
}
if ($this->_mode) {
$billingFields = array();
foreach ($this->_fields as $name => $dontCare) {
if (strpos($name, 'billing_') === 0) {
$name = $idName = substr($name, 8);
if (in_array($name, array("state_province_id-{$this->_bltID}", "country_id-{$this->_bltID}"))) {
$name = str_replace('_id', '', $name);
}
$billingFields[$name] = "billing_" . $idName;
}
$fields[$name] = 1;
}
require_once "CRM/Core/BAO/UFGroup.php";
if ($this->_contactID) {
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults);
}
foreach ($billingFields as $name => $billingName) {
$defaults[$billingName] = $defaults[$name];
}
}
if ($this->_id) {
$this->_contactID = $defaults['contact_id'];
} else {
list($defaults['receive_date']) = CRM_Utils_Date::setDateDefaults();
}
require_once 'CRM/Utils/Money.php';
// fix the display of the monetary value, CRM-4038
if (isset($defaults['total_amount'])) {
$defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], null, '%a');
}
if (isset($defaults['non_deductible_amount'])) {
$defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], null, '%a');
}
if (isset($defaults['fee_amount'])) {
$defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], null, '%a');
}
if (isset($defaults['net_amount'])) {
$defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], null, '%a');
}
if ($this->_contributionType) {
$defaults['contribution_type_id'] = $this->_contributionType;
}
if (CRM_Utils_Array::value('is_test', $defaults)) {
$this->assign("is_test", true);
}
if (isset($defaults["honor_contact_id"])) {
$honorDefault = array();
$ids = array();
$this->_honorID = $defaults["honor_contact_id"];
$honorType = CRM_Core_PseudoConstant::honor();
$idParams = array('id' => $defaults["honor_contact_id"], 'contact_id' => $defaults["honor_contact_id"]);
CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids);
$defaults["honor_prefix_id"] = $honorDefault["prefix_id"];
$defaults["honor_first_name"] = CRM_Utils_Array::value("first_name", $honorDefault);
$defaults["honor_last_name"] = CRM_Utils_Array::value("last_name", $honorDefault);
$defaults["honor_email"] = CRM_Utils_Array::value("email", $honorDefault["location"][1]["email"][1]);
$defaults["honor_type"] = $honorType[$defaults["honor_type_id"]];
}
$this->assign('showOption', true);
// for Premium section
if ($this->_premiumID) {
$this->assign('showOption', false);
$options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
if (!$options) {
$this->assign('showOption', true);
}
$options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options);
if ($options_key) {
$defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key));
} else {
$defaults['product_name'] = array($this->_productDAO->product_id);
}
list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date);
}
if (isset($this->userEmail)) {
$this->assign('email', $this->userEmail);
}
if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
$this->assign('is_pay_later', true);
}
$this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
$dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
foreach ($dates as $key) {
//.........这里部分代码省略.........
示例13: 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;
}
示例14: dataRule
/**
* Function for validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @return mixed true or array of errors
* @access public
* @static
*/
function dataRule(&$params, &$files, &$options)
{
if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) {
return true;
}
$errors = array();
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getCurrentDomain();
$mailing = null;
$session =& CRM_Core_Session::singleton();
$values = array('contact_id' => $session->get('userID'));
$contact = array();
$ids = array();
CRM_Contact_BAO_Contact::retrieve($values, $contact, $id);
$verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'owner'));
foreach ($verp as $key => $value) {
$verp[$key]++;
}
$urls = array_flip(array('forward'));
foreach ($urls as $key => $value) {
$urls[$key]++;
}
require_once 'CRM/Mailing/BAO/Component.php';
$header =& new CRM_Mailing_BAO_Component();
$header->id = $params['header_id'];
$header->find(true);
$footer =& new CRM_Mailing_BAO_Component();
$footer->id = $params['footer_id'];
$footer->find(true);
list($headerBody['htmlFile'], $headerBody['textFile']) = array($header->body_html, $header->body_text);
list($footerBody['htmlFile'], $footerBody['textFile']) = array($footer->body_html, $footer->body_text);
require_once 'CRM/Utils/Token.php';
if (!file_exists($files['textFile']['tmp_name'])) {
$errors['textFile'] = ts('Please provide at least the text message.');
}
foreach (array('textFile', 'htmlFile') as $file) {
if (!file_exists($files[$file]['tmp_name'])) {
continue;
}
$str = file_get_contents($files[$file]['tmp_name']);
$name = $files[$file]['name'];
/* append header/footer */
$str = $headerBody[$file] . $str . $footerBody[$file];
$dataErrors = array();
/* First look for missing tokens */
$err = CRM_Utils_Token::requiredTokens($str);
if ($err !== true) {
foreach ($err as $token => $desc) {
$dataErrors[] = '<li>' . ts('Missing required token') . ' {' . $token . "}: {$desc}</li>";
}
}
/* Do a full token replacement on a dummy verp, the current contact
* and domain. */
$str = CRM_Utils_Token::replaceDomainTokens($str, $domain);
$str = CRM_Utils_Token::replaceMailingTokens($str, $mailing);
$str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls);
$str = CRM_Utils_Token::replaceContactTokens($str, $contact);
$unmatched = CRM_Utils_Token::unmatchedTokens($str);
if (!empty($unmatched)) {
foreach ($unmatched as $token) {
$dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>';
}
}
if (!empty($dataErrors)) {
$errors[$file] = ts('The following errors were detected in %1:', array(1 => $name)) . ': <ul>' . implode('', $dataErrors) . '</ul>';
}
}
return empty($errors) ? true : $errors;
}
示例15: sendMail
function sendMail(&$input, &$ids, &$objects, &$values, $recur = false, $returnMessageText = false)
{
$contribution =& $objects['contribution'];
$membership =& $objects['membership'];
$participant =& $objects['participant'];
$event =& $objects['event'];
if (empty($values)) {
$values = array();
if ($input['component'] == 'contribute') {
require_once 'CRM/Contribute/BAO/ContributionPage.php';
if (isset($contribution->contribution_page_id)) {
CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
} else {
// Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id)
$values['is_email_receipt'] = 1;
$values['title'] = 'Contribution';
}
} else {
// event
$eventParams = array('id' => $objects['event']->id);
$values['event'] = array();
require_once 'CRM/Event/BAO/Event.php';
CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
$eventParams = array('id' => $objects['event']->id);
$values['event'] = array();
require_once 'CRM/Event/BAO/Event.php';
CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
//get location details
$locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event');
require_once 'CRM/Core/BAO/Location.php';
require_once 'CRM/Event/Form/ManageEvent/Location.php';
$values['location'] = CRM_Core_BAO_Location::getValues($locationParams);
require_once 'CRM/Core/BAO/UFJoin.php';
$ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'weight' => 1);
$values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
$ufJoinParams['weight'] = 2;
$values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
}
}
$template =& CRM_Core_Smarty::singleton();
// CRM_Core_Error::debug('tpl',$template);
//assign honor infomation to receiptmessage
if ($honarID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'honor_contact_id')) {
$honorDefault = array();
$honorIds = array();
$honorIds['contribution'] = $contribution->id;
$idParams = array('id' => $honarID, 'contact_id' => $honarID);
require_once "CRM/Contact/BAO/Contact.php";
CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds);
require_once "CRM/Core/PseudoConstant.php";
$honorType = CRM_Core_PseudoConstant::honor();
$prefix = CRM_Core_PseudoConstant::individualPrefix();
$template->assign('honor_block_is_active', 1);
$template->assign('honor_prefix', $prefix[$honorDefault["prefix_id"]]);
$template->assign('honor_first_name', CRM_Utils_Array::value("first_name", $honorDefault));
$template->assign('honor_last_name', CRM_Utils_Array::value("last_name", $honorDefault));
$template->assign('honor_email', CRM_Utils_Array::value("email", $honorDefault["email"][1]));
$template->assign('honor_type', $honorType[$contribution->honor_type_id]);
}
require_once 'CRM/Contribute/DAO/ContributionProduct.php';
$dao =& new CRM_Contribute_DAO_ContributionProduct();
$dao->contribution_id = $contribution->id;
if ($dao->find(true)) {
$premiumId = $dao->product_id;
$template->assign('option', $dao->product_option);
require_once 'CRM/Contribute/DAO/Product.php';
$productDAO =& new CRM_Contribute_DAO_Product();
$productDAO->id = $premiumId;
$productDAO->find(true);
$template->assign('selectPremium', true);
$template->assign('product_name', $productDAO->name);
$template->assign('price', $productDAO->price);
$template->assign('sku', $productDAO->sku);
}
// add the new contribution values
if ($input['component'] == 'contribute') {
$template->assign('title', $values['title']);
$template->assign('amount', $input['amount']);
//PCP Info
require_once 'CRM/Contribute/DAO/ContributionSoft.php';
$softDAO =& new CRM_Contribute_DAO_ContributionSoft();
$softDAO->contribution_id = $contribution->id;
if ($softDAO->find(true)) {
$template->assign('pcpBlock', true);
$template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll);
$template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname);
$template->assign('pcp_personal_note', $softDAO->pcp_personal_note);
//assign the pcp page title for email subject
require_once 'CRM/Contribute/DAO/PCP.php';
$pcpDAO =& new CRM_Contribute_DAO_PCP();
$pcpDAO->id = $softDAO->pcp_id;
if ($pcpDAO->find(true)) {
$template->assign('title', $pcpDAO->title);
}
}
} else {
$template->assign('title', $values['event']['title']);
$template->assign('totalAmount', $input['amount']);
}
$template->assign('trxn_id', $contribution->trxn_id);
//.........这里部分代码省略.........