本文整理汇总了PHP中CRM_Core_BAO_Note::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Note::add方法的具体用法?PHP CRM_Core_BAO_Note::add怎么用?PHP CRM_Core_BAO_Note::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Note
的用法示例。
在下文中一共展示了CRM_Core_BAO_Note::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _civicrm_initialize
/**
* Create Note
*
* This API is used for creating a note.
* Required parameters : entity_id AND note
*
* @param array $params an associative array of name/value property values of civicrm_note
*
* @return array note id if note is created otherwise is_error = 1
* @access public
*/
function &civicrm_note_create(&$params)
{
_civicrm_initialize();
if (!is_array($params)) {
return civicrm_create_error('Params is not an array');
}
if (!CRM_Utils_Array::value('id', $params)) {
if (!isset($params['entity_table']) || !isset($params['entity_id']) || !isset($params['note']) || !isset($params['contact_id'])) {
return civicrm_create_error('Required parameter missing');
}
} else {
if (!isset($params['id']) && !isset($params['contact_id'])) {
return civicrm_create_error('Required parameter missing');
}
}
$contactID = CRM_Utils_Array::value('contact_id', $params);
if (!isset($params['modified_date'])) {
$params['modified_date'] = date("Ymd");
}
$ids = array();
$ids = array('id' => CRM_Utils_Array::value('id', $params));
$noteBAO = CRM_Core_BAO_Note::add($params, $ids);
if (is_a($noteBAO, 'CRM_Core_Error')) {
$error = civicrm_create_error("Note could not be created");
return $error;
} else {
$note = array();
_civicrm_object_to_array($noteBAO, $note);
$note['is_error'] = 0;
}
return $note;
}
示例2: civicrm_api3_note_create
/**
* Create Note
*
* This API is used for creating a note.
* Required parameters : entity_id AND note
*
* @param array $params an associative array of name/value property values of civicrm_note
* {@getfields note_create}
*
* @return array API result array
* @access public
* @example NoteCreate.php Create example
*
*
*/
function civicrm_api3_note_create($params)
{
$ids = array();
$ids = array('id' => CRM_Utils_Array::value('id', $params));
$noteBAO = CRM_Core_BAO_Note::add($params, $ids);
if (is_a($noteBAO, 'CRM_Core_Error')) {
$error = civicrm_api3_create_error("Note could not be created");
return $error;
} else {
$note = array();
_civicrm_api3_object_to_array($noteBAO, $note[$noteBAO->id]);
}
$result = civicrm_api3_create_success($note, $params);
return civicrm_api3_create_success($note, $params);
}
示例3: CRM_Core_Transaction
/**
* takes an associative array and creates a participant object
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Event_BAO_Participant object
* @access public
* @static
*/
static function &create(&$params)
{
require_once 'CRM/Utils/Date.php';
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$status = null;
if (CRM_Utils_Array::value('id', $params)) {
$status = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $params['id'], 'status_id');
}
$participant =& self::add($params);
if (is_a($participant, 'CRM_Core_Error')) {
$transaction->rollback();
return $participant;
}
if (!CRM_Utils_Array::value('id', $params) || $params['status_id'] != $status) {
require_once 'CRM/Activity/BAO/Activity.php';
CRM_Activity_BAO_Activity::addActivity($participant);
}
//CRM-5403
//for update mode
if (self::isPrimaryParticipant($participant->id) && $status) {
self::updateParticipantStatus($participant->id, $status, $participant->status_id);
}
$session =& CRM_Core_Session::singleton();
$id = $session->get('userID');
if (!$id) {
$id = $params['contact_id'];
}
// add custom field values
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_participant', $participant->id);
}
if (CRM_Utils_Array::value('note', $params) || CRM_Utils_Array::value('participant_note', $params)) {
if (CRM_Utils_Array::value('note', $params)) {
$note = CRM_Utils_Array::value('note', $params);
} else {
$note = CRM_Utils_Array::value('participant_note', $params);
}
$noteDetails = CRM_Core_BAO_Note::getNote($participant->id, 'civicrm_participant');
$noteIDs = array();
if (!empty($noteDetails)) {
$noteIDs['id'] = array_pop(array_flip($noteDetails));
}
if ($note) {
require_once 'CRM/Core/BAO/Note.php';
$noteParams = array('entity_table' => 'civicrm_participant', 'note' => $note, 'entity_id' => $participant->id, 'contact_id' => $id, 'modified_date' => date('Ymd'));
CRM_Core_BAO_Note::add($noteParams, $noteIDs);
}
}
// Log the information on successful add/edit of Participant data.
require_once 'CRM/Core/BAO/Log.php';
$logParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'data' => CRM_Event_PseudoConstant::participantStatus($participant->status_id), 'modified_id' => $id, 'modified_date' => date('Ymd'));
CRM_Core_BAO_Log::add($logParams);
$params['participant_id'] = $participant->id;
$transaction->commit();
// do not add to recent items for import, CRM-4399
if (!CRM_Utils_Array::value('skipRecentView', $params)) {
require_once 'CRM/Utils/Recent.php';
require_once 'CRM/Event/PseudoConstant.php';
require_once 'CRM/Contact/BAO/Contact.php';
$url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
$recentOther = array();
if (CRM_Core_Permission::check('edit event participants')) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
}
if (CRM_Core_Permission::check('delete in CiviEvent')) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
}
$participantRoles = CRM_Event_PseudoConstant::participantRole();
if ($participant->role_id) {
$role = explode(CRM_Core_DAO::VALUE_SEPARATOR, $participant->role_id);
foreach ($role as $roleKey => $roleValue) {
if (isset($roles)) {
$roles .= ", " . $participantRoles[$roleValue];
} else {
$roles = $participantRoles[$roleValue];
}
}
}
$eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'title');
$title = CRM_Contact_BAO_Contact::displayName($participant->contact_id) . ' (' . $roles . ' - ' . $eventTitle . ')';
// add the recently created Participant
CRM_Utils_Recent::add($title, $url, $participant->id, 'Participant', $participant->contact_id, null, $recentOther);
}
return $participant;
}
示例4: array
/**
* takes an associative array and creates a contribution object
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Contribute_BAO_Contribution object
* @access public
* @static
*/
static function &create(&$params, &$ids)
{
// FIXME: a cludgy hack to fix the dates to MySQL format
$dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
foreach ($dateFields as $df) {
if (isset($params[$df])) {
$params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
}
}
if (CRM_Utils_Array::value('contribution', $ids) && !CRM_Utils_Array::value('softID', $params)) {
if ($softID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionSoft', $ids['contribution'], 'id', 'contribution_id')) {
$params['softID'] = $softID;
}
}
$transaction = new CRM_Core_Transaction();
// delete the soft credit record if no soft credit contact ID AND no PCP is set in the form
if (CRM_Utils_Array::value('contribution', $ids) && (!CRM_Utils_Array::value('soft_credit_to', $params) && !CRM_Utils_Array::value('pcp_made_through_id', $params)) && CRM_Utils_Array::value('softID', $params)) {
$softCredit = new CRM_Contribute_DAO_ContributionSoft();
$softCredit->id = $params['softID'];
$softCredit->delete();
}
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session = CRM_Core_Session::singleton();
if (CRM_Utils_Array::value('note', $params)) {
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams, CRM_Utils_Array::value('note', $ids));
}
// make entry in batch entity batch table
if (CRM_Utils_Array::value('batch_id', $params)) {
$entityParams = array('batch_id' => $params['batch_id'], 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id);
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'contribution_type_id');
$retrieverequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieverequired = 1;
break;
}
}
if ($retrieverequired == 1) {
$contribution->find(true);
}
CRM_Core_BAO_Batch::addBatchEntity($entityParams);
}
// check if activity record exist for this contribution, if
// not add activity
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $contribution->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
if (!$activity->find()) {
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
}
// Handle soft credit and / or link to personal campaign page
if (CRM_Utils_Array::value('soft_credit_to', $params) || CRM_Utils_Array::value('pcp_made_through_id', $params)) {
$csParams = array();
if ($id = CRM_Utils_Array::value('softID', $params)) {
$csParams['id'] = $params['softID'];
}
$csParams['contribution_id'] = $contribution->id;
// If pcp_made_through_id set, we define soft_credit_to contact based on selected PCP,
// else use passed soft_credit_to
if (CRM_Utils_Array::value('pcp_made_through_id', $params)) {
$csParams['pcp_display_in_roll'] = $params['pcp_display_in_roll'] ? 1 : 0;
foreach (array('pcp_roll_nickname', 'pcp_personal_note') as $val) {
$csParams[$val] = $params[$val];
}
$csParams['pcp_id'] = CRM_Utils_Array::value('pcp_made_through_id', $params);
$csParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $csParams['pcp_id'], 'contact_id');
} else {
$csParams['contact_id'] = $params['soft_credit_to'];
$csParams['pcp_id'] = '';
}
// first stage: we register whole amount as credited to given person
$csParams['amount'] = $contribution->total_amount;
self::addSoftContribution($csParams);
}
$transaction->commit();
// do not add to recent items for import, CRM-4399
if (!CRM_Utils_Array::value('skipRecentView', $params)) {
//.........这里部分代码省略.........
示例5: array
/**
* takes an associative array and creates a contribution object
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Contribute_BAO_Contribution object
* @access public
* @static
*/
static function &create(&$params, &$ids)
{
require_once 'CRM/Utils/Money.php';
require_once 'CRM/Utils/Date.php';
require_once 'CRM/Contribute/PseudoConstant.php';
// FIXME: a cludgy hack to fix the dates to MySQL format
$dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
foreach ($dateFields as $df) {
if (isset($params[$df])) {
$params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
}
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session =& CRM_Core_Session::singleton();
if (CRM_Utils_Array::value('note', $params)) {
require_once 'CRM/Core/BAO/Note.php';
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams, CRM_Utils_Array::value('note', $ids));
}
// check if activity record exist for this contribution, if
// not add activity
require_once "CRM/Activity/DAO/Activity.php";
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $contribution->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
if (!$activity->find()) {
require_once "CRM/Activity/BAO/Activity.php";
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
}
if (CRM_Utils_Array::value('soft_credit_to', $params)) {
$csParams = array();
if ($id = CRM_Utils_Array::value('softID', $params)) {
$csParams['id'] = $params['softID'];
}
$csParams['pcp_display_in_roll'] = $params['pcp_display_in_roll'] ? 1 : 0;
foreach (array('pcp_roll_nickname', 'pcp_personal_note') as $val) {
if (CRM_Utils_Array::value($val, $params)) {
$csParams[$val] = $params[$val];
}
}
$csParams['contribution_id'] = $contribution->id;
$csParams['contact_id'] = $params['soft_credit_to'];
// first stage: we register whole amount as credited to given person
$csParams['amount'] = $contribution->total_amount;
self::addSoftContribution($csParams);
}
$transaction->commit();
// do not add to recent items for import, CRM-4399
if (!CRM_Utils_Array::value('skipRecentView', $params)) {
require_once 'CRM/Utils/Recent.php';
require_once 'CRM/Contribute/PseudoConstant.php';
require_once 'CRM/Contact/BAO/Contact.php';
$url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
$contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->contribution_type_id] . ')';
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
// add the recently created Contribution
CRM_Utils_Recent::add($title, $url, $contribution->id, 'Contribution', $contribution->contact_id, null, $recentOther);
}
return $contribution;
}
示例6: processFormContribution
/**
* Process the contribution.
*
* @param CRM_Core_Form $form
* @param array $params
* @param array $result
* @param array $contributionParams
* Parameters to be passed to contribution create action.
* This differs from params in that we are currently adding params to it and 1) ensuring they are being
* passed consistently & 2) documenting them here.
* - contact_id
* - line_item
* - is_test
* - campaign_id
* - contribution_page_id
* - source
* - payment_type_id
* - thankyou_date (not all forms will set this)
*
* @param CRM_Financial_DAO_FinancialType $financialType
* @param bool $online
* Is the form a front end form? If so set a bunch of unpredictable things that should be passed in from the form.
*
* @param int $billingLocationID
* ID of billing location type.
* @param bool $isRecur
* Is this recurring?
*
* @return \CRM_Contribute_DAO_Contribution
* @throws \Exception
*/
public static function processFormContribution(&$form, $params, $result, $contributionParams, $financialType, $online, $billingLocationID, $isRecur)
{
$transaction = new CRM_Core_Transaction();
$contactID = $contributionParams['contact_id'];
$isEmailReceipt = !empty($form->_values['is_email_receipt']);
$isSeparateMembershipPayment = empty($params['separate_membership_payment']) ? FALSE : TRUE;
$pledgeID = !empty($params['pledge_id']) ? $params['pledge_id'] : CRM_Utils_Array::value('pledge_id', $form->_values);
if (!$isSeparateMembershipPayment && !empty($form->_values['pledge_block_id']) && (!empty($params['is_pledge']) || $pledgeID)) {
$isPledge = TRUE;
} else {
$isPledge = FALSE;
}
// add these values for the recurringContrib function ,CRM-10188
$params['financial_type_id'] = $financialType->id;
$contributionParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $billingLocationID);
//@todo - this is being set from the form to resolve CRM-10188 - an
// eNotice caused by it not being set @ the front end
// however, we then get it being over-written with null for backend contributions
// a better fix would be to set the values in the respective forms rather than require
// a function being shared by two forms to deal with their respective values
// moving it to the BAO & not taking the $form as a param would make sense here.
if (!isset($params['is_email_receipt']) && $isEmailReceipt) {
$params['is_email_receipt'] = $isEmailReceipt;
}
$params['is_recur'] = $isRecur;
$recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType);
$nonDeductibleAmount = self::getNonDeductibleAmount($params, $financialType, $online);
$now = date('YmdHis');
$receiptDate = CRM_Utils_Array::value('receipt_date', $params);
if ($isEmailReceipt) {
$receiptDate = $now;
}
if (isset($params['amount'])) {
$contributionParams = array_merge(self::getContributionParams($params, $financialType->id, $nonDeductibleAmount, TRUE, $result, $receiptDate, $recurringContributionID), $contributionParams);
$contribution = CRM_Contribute_BAO_Contribution::add($contributionParams);
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
if ($invoicing) {
$dataArray = array();
// @todo - interrogate the line items passed in on the params array.
// No reason to assume line items will be set on the form.
foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
foreach ($lineItemValue as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
} else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
}
}
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('dataArray', $dataArray);
$smarty->assign('totalTaxAmount', $params['tax_amount']);
}
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
}
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
// process soft credit / pcp params first
CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form);
//CRM-13981, processing honor contact into soft-credit contribution
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
//handle pledge stuff.
if ($isPledge) {
//.........这里部分代码省略.........
示例7: processContribution
//.........这里部分代码省略.........
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
}
// first create the contribution record
$contribParams = array('contact_id' => $contactID, 'financial_type_id' => $contributionType->id, 'contribution_page_id' => $contributionPageId, 'receive_date' => CRM_Utils_Array::value('receive_date', $params) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !$online || !empty($params['source']) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL, 'campaign_id' => $campaignId);
if (!$online && isset($params['thankyou_date'])) {
$contribParams['thankyou_date'] = $params['thankyou_date'];
}
if (!$online || $form->_values['is_monetary']) {
if (empty($params['is_pay_later'])) {
$contribParams['payment_instrument_id'] = 1;
}
}
if (!$pending && $result) {
$contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $result), 'payment_processor' => CRM_Utils_Array::value('payment_processor', $result));
}
if ($recurringContributionID) {
$contribParams['contribution_recur_id'] = $recurringContributionID;
}
$contribParams['contribution_status_id'] = $pending ? 2 : 1;
$contribParams['is_test'] = 0;
if ($form->_mode == 'test') {
$contribParams['is_test'] = 1;
}
$ids = array();
if (isset($contribParams['invoice_id'])) {
$contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
if (isset($contribID)) {
$ids['contribution'] = $contribID;
$contribParams['id'] = $contribID;
}
}
//create an contribution address
if ($form->_contributeMode != 'notify' && empty($params['is_pay_later']) && !empty($form->_values['is_monetary'])) {
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
// CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
$contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
$contribParams['total_amount'] = trim(CRM_Utils_Money::format($contribParams['total_amount'], ' '));
// Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
// if its due to pcp
if (!empty($params['pcp_made_through_id'])) {
$contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $params['pcp_made_through_id'], 'contact_id');
} else {
$contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
}
// Pass these details onto with the contribution to make them
// available at hook_post_process, CRM-8908
$contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
}
if (isset($params['amount'])) {
$contribParams['line_item'] = $form->_lineItem;
//add contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
}
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
//CRM-13981, processing honor contact into soft-credit contribution
CRM_Contact_Form_ProfileContact::postProcess($form);
// process soft credit / pcp pages
CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
//handle pledge stuff.
示例8: 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;
//.........这里部分代码省略.........
示例9: processNote
/**
* Function to process the Note
*
* @access public
* @return None
*/
function processNote(&$params, $contactID, $contributionID, $contributionNoteID = null)
{
//process note
require_once 'CRM/Core/BAO/Note.php';
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contributionID, 'contact_id' => $contactID);
$noteID = array();
if ($contributionNoteID) {
$noteID = array("id" => $contributionNoteID);
$noteParams['note'] = $noteParams['note'] ? $noteParams['note'] : "null";
}
CRM_Core_BAO_Note::add($noteParams, $noteID);
}
示例10: 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);
//.........这里部分代码省略.........
示例11: 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'];
//.........这里部分代码省略.........
示例12: import
//.........这里部分代码省略.........
if (CRM_Utils_Array::value('error_data', $formatError) == 'soft_credit') {
return CRM_Contribute_Import_Parser::SOFT_CREDIT_ERROR;
} else {
if (CRM_Utils_Array::value('error_data', $formatError) == 'pledge_payment') {
return CRM_Contribute_Import_Parser::PLEDGE_PAYMENT_ERROR;
}
}
return CRM_Contribute_Import_Parser::ERROR;
}
if ($onDuplicate != CRM_Contribute_Import_Parser::DUPLICATE_UPDATE) {
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, null, 'Contribution');
} else {
//fix for CRM-2219 - Update Contribution
// onDuplicate == CRM_Contribute_Import_Parser::DUPLICATE_UPDATE
if ($paramValues['invoice_id'] || $paramValues['trxn_id'] || $paramValues['contribution_id']) {
require_once 'CRM/Contribute/BAO/Contribution.php';
$dupeIds = array('id' => CRM_Utils_Array::value('contribution_id', $paramValues), 'trxn_id' => CRM_Utils_Array::value('trxn_id', $paramValues), 'invoice_id' => CRM_Utils_Array::value('invoice_id', $paramValues));
$ids['contribution'] = CRM_Contribute_BAO_Contribution::checkDuplicateIds($dupeIds);
if ($ids['contribution']) {
$formatted['id'] = $ids['contribution'];
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, $formatted['id'], 'Contribution');
//process note
if ($paramValues['note']) {
$noteID = array();
$contactID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $ids['contribution'], 'contact_id');
require_once 'CRM/Core/BAO/Note.php';
$daoNote =& new CRM_Core_BAO_Note();
$daoNote->entity_table = 'civicrm_contribution';
$daoNote->entity_id = $ids['contribution'];
if ($daoNote->find(true)) {
$noteID['id'] = $daoNote->id;
}
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $paramValues['note'], 'entity_id' => $ids['contribution'], 'contact_id' => $contactID);
CRM_Core_BAO_Note::add($noteParams, $noteID);
unset($formatted['note']);
}
//need to check existing soft credit contribution, CRM-3968
if (CRM_Utils_Array::value('soft_credit_to', $formatted)) {
$dupeSoftCredit = array('contact_id' => $formatted['soft_credit_to'], 'contribution_id' => $ids['contribution']);
$existingSoftCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($dupeSoftCredit);
if (CRM_Utils_Array::value('soft_credit_id', $existingSoftCredit)) {
$formatted['softID'] = $existingSoftCredit['soft_credit_id'];
}
}
$newContribution =& CRM_Contribute_BAO_Contribution::create($formatted, $ids);
$this->_newContributions[] = $newContribution->id;
//return soft valid since we need to show how soft credits were added
if (CRM_Utils_Array::value('soft_credit_to', $formatted)) {
return CRM_Contribute_Import_Parser::SOFT_CREDIT;
}
// process pledge payment assoc w/ the contribution
return self::processPledgePayments($formatted);
return CRM_Contribute_Import_Parser::VALID;
} else {
$labels = array('id' => 'Contribution ID', 'trxn_id' => 'Transaction ID', 'invoice_id' => 'Invoice ID');
foreach ($dupeIds as $k => $v) {
if ($v) {
$errorMsg[] = "{$labels[$k]} {$v}";
}
}
$errorMsg = implode(' AND ', $errorMsg);
array_unshift($values, "Matching Contribution record not found for " . $errorMsg . ". Row was skipped.");
return CRM_Contribute_Import_Parser::ERROR;
}
}
}
示例13: processFormContribution
/**
* Process the contribution.
*
* @param CRM_Core_Form $form
* @param array $params
* @param array $result
* @param int $contactID
* @param CRM_Financial_DAO_FinancialType $financialType
* @param bool $pending
* @param bool $online
*
* @param bool $isTest
* @param array $lineItems
*
* @param int $billingLocationID
* ID of billing location type.
*
* @return \CRM_Contribute_DAO_Contribution
* @throws \Exception
*/
public static function processFormContribution(&$form, $params, $result, $contactID, $financialType, $pending, $online, $isTest, $lineItems, $billingLocationID)
{
$transaction = new CRM_Core_Transaction();
$contribSoftContactId = $addressID = NULL;
$contributeMode = $form->_contributeMode;
$isMonetary = !empty($form->_values['is_monetary']);
$isEmailReceipt = !empty($form->_values['is_email_receipt']);
// How do these vary from params? These are currently passed to
// - custom data function....
$formParams = $form->_params;
$isSeparateMembershipPayment = empty($formParams['separate_membership_payment']) ? FALSE : TRUE;
$pledgeID = empty($formParams['pledge_id']) ? NULL : $formParams['pledge_id'];
if (!$isSeparateMembershipPayment && !empty($form->_values['pledge_block_id']) && (!empty($formParams['is_pledge']) || $pledgeID)) {
$isPledge = TRUE;
} else {
$isPledge = FALSE;
}
// add these values for the recurringContrib function ,CRM-10188
$params['financial_type_id'] = $financialType->id;
//create an contribution address
if ($contributeMode != 'notify' && empty($params['is_pay_later']) && $isMonetary) {
$addressID = CRM_Contribute_BAO_Contribution::createAddress($params, $billingLocationID);
}
//@todo - this is being set from the form to resolve CRM-10188 - an
// eNotice caused by it not being set @ the front end
// however, we then get it being over-written with null for backend contributions
// a better fix would be to set the values in the respective forms rather than require
// a function being shared by two forms to deal with their respective values
// moving it to the BAO & not taking the $form as a param would make sense here.
if (!isset($params['is_email_receipt']) && $isEmailReceipt) {
$params['is_email_receipt'] = $isEmailReceipt;
}
$recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType, $online);
$nonDeductibleAmount = self::getNonDeductibleAmount($params, $financialType, $online);
$now = date('YmdHis');
$receiptDate = CRM_Utils_Array::value('receipt_date', $params);
if ($isEmailReceipt) {
$receiptDate = $now;
}
//get the contrib page id.
$contributionPageId = NULL;
if ($online) {
$contributionPageId = $form->_id;
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
if (!array_key_exists('campaign_id', $params)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
}
} else {
//also for offline we do support - CRM-7290
$contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
}
// Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
// if its due to pcp
if (!empty($params['pcp_made_through_id'])) {
$contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $params['pcp_made_through_id'], 'contact_id');
} else {
$contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
}
// Pass these details onto with the contribution to make them
// available at hook_post_process, CRM-8908
$params['soft_credit_to'] = $contribSoftContactId;
}
if (isset($params['amount'])) {
$contribParams = self::getContributionParams($params, $contactID, $financialType->id, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate, $recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems);
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams);
$invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
if ($invoicing) {
$dataArray = array();
foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
foreach ($lineItemValue as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
} else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
//.........这里部分代码省略.........
示例14: create
/**
* Takes an associative array and creates a contribution object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $ids
* The array that holds all the db ids.
*
* @return CRM_Contribute_BAO_Contribution
*/
public static function create(&$params, $ids = array())
{
$dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
foreach ($dateFields as $df) {
if (isset($params[$df])) {
$params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
}
}
//if contribution is created with cancelled or refunded status, add credit note id
if (!empty($params['contribution_status_id'])) {
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if ($params['contribution_status_id'] == array_search('Refunded', $contributionStatus) || $params['contribution_status_id'] == array_search('Cancelled', $contributionStatus)) {
if (empty($params['creditnote_id']) || $params['creditnote_id'] == "null") {
$params['creditnote_id'] = self::createCreditNoteId();
}
}
}
$transaction = new CRM_Core_Transaction();
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session = CRM_Core_Session::singleton();
if (!empty($params['note'])) {
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams);
}
// make entry in batch entity batch table
if (!empty($params['batch_id'])) {
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
}
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
$transaction->commit();
// check if activity record exist for this contribution, if
// not add activity
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $contribution->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
if (!$activity->find(TRUE)) {
if (empty($contribution->contact_id)) {
$contribution->find(TRUE);
}
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
} else {
// CRM-13237 : if activity record found, update it with campaign id of contribution
CRM_Core_DAO::setFieldValue('CRM_Activity_BAO_Activity', $activity->id, 'campaign_id', $contribution->campaign_id);
}
// do not add to recent items for import, CRM-4399
if (empty($params['skipRecentView'])) {
$url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
$contributionTypes = CRM_Contribute_PseudoConstant::financialType();
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->financial_type_id] . ')';
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
//.........这里部分代码省略.........
示例15: postProcess
/**
* This function is called when the form is submitted
*
* @access public
*
* @return None
*/
public function postProcess()
{
$quickSave = FALSE;
if (CRM_Utils_Array::value('_qf_Relationship_refresh_save', $_POST) || CRM_Utils_Array::value('_qf_Relationship_refresh_savedetails', $_POST)) {
//CRM-15873
//Parse custom file uploads
$pageName = $this->getAttribute('name');
$data =& $this->controller->container();
foreach ($this->controller->get('uploadNames') as $name) {
$this->controller->_actions['upload']->upload($this, $data, $pageName, $name);
}
$quickSave = TRUE;
}
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$this->set('searchDone', 0);
$this->set('callAjax', FALSE);
if (CRM_Utils_Array::value('_qf_Relationship_refresh', $_POST) || $quickSave) {
if (is_numeric($params['contact_select_id'][1])) {
if ($quickSave) {
$params['contact_check'] = array($params['contact_select_id'][1] => 1);
}
} else {
$this->set('callAjax', TRUE);
$this->set('relType', $params['relationship_type_id']);
$this->set('relContact', $params['contact'][1]);
$quickSave = FALSE;
}
$this->set('searchDone', 1);
if (!$quickSave) {
return;
}
}
// action is taken depending upon the mode
$ids = array();
$ids['contact'] = $this->_contactId;
// modify params for ajax call
$this->modifyParams($params);
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Relationship::del($this->_relationshipId);
return;
}
$relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $params['relationship_type_id']);
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['relationship'] = $this->_relationshipId;
$relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId);
$ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a;
//if relationship type change and previously it was
//employer / emplyee relationship with current employer
//than clear the current employer. CRM-3235.
//make sure we has to have employer id before firing queries, CRM-7306
$employerId = CRM_Utils_Array::value('current_employee_id', $this->_values);
$isDisabled = TRUE;
if (CRM_Utils_Array::value('is_active', $params)) {
$isDisabled = FALSE;
}
$relChanged = TRUE;
if ($relationshipTypeId == $this->_values['relationship_type_id']) {
$relChanged = FALSE;
}
if ($employerId && ($isDisabled || $relChanged)) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['current_employee_id']);
}
//if field key doesn't exists in params that means the user has unchecked checkbox,
//hence fill FALSE to params
$params['is_active'] = $isDisabled ? FALSE : TRUE;
$params['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_a_b', $params, FALSE);
$params['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_b_a', $params, FALSE);
} elseif ($quickSave) {
if (CRM_Utils_Array::value('add_current_employee', $params) && $this->_allRelationshipNames[$relationshipTypeId]['name_a_b'] == 'Employee of') {
$params['employee_of'] = $params['contact_select_id'][1];
} elseif (CRM_Utils_Array::value('add_current_employer', $params) && $this->_allRelationshipNames[$relationshipTypeId]['name_b_a'] == 'Employer of') {
$params['employer_of'] = array($params['contact_select_id'][1] => 1);
}
if (!$this->_rtype) {
$this->_rtype = str_replace($relationshipTypeId . '_', '', $params['relationship_type_id']);
}
}
if (!$params['note']) {
$params['note'] = 'null';
}
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], NULL, TRUE);
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], NULL, TRUE);
//special case to handle if all checkboxes are unchecked
$customFields = CRM_Core_BAO_CustomField::getFields('Relationship', FALSE, FALSE, $relationshipTypeId);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship');
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids);
// if this is called from case view,
//create an activity for case role removal.CRM-4480
if ($this->_caseId) {
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
}
$status = '';
//.........这里部分代码省略.........