本文整理汇总了PHP中CRM_Contact_BAO_Contact::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Contact::create方法的具体用法?PHP CRM_Contact_BAO_Contact::create怎么用?PHP CRM_Contact_BAO_Contact::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Contact
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Contact::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFindByContactIdNoSyncSettings
function testFindByContactIdNoSyncSettings()
{
$params = CRM_CiviMailchimp_UtilsTest::sampleContactParams();
$contact = CRM_Contact_BAO_Contact::create($params);
$mailchimp_sync_settings = CRM_CiviMailchimp_BAO_SyncSettings::findByContactId($contact->id);
$this->assertEmpty($mailchimp_sync_settings);
}
示例2: createOrganisation
/**
* Helper function to create
* a contact of type Organisation
*
* @param null $params
* @return mixed $contactID id of created Organisation
*/
static function createOrganisation($params = NULL)
{
//compose the params, when not passed
if (!$params) {
$organization_name = "My Organization";
$params = array('organization_name' => $organization_name, 'contact_type' => 'Organization');
}
require_once "CRM/Contact/BAO/Contact.php";
$organization = CRM_Contact_BAO_Contact::create($params);
return $organization->id;
}
示例3: postProcess
/**
* process the form
*
* @return void
* @access public
*/
public function postProcess()
{
$params = $this->exportValues();
// Process / save contact info
$params['contact_type'] = $this->_contactType;
$params['contact_id'] = $this->_contactId;
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
CRM_Contact_BAO_Contact::create($params);
$this->response();
}
示例4: testForceCiviToMailchimpSyncNullEmail
function testForceCiviToMailchimpSyncNullEmail()
{
$mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test Group testForceCiviToMailchimpSyncNullEmail');
$params = CRM_CiviMailchimp_UtilsTest::sampleContactParams();
unset($params['email']);
$contact = CRM_Contact_BAO_Contact::create($params);
$contact_ids = array($contact->id);
CRM_Contact_BAO_GroupContact::addContactsToGroup($contact_ids, $mailchimp_sync_setting->civicrm_group_id);
$contacts = CRM_CiviMailchimp_Form_Sync::forceCiviToMailchimpSync($mailchimp_sync_setting);
$mailchimp_api_subscribe = civimailchimp_static('mailchimp_api_subscribe');
$this->assertCount(0, $contacts);
$this->assertNull($mailchimp_api_subscribe);
}
示例5: postProcess
/**
* process the form
*
* @return void
* @access public
*/
public function postProcess()
{
$params = $this->exportValues();
// Process / save contact info
$params['contact_type'] = $this->_contactType;
$params['contact_id'] = $this->_contactId;
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
CRM_Contact_BAO_Contact::create($params);
// Saving current employer affects relationship tab
$this->ajaxResponse['updateTabs'] = array('#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId));
$this->response();
}
示例6: postProcess
/**
* process the form
*
* @return void
* @access public
*/
public function postProcess()
{
$params = $this->exportValues();
// Process / save demographics
if (empty($params['is_deceased'])) {
$params['is_deceased'] = FALSE;
$params['deceased_date'] = NULL;
}
$params['contact_type'] = 'Individual';
$params['contact_id'] = $this->_contactId;
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
CRM_Contact_BAO_Contact::create($params);
$this->response();
}
示例7: postProcess
/**
* Process the form.
*
* @return void
*/
public function postProcess()
{
$params = $this->exportValues();
// Process / save contact info
$params['contact_type'] = $this->_contactType;
$params['contact_id'] = $this->_contactId;
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
CRM_Contact_BAO_Contact::create($params);
// Saving current employer affects relationship tab, and possibly related memberships and contributions
$this->ajaxResponse['updateTabs'] = array('#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId));
if (CRM_Core_Permission::access('CiviContribute')) {
$this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
}
if (CRM_Core_Permission::access('CiviMember')) {
$this->ajaxResponse['updateTabs']['#tab_member'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
}
$this->response();
}
示例8: postProcess
/**
* process the form
*
* @return void
* @access public
*/
public function postProcess()
{
$params = $this->exportValues();
// need to process / save demographics
if (!CRM_Utils_Array::value('is_deceased', $params)) {
$params['is_deceased'] = FALSE;
$params['deceased_date'] = NULL;
}
$params['contact_type'] = 'Individual';
$params['contact_id'] = $this->_contactId;
CRM_Contact_BAO_Contact::create($params);
$response = array('status' => 'save');
$this->postProcessHook();
echo json_encode($response);
CRM_Utils_System::civiExit();
}
示例9: createContactWithTransaction
/**
* Use SQL to INSERT a contact and assert success. Perform
* work within a transaction.
*
* @param string $nesting
* 'reuse-tx'|'nest-tx' how to construct transaction.
* @param string $insert
* 'sql-insert'|'bao-create' how to add the example record.
* @param string $outcome
* 'rollback'|'implicit-commit'|'explicit-commit' how to finish transaction.
* @return int
* cid
*/
public function createContactWithTransaction($nesting, $insert, $outcome)
{
if ($nesting != 'reuse-tx' && $nesting != 'nest-tx') {
throw new RuntimeException('Bad test data: reuse=' . $nesting);
}
if ($insert != 'sql-insert' && $insert != 'bao-create') {
throw new RuntimeException('Bad test data: insert=' . $insert);
}
if ($outcome != 'rollback' && $outcome != 'implicit-commit' && $outcome != 'explicit-commit') {
throw new RuntimeException('Bad test data: outcome=' . $outcome);
}
$tx = new CRM_Core_Transaction($nesting === 'nest-tx');
if ($insert == 'sql-insert') {
$r = CRM_Core_DAO::executeQuery("INSERT INTO civicrm_contact(first_name,last_name) VALUES ('ff', 'll')");
$cid = mysql_insert_id();
} elseif ($insert == 'bao-create') {
$params = array('contact_type' => 'Individual', 'first_name' => 'FF', 'last_name' => 'LL');
$r = CRM_Contact_BAO_Contact::create($params);
$cid = $r->id;
}
$this->cids[] = $cid;
$this->assertContactsExist(array($cid), TRUE);
if ($outcome == 'rollback') {
$tx->rollback();
} elseif ($outcome == 'explicit-commit') {
$tx->commit();
}
// else: implicit-commit
return $cid;
}
示例10: postProcess
/**
* Form submission of new/edit contact is processed.
*
* @access public
*
* @return void
*/
public function postProcess()
{
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$locType = CRM_Core_BAO_LocationType::getDefault();
foreach (array('phone', 'email', 'address') as $locFld) {
if (!empty($this->_defaults[$locFld]) && $this->_defaults[$locFld][1]['location_type_id']) {
$params[$locFld][1]['is_primary'] = $this->_defaults[$locFld][1]['is_primary'];
$params[$locFld][1]['location_type_id'] = $this->_defaults[$locFld][1]['location_type_id'];
} else {
$params[$locFld][1]['is_primary'] = 1;
$params[$locFld][1]['location_type_id'] = $locType->id;
}
}
$params['contact_type'] = $this->_contactType;
$params['contact_id'] = $this->_contactId;
$contact = CRM_Contact_BAO_Contact::create($params, TRUE);
// set status message.
if ($this->_contactId) {
$message = ts('%1 has been updated.', array(1 => $contact->display_name));
} else {
$message = ts('%1 has been created.', array(1 => $contact->display_name));
}
CRM_Core_Session::setStatus($message, ts('Contact Saved'), 'success');
}
示例11: test_civicrm_api3_civi_mailchimp_sync
function test_civicrm_api3_civi_mailchimp_sync()
{
$action = 'subscribeContactToMailchimpList';
$mailchimp_list_id = 'MailchimpListsTestListA';
$mailchimp_interest_groups = array('MailchimpTestInterestGroupingA_MailchimpTestInterestGroupA', 'MailchimpTestInterestGroupingA_MailchimpTestInterestGroupC');
$mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test Group test_civicrm_api3_civi_mailchimp_sync', $mailchimp_list_id, $mailchimp_interest_groups);
$merge_fields = CRM_CiviMailchimp_Utils::getMailchimpMergeFields();
$params = CRM_CiviMailchimp_UtilsTest::sampleContactParams();
$contact = CRM_Contact_BAO_Contact::create($params);
$merge_vars = CRM_CiviMailchimp_Utils::formatMailchimpMergeVars($merge_fields, $contact);
CRM_CiviMailchimp_Utils::addMailchimpSyncQueueItem($action, $mailchimp_list_id, $params['email'][0]['email'], $merge_vars);
$action = 'unsubscribeContactFromMailchimpList';
CRM_CiviMailchimp_Utils::addMailchimpSyncQueueItem($action, $mailchimp_list_id, $params['email'][0]['email'], $merge_vars);
$job_params['records_to_process_per_run'] = 100;
civicrm_api3_civi_mailchimp_sync($job_params);
$queue = CRM_Queue_Service::singleton()->create(array('type' => 'Sql', 'name' => 'mailchimp-sync', 'reset' => FALSE));
$this->assertEquals(0, $queue->numberOfItems());
}
示例12: testClearQueueItem
function testClearQueueItem()
{
$mailchimp_list_id = 'MailchimpListsTestListA';
$mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test Group testClearQueueItem', $mailchimp_list_id);
$group = CRM_CiviMailchimp_Utils::getGroupById($mailchimp_sync_setting->civicrm_group_id);
$params = CRM_CiviMailchimp_UtilsTest::sampleContactParams();
$contact = CRM_Contact_BAO_Contact::create($params);
$queue = CRM_Queue_Service::singleton()->create(array('type' => 'Sql', 'name' => 'mailchimp-sync', 'reset' => TRUE));
civimailchimp_civicrm_contact_removed_from_group($group, $contact);
$item = $queue->claimItem($lease_time = 0);
$existing_mailchimp_sync_log = self::createTestLogMessage('This is a test error message', $details = NULL, $direction = 'civicrm_to_mailchimp', $type = 'error', $item->id);
CRM_CiviMailchimp_BAO_SyncLog::clearQueueItem($item->id);
$query = "\n SELECT\n *\n FROM\n civicrm_queue_item\n WHERE\n queue_name = 'mailchimp-sync'\n AND\n id = %1\n LIMIT 1\n ";
$params = array(1 => array($item->id, 'Integer'));
$new_item = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Queue_DAO_QueueItem');
$mailchimp_sync_log = CRM_CiviMailchimp_BAO_SyncLog::findById($existing_mailchimp_sync_log->id);
$this->assertFalse($new_item->fetch());
$this->assertNull($mailchimp_sync_log->civicrm_queue_item_id);
}
示例13: testGetDisplayAndImage
/**
* Test case for getDisplayAndImage( ).
*/
public function testGetDisplayAndImage()
{
//get the contact params
$params = $this->contactParams();
//create contact
$contact = CRM_Contact_BAO_Contact::create($params);
$contactId = $contact->id;
//get DisplayAndImage.
list($displayName, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($contactId);
$checkImage = CRM_Contact_BAO_Contact_Utils::getImage($params['contact_type'], FALSE, $contactId);
$prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
$suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
//build display name
$paramsDisplayName = $prefix[$params['prefix_id']] . ' ' . $params['first_name'] . ' ' . $params['last_name'] . ' ' . $suffix[$params['suffix_id']];
$this->assertEquals($displayName, $paramsDisplayName, 'Check For Display Name');
$this->assertEquals($image, $checkImage, 'Check For Image');
//cleanup DB by deleting the contact
$this->contactDelete($contactId);
}
示例14: processAPIContribution
static function processAPIContribution($params)
{
if (empty($params) || array_key_exists('error', $params)) {
return false;
}
// add contact using dedupe rule
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
$dedupeParams['check_permission'] = false;
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
if (CRM_Utils_Array::value(0, $dupeIds)) {
$params['contact_id'] = $dupeIds[0];
}
require_once 'CRM/Contact/BAO/Contact.php';
$contact = CRM_Contact_BAO_Contact::create($params);
if (!$contact->id) {
return false;
}
// only pass transaction params to contribution::create, if available
if (array_key_exists('transaction', $params)) {
$params = $params['transaction'];
$params['contact_id'] = $contact->id;
}
// handle contribution custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Contribution', false, false, CRM_Utils_Array::value('contribution_type_id', $params));
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, CRM_Utils_Array::value('id', $params, null), 'Contribution');
// create contribution
// if this is a recurring contribution then process it first
if ($params['trxn_type'] == 'subscrpayment') {
// see if a recurring record already exists
require_once 'CRM/Contribute/BAO/ContributionRecur.php';
$recurring = new CRM_Contribute_BAO_ContributionRecur();
$recurring->processor_id = $params['processor_id'];
if (!$recurring->find(true)) {
$recurring = new CRM_Contribute_BAO_ContributionRecur();
$recurring->invoice_id = $params['invoice_id'];
$recurring->find(true);
}
// This is the same thing the CiviCRM IPN handler does to handle
// subsequent recurring payments to avoid duplicate contribution
// errors due to invoice ID. See:
// ./CRM/Core/Payment/PayPalIPN.php:200
if ($recurring->id) {
$params['invoice_id'] = md5(uniqid(rand(), true));
}
$recurring->copyValues($params);
$recurring->save();
if (is_a($recurring, 'CRM_Core_Error')) {
return false;
} else {
$params['contribution_recur_id'] = $recurring->id;
}
}
require_once 'CRM/Contribute/BAO/Contribution.php';
$contribution =& CRM_Contribute_BAO_Contribution::create($params, CRM_Core_DAO::$_nullArray);
if (!$contribution->id) {
return false;
}
return true;
}
示例15: postProcess
/**
* Form submission of new/edit contact is processed.
*/
public function postProcess()
{
// check if dedupe button, if so return.
$buttonName = $this->controller->getButtonName();
if ($buttonName == $this->_dedupeButtonName) {
return;
}
//get the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$group = CRM_Utils_Array::value('group', $params);
if (!empty($group) && is_array($group)) {
unset($params['group']);
foreach ($group as $key => $value) {
$params['group'][$value] = 1;
}
}
CRM_Contact_BAO_Contact_Optimizer::edit($params, $this->_preEditValues);
if (!empty($params['image_URL'])) {
CRM_Contact_BAO_Contact::processImageParams($params);
}
if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && !empty($params['current_employer'])) {
$params['current_employer'] = $params['current_employer_id'];
}
// don't carry current_employer_id field,
// since we don't want to directly update DAO object without
// handling related business logic ( eg related membership )
if (isset($params['current_employer_id'])) {
unset($params['current_employer_id']);
}
$params['contact_type'] = $this->_contactType;
if (empty($params['contact_sub_type']) && $this->_isContactSubType) {
$params['contact_sub_type'] = array($this->_contactSubType);
}
if ($this->_contactId) {
$params['contact_id'] = $this->_contactId;
}
//make deceased date null when is_deceased = false
if ($this->_contactType == 'Individual' && !empty($this->_editOptions['Demographics']) && empty($params['is_deceased'])) {
$params['is_deceased'] = FALSE;
$params['deceased_date'] = NULL;
}
if (isset($params['contact_id'])) {
// process membership status for deceased contact
$deceasedParams = array('contact_id' => CRM_Utils_Array::value('contact_id', $params), 'is_deceased' => CRM_Utils_Array::value('is_deceased', $params, FALSE), 'deceased_date' => CRM_Utils_Array::value('deceased_date', $params, NULL));
$updateMembershipMsg = $this->updateMembershipStatus($deceasedParams);
}
// action is taken depending upon the mode
if ($this->_action & CRM_Core_Action::UPDATE) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params);
}
$customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, TRUE);
//CRM-5143
//if subtype is set, send subtype as extend to validate subtype customfield
$customFieldExtends = CRM_Utils_Array::value('contact_sub_type', $params) ? $params['contact_sub_type'] : $params['contact_type'];
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_contactId, $customFieldExtends, TRUE);
if ($this->_contactId && !empty($this->_oldSubtypes)) {
CRM_Contact_BAO_ContactType::deleteCustomSetForSubtypeMigration($this->_contactId, $params['contact_type'], $this->_oldSubtypes, $params['contact_sub_type']);
}
if (array_key_exists('CommunicationPreferences', $this->_editOptions)) {
// this is a chekbox, so mark false if we dont get a POST value
$params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE);
}
// process shared contact address.
CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']);
if (!array_key_exists('TagsAndGroups', $this->_editOptions) && !empty($params['group'])) {
unset($params['group']);
}
if (!empty($params['contact_id']) && $this->_action & CRM_Core_Action::UPDATE && !empty($params['group'])) {
// figure out which all groups are intended to be removed
$contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added');
if (is_array($contactGroupList)) {
foreach ($contactGroupList as $key) {
if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1) && empty($key['is_hidden'])) {
$params['group'][$key['group_id']] = -1;
}
}
}
}
// parse street address, CRM-5450
$parseStatusMsg = NULL;
if ($this->_parseStreetAddress) {
$parseResult = self::parseAddress($params);
$parseStatusMsg = self::parseAddressStatusMsg($parseResult);
}
// Allow un-setting of location info, CRM-5969
$params['updateBlankLocInfo'] = TRUE;
$contact = CRM_Contact_BAO_Contact::create($params, TRUE, FALSE, TRUE);
// status message
if ($this->_contactId) {
$message = ts('%1 has been updated.', array(1 => $contact->display_name));
} else {
$message = ts('%1 has been created.', array(1 => $contact->display_name));
}
// set the contact ID
$this->_contactId = $contact->id;
//.........这里部分代码省略.........