本文整理匯總了PHP中CRM_Price_BAO_LineItem::syncLineItems方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Price_BAO_LineItem::syncLineItems方法的具體用法?PHP CRM_Price_BAO_LineItem::syncLineItems怎麽用?PHP CRM_Price_BAO_LineItem::syncLineItems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Price_BAO_LineItem
的用法示例。
在下文中一共展示了CRM_Price_BAO_LineItem::syncLineItems方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: import
/**
* Handle the values in import mode.
*
* @param int $onDuplicate
* The code for what action to take on duplicates.
* @param array $values
* The array of values belonging to this line.
*
* @return bool
* the result of this processing
*/
public function import($onDuplicate, &$values)
{
// first make sure this is a valid line
$response = $this->summary($values);
if ($response != CRM_Import_Parser::VALID) {
return $response;
}
$params =& $this->getActiveFieldParams();
$session = CRM_Core_Session::singleton();
$dateType = $session->get('dateTypes');
$formatted = array('version' => 3);
$customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
// don't add to recent items, CRM-4399
$formatted['skipRecentView'] = TRUE;
foreach ($params as $key => $val) {
if ($val) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
if ($customFields[$customFieldID]['data_type'] == 'Date') {
CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
unset($params[$key]);
} elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
$params[$key] = CRM_Utils_String::strtoboolstr($val);
}
}
if ($key == 'participant_register_date') {
CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'participant_register_date');
$formatted['participant_register_date'] = CRM_Utils_Date::processDate($params['participant_register_date']);
}
}
}
if (!(!empty($params['participant_role_id']) || !empty($params['participant_role']))) {
if (!empty($params['event_id'])) {
$params['participant_role_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'default_role_id');
} else {
$eventTitle = $params['event_title'];
$qParams = array();
$dao = new CRM_Core_DAO();
$params['participant_role_id'] = $dao->singleValueQuery("SELECT default_role_id FROM civicrm_event WHERE title = '{$eventTitle}' ", $qParams);
}
}
//date-Format part ends
static $indieFields = NULL;
if ($indieFields == NULL) {
$indieFields = CRM_Event_BAO_Participant::import();
}
$formatValues = array();
foreach ($params as $key => $field) {
if ($field == NULL || $field === '') {
continue;
}
$formatValues[$key] = $field;
}
$formatError = _civicrm_api3_deprecated_participant_formatted_param($formatValues, $formatted, TRUE);
if ($formatError) {
array_unshift($values, $formatError['error_message']);
return CRM_Import_Parser::ERROR;
}
if (!CRM_Utils_Rule::integer($formatted['event_id'])) {
array_unshift($values, ts('Invalid value for Event ID'));
return CRM_Import_Parser::ERROR;
}
if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Participant');
} else {
if ($formatValues['participant_id']) {
$dao = new CRM_Event_BAO_Participant();
$dao->id = $formatValues['participant_id'];
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, $formatValues['participant_id'], 'Participant');
if ($dao->find(TRUE)) {
$ids = array('participant' => $formatValues['participant_id'], 'userId' => $session->get('userID'));
$participantValues = array();
//@todo calling api functions directly is not supported
$newParticipant = _civicrm_api3_deprecated_participant_check_params($formatted, $participantValues, FALSE);
if ($newParticipant['error_message']) {
array_unshift($values, $newParticipant['error_message']);
return CRM_Import_Parser::ERROR;
}
$newParticipant = CRM_Event_BAO_Participant::create($formatted, $ids);
if (!empty($formatted['fee_level'])) {
$otherParams = array('fee_label' => $formatted['fee_level'], 'event_id' => $newParticipant->event_id);
CRM_Price_BAO_LineItem::syncLineItems($newParticipant->id, 'civicrm_participant', $newParticipant->fee_amount, $otherParams);
}
$this->_newParticipant[] = $newParticipant->id;
return CRM_Import_Parser::VALID;
} else {
array_unshift($values, 'Matching Participant record not found for Participant ID ' . $formatValues['participant_id'] . '. Row was skipped.');
return CRM_Import_Parser::ERROR;
}
}
//.........這裏部分代碼省略.........
示例2: import
//.........這裏部分代碼省略.........
$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 (CRM_Utils_Array::value('invoice_id', $paramValues) || CRM_Utils_Array::value('trxn_id', $paramValues) || $paramValues['contribution_id']) {
$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 (CRM_Utils_Array::value('note', $paramValues)) {
$noteID = array();
$contactID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $ids['contribution'], 'contact_id');
$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);
CRM_Price_BAO_LineItem::syncLineItems($ids['contribution'], 'civicrm_contribution', CRM_Utils_Array::value('total_amount', $formatted));
$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;
}
}
}
if ($this->_contactIdIndex < 0) {
// set the contact type if its not set
if (!isset($paramValues['contact_type'])) {
$paramValues['contact_type'] = $this->_contactType;
}
$paramValues['version'] = 3;
//retrieve contact id using contact dedupe rule
require_once 'api/v3/DeprecatedUtils.php';
$error = _civicrm_api3_deprecated_check_contact_dedupe($paramValues);
if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);