本文整理汇总了PHP中CRM_Member_BAO_MembershipType::getDatesForMembershipType方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_MembershipType::getDatesForMembershipType方法的具体用法?PHP CRM_Member_BAO_MembershipType::getDatesForMembershipType怎么用?PHP CRM_Member_BAO_MembershipType::getDatesForMembershipType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Member_BAO_MembershipType
的用法示例。
在下文中一共展示了CRM_Member_BAO_MembershipType::getDatesForMembershipType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_membership_create
/**
* Create a Contact Membership.
*
* This API is used for creating a Membership for a contact.
* Required parameters : membership_type_id and status_id.
*
* @param array $params
* Array of name/value property values of civicrm_membership.
*
* @return array
* API result array.
*/
function civicrm_api3_membership_create($params)
{
// check params for membership id during update
if (!empty($params['id']) && !isset($params['skipStatusCal'])) {
// Don't calculate status on existing membership - expect API use to pass them in
// or leave unchanged.
$params['skipStatusCal'] = 1;
} else {
// also check for status id if override is set (during add/update)
if (!empty($params['is_override']) && empty($params['status_id'])) {
return civicrm_api3_create_error('Status ID required');
}
}
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Membership');
$params = array_merge($params, $values);
// Fixme: This code belongs in the BAO
if (empty($params['id']) || !empty($params['num_terms'])) {
if (empty($params['id'])) {
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($params['membership_type_id'], CRM_Utils_Array::value('join_date', $params), CRM_Utils_Array::value('start_date', $params), CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('num_terms', $params, 1));
} else {
$calcDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($params['id'], NULL, CRM_Utils_Array::value('membership_type_id', $params), $params['num_terms']);
}
foreach (array('join_date', 'start_date', 'end_date') as $date) {
if (empty($params[$date]) && isset($calcDates[$date])) {
$params[$date] = $calcDates[$date];
}
}
}
// Fixme: This code belongs in the BAO
$action = CRM_Core_Action::ADD;
// we need user id during add mode
$ids = array();
if (!empty($params['contact_id'])) {
$ids['userId'] = $params['contact_id'];
}
//for edit membership id should be present
if (!empty($params['id'])) {
$ids['membership'] = $params['id'];
$action = CRM_Core_Action::UPDATE;
}
//need to pass action to handle related memberships.
$params['action'] = $action;
if (empty($params['line_item']) && !empty($params['membership_type_id'])) {
CRM_Price_BAO_LineItem::getLineItemArray($params, NULL, 'membership', $params['membership_type_id']);
}
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
if (array_key_exists('is_error', $membershipBAO)) {
// In case of no valid status for given dates, $membershipBAO
// is going to contain 'is_error' => "Error Message"
return civicrm_api3_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
}
$membership = array();
_civicrm_api3_object_to_array($membershipBAO, $membership[$membershipBAO->id]);
return civicrm_api3_create_success($membership, $params, 'Membership', 'create', $membershipBAO);
}
示例2: processMembership
/**
* process membership records
*
* @param array $params associated array of submitted values
*
* @access public
*
* @return bool
*/
private function processMembership(&$params)
{
$dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate');
$dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
// get the price set associated with offline memebership
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
$this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
if (isset($params['field'])) {
$customFields = array();
foreach ($params['field'] as $key => $value) {
// if contact is not selected we should skip the row
if (empty($params['primary_contact_id'][$key])) {
continue;
}
$value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']);
// update contact information
$this->updateContactInfo($value);
$membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
foreach ($dateTypes as $dateField => $dateVariable) {
${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]);
}
$calcDates = array();
$calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate);
foreach ($calcDates as $memType => $calcDate) {
foreach ($dates as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $value);
if (!$date) {
$date = CRM_Utils_Array::value($d, $calcDate);
}
$value[$d] = CRM_Utils_Date::processDate($date);
}
}
if (!empty($value['send_receipt'])) {
$value['receipt_date'] = date('Y-m-d His');
}
if (!empty($value['membership_source'])) {
$value['source'] = $value['membership_source'];
}
unset($value['membership_source']);
//Get the membership status
if (!empty($value['membership_status'])) {
$value['status_id'] = $value['membership_status'];
unset($value['membership_status']);
}
if (empty($customFields)) {
// membership type custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
}
//check for custom data
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $customFields, $key, 'Membership', $membershipTypeId);
if (!empty($value['financial_type'])) {
$value['financial_type_id'] = $value['financial_type'];
}
if (!empty($value['payment_instrument'])) {
$value['payment_instrument_id'] = $value['payment_instrument'];
}
// handle soft credit
if (is_array(CRM_Utils_Array::value('soft_credit_contact_id', $params)) && !empty($params['soft_credit_contact_id'][$key]) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) {
$value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
$value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
}
if (!empty($value['receive_date'])) {
$value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
}
$params['actualBatchTotal'] += $value['total_amount'];
unset($value['financial_type']);
unset($value['payment_instrument']);
$value['batch_id'] = $this->_batchId;
$value['skipRecentView'] = TRUE;
// make entry in line item for contribution
$editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
$editedResults = array();
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
if (!empty($editedResults)) {
unset($this->_priceSet['fields']);
$this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
unset($this->_priceSet['fields'][$editedResults['id']]['options']);
$fid = $editedResults['id'];
$editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
$editedResults = array();
CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
if (!empty($value['total_amount'])) {
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
}
$fieldID = key($this->_priceSet['fields']);
$value['price_' . $fieldID] = $editedResults['id'];
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
//.........这里部分代码省略.........
示例3: import
//.........这里部分代码省略.........
$newMembership = CRM_Member_BAO_Membership::create($formatted, $ids, TRUE);
if (civicrm_error($newMembership)) {
array_unshift($values, $newMembership['is_error'] . ' for Membership ID ' . $formatValues['membership_id'] . '. Row was skipped.');
return CRM_Import_Parser::ERROR;
} else {
$this->_newMemberships[] = $newMembership->id;
return CRM_Import_Parser::VALID;
}
} else {
array_unshift($values, 'Matching Membership record not found for Membership ID ' . $formatValues['membership_id'] . '. Row was skipped.');
return CRM_Import_Parser::ERROR;
}
}
}
//Format dates
$startDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $formatted), '%Y-%m-%d');
$endDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $formatted), '%Y-%m-%d');
$joinDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $formatted), '%Y-%m-%d');
if ($this->_contactIdIndex < 0) {
//retrieve contact id using contact dedupe rule
$formatValues['contact_type'] = $this->_contactType;
$formatValues['version'] = 3;
require_once 'CRM/Utils/DeprecatedUtils.php';
$error = _civicrm_api3_deprecated_check_contact_dedupe($formatValues);
if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
if (count($matchedIDs) > 1) {
array_unshift($values, 'Multiple matching contact records detected for this row. The membership was not imported');
return CRM_Import_Parser::ERROR;
} else {
$cid = $matchedIDs[0];
$formatted['contact_id'] = $cid;
//fix for CRM-1924
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($formatted['membership_type_id'], $joinDate, $startDate, $endDate);
self::formattedDates($calcDates, $formatted);
//fix for CRM-3570, exclude the statuses those having is_admin = 1
//now user can import is_admin if is override is true.
$excludeIsAdmin = FALSE;
if (!CRM_Utils_Array::value('is_override', $formatted)) {
$formatted['exclude_is_admin'] = $excludeIsAdmin = TRUE;
}
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', $excludeIsAdmin, $formatted['membership_type_id'], $formatted);
if (!CRM_Utils_Array::value('status_id', $formatted)) {
$formatted['status_id'] = $calcStatus['id'];
} elseif (!CRM_Utils_Array::value('is_override', $formatted)) {
if (empty($calcStatus)) {
array_unshift($values, 'Status in import row (' . $formatValues['status_id'] . ') does not match calculated status based on your configured Membership Status Rules. Record was not imported.');
return CRM_Import_Parser::ERROR;
} elseif ($formatted['status_id'] != $calcStatus['id']) {
//Status Hold" is either NOT mapped or is FALSE
array_unshift($values, 'Status in import row (' . $formatValues['status_id'] . ') does not match calculated status based on your configured Membership Status Rules (' . $calcStatus['name'] . '). Record was not imported.');
return CRM_Import_Parser::ERROR;
}
}
$newMembership = civicrm_api3('membership', 'create', $formatted);
$this->_newMemberships[] = $newMembership['id'];
return CRM_Import_Parser::VALID;
}
} else {
// Using new Dedupe rule.
$ruleParams = array('contact_type' => $this->_contactType, 'used' => 'Unsupervised');
$fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
$disp = '';
foreach ($fieldsArray as $value) {
if (array_key_exists(trim($value), $params)) {
$paramValue = $params[trim($value)];
示例4: transitionComponents
//.........这里部分代码省略.........
}
if ($participant) {
$updatedStatusId = array_search('Cancelled', $participantStatuses);
CRM_Event_BAO_Participant::updateParticipantStatus($participant->id, $oldStatus, $updatedStatusId, true);
$updateResult['updatedComponents']['CiviEvent'] = $updatedStatusId;
if ($processContributionObject) {
$processContribution = true;
}
}
if ($pledgePayment) {
CRM_Pledge_BAO_Payment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, $contributionStatusId);
$updateResult['updatedComponents']['CiviPledge'] = $contributionStatusId;
if ($processContributionObject) {
$processContribution = true;
}
}
} else {
if ($contributionStatusId == array_search('Completed', $contributionStatuses)) {
// only pending contribution related object processed.
if ($previousContriStatusId && $previousContriStatusId != array_search('Pending', $contributionStatuses)) {
// this is case when we already processed contribution object.
return $updateResult;
} else {
if (!$previousContriStatusId && $contribution->contribution_status_id != array_search('Pending', $contributionStatuses)) {
// this is case when we will going to process contribution object.
return $updateResult;
}
}
if ($membership) {
$format = '%Y%m%d';
require_once 'CRM/Member/BAO/MembershipType.php';
//CRM-4523
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
if ($currentMembership) {
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday = null);
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday = null);
$dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
} else {
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id);
}
//get the status for membership.
require_once 'CRM/Member/BAO/MembershipStatus.php';
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', true);
$formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, array_search('Current', $membershipStatuses)), 'join_date' => CRM_Utils_Date::customFormat($dates['join_date'], $format), 'start_date' => CRM_Utils_Date::customFormat($dates['start_date'], $format), 'end_date' => CRM_Utils_Date::customFormat($dates['end_date'], $format), 'reminder_date' => CRM_Utils_Date::customFormat($dates['reminder_date'], $format));
$membership->copyValues($formatedParams);
$membership->save();
//updating the membership log
$membershipLog = array();
$membershipLog = $formatedParams;
$logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
$logStartDate = $logStartDate ? CRM_Utils_Date::isoToMysql($logStartDate) : $formatedParams['start_date'];
$membershipLog['start_date'] = $logStartDate;
$membershipLog['membership_id'] = $membership->id;
$membershipLog['modified_id'] = $membership->contact_id;
$membershipLog['modified_date'] = date('Ymd');
require_once 'CRM/Member/BAO/MembershipLog.php';
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
//update related Memberships.
CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
$updateResult['membership_end_date'] = CRM_Utils_Date::customFormat($dates['end_date'], '%B %E%f, %Y');
$updateResult['updatedComponents']['CiviMember'] = $membership->status_id;
if ($processContributionObject) {
$processContribution = true;
}
}
if ($participant) {
$updatedStatusId = array_search('Registered', $participantStatuses);
CRM_Event_BAO_Participant::updateParticipantStatus($participant->id, $oldStatus, $updatedStatusId, true);
$updateResult['updatedComponents']['CiviEvent'] = $updatedStatusId;
if ($processContributionObject) {
$processContribution = true;
}
}
if ($pledgePayment) {
CRM_Pledge_BAO_Payment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, $contributionStatusId);
$updateResult['updatedComponents']['CiviPledge'] = $contributionStatusId;
if ($processContributionObject) {
$processContribution = true;
}
}
}
}
}
// process contribution object.
if ($processContribution) {
require_once 'CRM/Contribute/BAO/Contribution.php';
$contributionParams = array();
$fields = array('contact_id', 'total_amount', 'receive_date', 'is_test', 'payment_instrument_id', 'trxn_id', 'invoice_id', 'contribution_type_id', 'contribution_status_id', 'non_deductible_amount', 'receipt_date', 'check_number');
foreach ($fields as $field) {
if (!CRM_Utils_Array::value($field, $params)) {
continue;
}
$contributionParams[$field] = $params[$field];
}
$ids = array('contribution' => $contributionId);
require_once 'CRM/Contribute/BAO/Contribution.php';
$contribution =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
}
return $updateResult;
}
示例5: postProcess
//.........这里部分代码省略.........
}
///CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
if ($isQuickConfig && $submittedFinancialType) {
$li['financial_type_id'] = $submittedFinancialType;
}
}
}
}
$this->storeContactFields($formValues);
$params['contact_id'] = $this->_contactID;
$fields = array('status_id', 'source', 'is_override', 'campaign_id');
foreach ($fields as $f) {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
// fix for CRM-3724
// when is_override false ignore is_admin statuses during membership
// status calculation. similarly we did fix for import in CRM-3570.
if (empty($params['is_override'])) {
$params['exclude_is_admin'] = TRUE;
}
// process date params to mysql date format.
$dateTypes = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate');
foreach ($dateTypes as $dateField => $dateVariable) {
${$dateVariable} = CRM_Utils_Date::processDate($formValues[$dateField]);
}
$memTypeNumTerms = empty($termsByType) ? CRM_Utils_Array::value('num_terms', $formValues) : NULL;
$calcDates = array();
foreach ($this->_memTypeSelected as $memType) {
if (empty($memTypeNumTerms)) {
$memTypeNumTerms = CRM_Utils_Array::value($memType, $termsByType, 1);
}
$calcDates[$memType] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate, $memTypeNumTerms);
}
foreach ($calcDates as $memType => $calcDate) {
foreach (array_keys($dateTypes) as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $formValues);
if (!$date) {
$date = CRM_Utils_Array::value($d, $calcDate);
}
$membershipTypeValues[$memType][$d] = CRM_Utils_Date::processDate($date);
//$params[$d] = CRM_Utils_Date::processDate( $date );
}
}
// max related memberships - take from form or inherit from membership type
foreach ($this->_memTypeSelected as $memType) {
if (array_key_exists('max_related', $formValues)) {
$membershipTypeValues[$memType]['max_related'] = CRM_Utils_Array::value('max_related', $formValues);
}
}
if ($this->_id) {
$ids['membership'] = $params['id'] = $this->_id;
}
$session = CRM_Core_Session::singleton();
$ids['userId'] = $session->get('userID');
// membership type custom data
foreach ($this->_memTypeSelected as $memType) {
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $memType);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
$membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership');
}
foreach ($this->_memTypeSelected as $memType) {
$membershipTypes[$memType] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memType);
}
示例6: completeTransaction
function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE)
{
$contribution =& $objects['contribution'];
$memberships =& $objects['membership'];
if (is_numeric($memberships)) {
$memberships = array($objects['membership']);
}
$participant =& $objects['participant'];
$event =& $objects['event'];
$changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
$recurContrib =& $objects['contributionRecur'];
$values = array();
if ($input['component'] == 'contribute') {
if ($contribution->contribution_page_id) {
CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
$source = ts('Online Contribution') . ': ' . $values['title'];
} elseif ($recurContrib->id) {
$contribution->contribution_page_id = NULL;
$values['amount'] = $recurContrib->amount;
$values['contribution_type_id'] = $objects['contributionType']->id;
$values['title'] = $source = ts('Offline Recurring Contribution');
$values['is_email_receipt'] = $recurContrib->is_email_receipt;
$domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
$values['receipt_from_name'] = $domainValues[0];
$values['receipt_from_email'] = $domainValues[1];
}
$contribution->source = $source;
if (CRM_Utils_Array::value('is_email_receipt', $values)) {
$contribution->receipt_date = self::$_now;
}
if (!empty($memberships)) {
foreach ($memberships as $membershipTypeIdKey => $membership) {
if ($membership) {
$format = '%Y%m%d';
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
// CRM-8141 update the membership type with the value recorded in log when membership created/renewed
// this picks up membership type changes during renewals
$sql = "\nSELECT membership_type_id\nFROM civicrm_membership_log\nWHERE membership_id={$membership->id}\nORDER BY id DESC\nLIMIT 1;";
$dao = new CRM_Core_DAO();
$dao->query($sql);
if ($dao->fetch()) {
if (!empty($dao->membership_type_id)) {
$membership->membership_type_id = $dao->membership_type_id;
$membership->save();
}
// else fall back to using current membership type
}
// else fall back to using current membership type
$dao->free();
if ($currentMembership) {
/*
* Fixed FOR CRM-4433
* In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
* when Contribution mode is notify and membership is for renewal )
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday);
$dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
} else {
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id);
}
//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE);
$formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format), 'reminder_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('reminder_date', $dates), $format));
//we might be renewing membership,
//so make status override false.
$formatedParams['is_override'] = FALSE;
$membership->copyValues($formatedParams);
$membership->save();
//updating the membership log
$membershipLog = array();
$membershipLog = $formatedParams;
$logStartDate = $formatedParams['start_date'];
if (CRM_Utils_Array::value('log_start_date', $dates)) {
$logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
$logStartDate = CRM_Utils_Date::isoToMysql($logStartDate);
}
$membershipLog['start_date'] = $logStartDate;
$membershipLog['membership_id'] = $membership->id;
$membershipLog['modified_id'] = $membership->contact_id;
$membershipLog['modified_date'] = date('Ymd');
$membershipLog['membership_type_id'] = $membership->membership_type_id;
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
//update related Memberships.
CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
//update the membership type key of membership relatedObjects array
//if it has changed after membership update
if ($membershipTypeIdKey != $membership->membership_type_id) {
$memberships[$membership->membership_type_id] = $membership;
$contribution->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
unset($contribution->_relatedObjects['membership'][$membershipTypeIdKey]);
unset($memberships[$membershipTypeIdKey]);
}
}
}
}
} else {
// event
$eventParams = array('id' => $objects['event']->id);
$values['event'] = array();
//.........这里部分代码省略.........
示例7: transitionComponents
//.........这里部分代码省略.........
//CRM-4523
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
// CRM-8141 update the membership type with the value recorded in log when membership created/renewed
// this picks up membership type changes during renewals
$sql = "\n SELECT membership_type_id\n FROM civicrm_membership_log\n WHERE membership_id={$membership->id}\n ORDER BY id DESC\n LIMIT 1;";
$dao = new CRM_Core_DAO();
$dao->query($sql);
if ($dao->fetch()) {
if (!empty($dao->membership_type_id)) {
$membership->membership_type_id = $dao->membership_type_id;
$membership->save();
}
}
// else fall back to using current membership type
$dao->free();
// Figure out number of terms
$numterms = 1;
$lineitems = CRM_Price_BAO_LineItem::getLineItems($contributionId, 'contribution');
foreach ($lineitems as $lineitem) {
if ($membership->membership_type_id == CRM_Utils_Array::value('membership_type_id', $lineitem)) {
$numterms = CRM_Utils_Array::value('membership_num_terms', $lineitem);
// in case membership_num_terms comes through as null or zero
$numterms = $numterms >= 1 ? $numterms : 1;
break;
}
}
// CRM-15735-to update the membership status as per the contribution receive date
$joinDate = NULL;
if (!empty($params['receive_date'])) {
$joinDate = $params['receive_date'];
$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($membership->start_date, $membership->end_date, $membership->join_date, $params['receive_date'], FALSE, $membership->membership_type_id, (array) $membership);
$membership->status_id = CRM_Utils_Array::value('id', $status, $membership->status_id);
$membership->save();
}
if ($currentMembership) {
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, NULL);
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, NULL, NULL, $numterms);
$dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
} else {
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, $joinDate, NULL, NULL, $numterms);
}
//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membership->membership_type_id, (array) $membership);
$formattedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, array_search('Current', $membershipStatuses)), 'join_date' => CRM_Utils_Date::customFormat($dates['join_date'], $format), 'start_date' => CRM_Utils_Date::customFormat($dates['start_date'], $format), 'end_date' => CRM_Utils_Date::customFormat($dates['end_date'], $format));
CRM_Utils_Hook::pre('edit', 'Membership', $membership->id, $formattedParams);
$membership->copyValues($formattedParams);
$membership->save();
//updating the membership log
$membershipLog = array();
$membershipLog = $formattedParams;
$logStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('log_start_date', $dates), $format);
$logStartDate = $logStartDate ? CRM_Utils_Date::isoToMysql($logStartDate) : $formattedParams['start_date'];
$membershipLog['start_date'] = $logStartDate;
$membershipLog['membership_id'] = $membership->id;
$membershipLog['modified_id'] = $membership->contact_id;
$membershipLog['modified_date'] = date('Ymd');
$membershipLog['membership_type_id'] = $membership->membership_type_id;
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
//update related Memberships.
CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formattedParams);
$updateResult['membership_end_date'] = CRM_Utils_Date::customFormat($dates['end_date'], '%B %E%f, %Y');
$updateResult['updatedComponents']['CiviMember'] = $membership->status_id;
if ($processContributionObject) {
$processContribution = TRUE;
}
CRM_Utils_Hook::post('edit', 'Membership', $membership->id, $membership);
}
}
}
if ($participant) {
$updatedStatusId = array_search('Registered', $participantStatuses);
CRM_Event_BAO_Participant::updateParticipantStatus($participant->id, $oldStatus, $updatedStatusId, TRUE);
$updateResult['updatedComponents']['CiviEvent'] = $updatedStatusId;
if ($processContributionObject) {
$processContribution = TRUE;
}
}
if ($pledgePayment) {
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, $contributionStatusId);
$updateResult['updatedComponents']['CiviPledge'] = $contributionStatusId;
if ($processContributionObject) {
$processContribution = TRUE;
}
}
}
// process contribution object.
if ($processContribution) {
$contributionParams = array();
$fields = array('contact_id', 'total_amount', 'receive_date', 'is_test', 'campaign_id', 'payment_instrument_id', 'trxn_id', 'invoice_id', 'financial_type_id', 'contribution_status_id', 'non_deductible_amount', 'receipt_date', 'check_number');
foreach ($fields as $field) {
if (empty($params[$field])) {
continue;
}
$contributionParams[$field] = $params[$field];
}
$ids = array('contribution' => $contributionId);
$contribution = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
}
return $updateResult;
}
示例8: renewMembership
//.........这里部分代码省略.........
if ($form->_values['title']) {
$currentMembership['source'] = ts('Online Contribution:') . ' ' . $form->_values['title'];
} else {
$currentMembership['source'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $currentMembership['id'], 'source');
}
}
if (CRM_Utils_Array::value('id', $currentMembership)) {
$ids['membership'] = $currentMembership['id'];
}
$memParams = $currentMembership;
//set the log start date.
$memParams['log_start_date'] = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
} else {
// CURRENT Membership
$membership = new CRM_Member_DAO_Membership();
$membership->id = $currentMembership['id'];
$membership->find(true);
require_once 'CRM/Member/BAO/MembershipType.php';
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday);
// Insert renewed dates for CURRENT membership
$memParams = array();
$memParams['join_date'] = CRM_Utils_Date::isoToMysql($membership->join_date);
$memParams['start_date'] = CRM_Utils_Date::isoToMysql($membership->start_date);
$memParams['end_date'] = CRM_Utils_Array::value('end_date', $dates);
$memParams['reminder_date'] = CRM_Utils_Array::value('reminder_date', $dates);
//set the log start date.
$memParams['log_start_date'] = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
if (empty($membership->source)) {
if (CRM_Utils_Array::value('membership_source', $form->_params)) {
$currentMembership['source'] = $form->_params['membership_source'];
} else {
if (CRM_Utils_Array::value('title', $form->_values)) {
$currentMembership['source'] = ts('Online Contribution:') . ' ' . $form->_values['title'];
} else {
$currentMembership['source'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $currentMembership['id'], 'source');
}
}
}
if (CRM_Utils_Array::value('id', $currentMembership)) {
$ids['membership'] = $currentMembership['id'];
}
}
//CRM-4555
if ($pending) {
$updateStatusId = array_search('Pending', $allStatus);
}
} else {
// NEW Membership
$activityType = 'Membership Signup';
$memParams = array('contact_id' => $contactID, 'membership_type_id' => $membershipTypeID);
if (!$pending) {
require_once 'CRM/Member/BAO/MembershipType.php';
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeID);
$memParams['join_date'] = CRM_Utils_Array::value('join_date', $dates);
$memParams['start_date'] = CRM_Utils_Array::value('start_date', $dates);
$memParams['end_date'] = CRM_Utils_Array::value('end_date', $dates);
$memParams['reminder_date'] = CRM_Utils_Array::value('reminder_date', $dates);
require_once 'CRM/Member/BAO/MembershipStatus.php';
$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate(CRM_Utils_Date::customFormat($dates['start_date'], $statusFormat), CRM_Utils_Date::customFormat($dates['end_date'], $statusFormat), CRM_Utils_Date::customFormat($dates['join_date'], $statusFormat), 'today', true);
$updateStatusId = CRM_Utils_Array::value('id', $status);
} else {
// if IPN/Pay-Later set status to: PENDING
$updateStatusId = array_search('Pending', $allStatus);
}
if (CRM_Utils_Array::value('membership_source', $form->_params)) {
$memParams['source'] = $form->_params['membership_source'];
} else {
$memParams['source'] = ts('Online Contribution:') . ' ' . $form->_values['title'];
}
$memParams['contribution_recur_id'] = CRM_Utils_Array::value('contributionRecurID', $form->_params);
$memParams['is_test'] = $is_test;
$memParams['is_pay_later'] = $form->_params['is_pay_later'];
}
//CRM-4555
//if we decided status here and want to skip status
//calculation in create( ); than need to pass 'skipStatusCal'.
if ($updateStatusId) {
$memParams['status_id'] = $updateStatusId;
$memParams['skipStatusCal'] = true;
}
//since we are renewing,
//make status override false.
$memParams['is_override'] = false;
//CRM-4027, create log w/ individual contact.
if ($modifiedID) {
$ids['userId'] = $modifiedID;
$memParams['is_for_organization'] = true;
} else {
$ids['userId'] = $contactID;
}
$membership =& self::create($memParams, $ids, false, $activityType);
// not sure why this statement is here, seems quite odd :( - Lobo: 12/26/2010
// related to: http://forum.civicrm.org/index.php/topic,11416.msg49072.html#msg49072
$membership->find(true);
if (!empty($dates)) {
$form->assign('mem_start_date', CRM_Utils_Date::customFormat($dates['start_date'], $format));
$form->assign('mem_end_date', CRM_Utils_Date::customFormat($dates['end_date'], $format));
}
return $membership;
}
示例9: processMembership
/**
* Process membership records.
*
* @param array $params
* Associated array of submitted values.
*
*
* @return bool
*/
private function processMembership(&$params)
{
$dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate');
$dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
// get the price set associated with offline membership
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
$this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
if (isset($params['field'])) {
$customFields = array();
foreach ($params['field'] as $key => $value) {
// if contact is not selected we should skip the row
if (empty($params['primary_contact_id'][$key])) {
continue;
}
$value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']);
// update contact information
$this->updateContactInfo($value);
$membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
foreach ($dateTypes as $dateField => $dateVariable) {
${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]);
$fDate[$dateField] = CRM_Utils_Array::value($dateField, $value);
}
$calcDates = array();
$calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate);
foreach ($calcDates as $memType => $calcDate) {
foreach ($dates as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $value);
if (!$date) {
$date = CRM_Utils_Array::value($d, $calcDate);
}
$value[$d] = CRM_Utils_Date::processDate($date);
}
}
if (!empty($value['send_receipt'])) {
$value['receipt_date'] = date('Y-m-d His');
}
if (!empty($value['membership_source'])) {
$value['source'] = $value['membership_source'];
}
unset($value['membership_source']);
//Get the membership status
if (!empty($value['membership_status'])) {
$value['status_id'] = $value['membership_status'];
unset($value['membership_status']);
}
if (empty($customFields)) {
// membership type custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
}
//check for custom data
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $key, 'Membership', $membershipTypeId);
if (!empty($value['financial_type'])) {
$value['financial_type_id'] = $value['financial_type'];
}
if (!empty($value['payment_instrument'])) {
$value['payment_instrument_id'] = $value['payment_instrument'];
}
// handle soft credit
if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
$value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
$value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
//CRM-15350: if soft-credit-type profile field is disabled or removed then
//we choose Gift as default value as per Gift Membership rule
if (!empty($params['soft_credit_type'][$key])) {
$value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
} else {
$value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
}
}
if (!empty($value['receive_date'])) {
$value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
}
$params['actualBatchTotal'] += $value['total_amount'];
unset($value['financial_type']);
unset($value['payment_instrument']);
$value['batch_id'] = $this->_batchId;
$value['skipRecentView'] = TRUE;
// make entry in line item for contribution
$editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
$editedResults = array();
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
if (!empty($editedResults)) {
unset($this->_priceSet['fields']);
$this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
unset($this->_priceSet['fields'][$editedResults['id']]['options']);
$fid = $editedResults['id'];
$editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
$editedResults = array();
CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
//.........这里部分代码省略.........
示例10: testGetDatesForMembershipType
/**
* check function getDatesForMembershipType( )
*
*/
public function testGetDatesForMembershipType()
{
$ids = array();
$params = array('name' => 'General', 'description' => NULL, 'minimum_fee' => 100, 'domain_id' => 1, 'duration_unit' => 'year', 'member_of_contact_id' => $this->_orgContactID, 'period_type' => 'rolling', 'duration_interval' => 1, 'financial_type_id' => $this->_financialTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1);
$membership = CRM_Member_BAO_MembershipType::add($params, $ids);
$membershipDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->id);
$this->assertEquals($membershipDates['start_date'], date('Ymd'), 'Verify membership types details.');
$this->membershipTypeDelete(array('id' => $membership->id));
}
示例11: submit
//.........这里部分代码省略.........
}
}
///CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
if ($isQuickConfig && $submittedFinancialType) {
$li['financial_type_id'] = $submittedFinancialType;
}
}
}
$this->storeContactFields($formValues);
$params['contact_id'] = $this->_contactID;
$fields = array('status_id', 'source', 'is_override', 'campaign_id');
foreach ($fields as $f) {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
// fix for CRM-3724
// when is_override false ignore is_admin statuses during membership
// status calculation. similarly we did fix for import in CRM-3570.
if (empty($params['is_override'])) {
$params['exclude_is_admin'] = TRUE;
}
// process date params to mysql date format.
$dateTypes = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate');
foreach ($dateTypes as $dateField => $dateVariable) {
${$dateVariable} = CRM_Utils_Date::processDate($formValues[$dateField]);
}
$memTypeNumTerms = empty($termsByType) ? CRM_Utils_Array::value('num_terms', $formValues) : NULL;
$calcDates = array();
foreach ($this->_memTypeSelected as $memType) {
if (empty($memTypeNumTerms)) {
$memTypeNumTerms = CRM_Utils_Array::value($memType, $termsByType, 1);
}
$calcDates[$memType] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate, $memTypeNumTerms);
}
foreach ($calcDates as $memType => $calcDate) {
foreach (array_keys($dateTypes) as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $formValues);
if (!$date) {
$date = CRM_Utils_Array::value($d, $calcDate);
}
$membershipTypeValues[$memType][$d] = CRM_Utils_Date::processDate($date);
}
}
// max related memberships - take from form or inherit from membership type
foreach ($this->_memTypeSelected as $memType) {
if (array_key_exists('max_related', $formValues)) {
$membershipTypeValues[$memType]['max_related'] = CRM_Utils_Array::value('max_related', $formValues);
}
$membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $this->_id, 'Membership');
$membershipTypes[$memType] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memType);
}
$membershipType = implode(', ', $membershipTypes);
// Retrieve the name and email of the current user - this will be the FROM for the receipt email
list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
//CRM-13981, allow different person as a soft-contributor of chosen type
if ($this->_contributorContactID != $this->_contactID) {
$params['contribution_contact_id'] = $this->_contributorContactID;
if (!empty($formValues['soft_credit_type_id'])) {
$softParams['soft_credit_type_id'] = $formValues['soft_credit_type_id'];
$softParams['contact_id'] = $this->_contactID;
}
}
if (!empty($formValues['record_contribution'])) {
$recordContribution = array('total_amount', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'check_number', 'campaign_id', 'receive_date');
示例12: completeTransaction
function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = false)
{
$contribution =& $objects['contribution'];
$membership =& $objects['membership'];
$participant =& $objects['participant'];
$event =& $objects['event'];
$values = array();
if ($input['component'] == 'contribute') {
require_once 'CRM/Contribute/BAO/ContributionPage.php';
CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
$contribution->source = ts('Online Contribution') . ': ' . $values['title'];
if ($values['is_email_receipt']) {
$contribution->receipt_date = self::$_now;
}
if ($membership) {
$format = '%Y%m%d';
require_once 'CRM/Member/BAO/MembershipType.php';
require_once 'CRM/Member/BAO/Membership.php';
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
if ($currentMembership) {
/*
* Fixed FOR CRM-4433
* In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
* when Contribution mode is notify and membership is for renewal )
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday = null);
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday = null);
$dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
} else {
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id);
}
//get the status for membership.
require_once 'CRM/Member/BAO/MembershipStatus.php';
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', true);
$formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat($dates['join_date'], $format), 'start_date' => CRM_Utils_Date::customFormat($dates['start_date'], $format), 'end_date' => CRM_Utils_Date::customFormat($dates['end_date'], $format), 'reminder_date' => CRM_Utils_Date::customFormat($dates['reminder_date'], $format));
$membership->copyValues($formatedParams);
$membership->save();
//updating the membership log
$membershipLog = array();
$membershipLog = $formatedParams;
$logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
$logStartDate = $logStartDate ? CRM_Utils_Date::isoToMysql($logStartDate) : $formatedParams['start_date'];
$membershipLog['start_date'] = $logStartDate;
$membershipLog['membership_id'] = $membership->id;
$membershipLog['modified_id'] = $membership->contact_id;
$membershipLog['modified_date'] = date('Ymd');
require_once 'CRM/Member/BAO/MembershipLog.php';
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
//update related Memberships.
CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
}
} 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);
$contribution->source = ts('Online Event Registration') . ': ' . $values['event']['title'];
if ($values['event']['is_email_confirm']) {
$contribution->receipt_date = self::$_now;
}
$participant->status_id = 1;
$participant->save();
}
if ($input['net_amount'] == 0 && $input['fee_amount'] != 0) {
$input['net_amount'] = $input['amount'] - $input['fee_amount'];
}
$contribution->contribution_status_id = 1;
$contribution->is_test = $input['is_test'];
$contribution->fee_amount = $input['fee_amount'];
$contribution->net_amount = $input['net_amount'];
$contribution->trxn_id = $input['trxn_id'];
$contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
$contribution->cancel_date = 'null';
if (CRM_Utils_Array::value('check_number', $input)) {
$contribution->check_number = $input['check_number'];
}
if (CRM_Utils_Array::value('payment_instrument_id', $input)) {
$contribution->payment_instrument_id = $input['payment_instrument_id'];
}
$contribution->save();
// next create the transaction record
if (isset($objects['paymentProcessor'])) {
$paymentProcessor = $objects['paymentProcessor']['payment_processor_type'];
} else {
$paymentProcessor = '';
//.........这里部分代码省略.........
示例13: renewMembership
//.........这里部分代码省略.........
}
if (CRM_Utils_Array::value('id', $currentMembership)) {
$ids['membership'] = $currentMembership['id'];
}
$memParams = $currentMembership;
$memParams['membership_type_id'] = $membershipTypeID;
//set the log start date.
$memParams['log_start_date'] = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
} else {
// CURRENT Membership
$membership = new CRM_Member_DAO_Membership();
$membership->id = $currentMembership['id'];
$membership->find(TRUE);
// CRM-7297 Membership Upsell - calculate dates based on new membership type
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday, $membershipTypeID, $numRenewTerms);
// Insert renewed dates for CURRENT membership
$memParams = array();
$memParams['join_date'] = CRM_Utils_Date::isoToMysql($membership->join_date);
$memParams['start_date'] = CRM_Utils_Date::isoToMysql($membership->start_date);
$memParams['end_date'] = CRM_Utils_Array::value('end_date', $dates);
$memParams['membership_type_id'] = $membershipTypeID;
//set the log start date.
$memParams['log_start_date'] = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
if (empty($membership->source)) {
if (CRM_Utils_Array::value('membership_source', $form->_params)) {
$memParams['source'] = $form->_params['membership_source'];
} elseif (property_exists($form, '_values') && CRM_Utils_Array::value('title', $form->_values)) {
$memParams['source'] = ts('Online Contribution:') . ' ' . $form->_values['title'];
} else {
$memParams['source'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $currentMembership['id'], 'source');
}
}
if (CRM_Utils_Array::value('id', $currentMembership)) {
$ids['membership'] = $currentMembership['id'];
}
}
//CRM-4555
if ($pending) {
$updateStatusId = array_search('Pending', $allStatus);
}
} else {
// NEW Membership
$activityType = 'Membership Signup';
$memParams = array('contact_id' => $contactID, 'membership_type_id' => $membershipTypeID);
if (!$pending) {
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeID, NULL, NULL, NULL, $numRenewTerms);
$memParams['join_date'] = CRM_Utils_Array::value('join_date', $dates);
$memParams['start_date'] = CRM_Utils_Array::value('start_date', $dates);
$memParams['end_date'] = CRM_Utils_Array::value('end_date', $dates);
$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate(CRM_Utils_Date::customFormat($dates['start_date'], $statusFormat), CRM_Utils_Date::customFormat($dates['end_date'], $statusFormat), CRM_Utils_Date::customFormat($dates['join_date'], $statusFormat), 'today', TRUE, $membershipTypeID, $memParams);
$updateStatusId = CRM_Utils_Array::value('id', $status);
} else {
// if IPN/Pay-Later set status to: PENDING
$updateStatusId = array_search('Pending', $allStatus);
}
if (CRM_Utils_Array::value('membership_source', $form->_params)) {
$memParams['source'] = $form->_params['membership_source'];
} elseif (CRM_Utils_Array::value('title', $form->_values)) {
$memParams['source'] = ts('Online Contribution:') . ' ' . $form->_values['title'];
}
$memParams['contribution_recur_id'] = CRM_Utils_Array::value('contributionRecurID', $form->_params);
$memParams['is_test'] = $is_test;
$memParams['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $form->_params);
}
//CRM-4555
//if we decided status here and want to skip status
//calculation in create( ); then need to pass 'skipStatusCal'.
if ($updateStatusId) {
$memParams['status_id'] = $updateStatusId;
$memParams['skipStatusCal'] = TRUE;
}
//since we are renewing,
//make status override false.
$memParams['is_override'] = FALSE;
//CRM-4027, create log w/ individual contact.
if ($modifiedID) {
$ids['userId'] = $modifiedID;
$memParams['is_for_organization'] = TRUE;
} else {
$ids['userId'] = $contactID;
}
//inherit campaign from contrib page.
if (isset($form->_values) && is_array($form->_values) && !empty($form->_values)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $form->_params);
if (!array_key_exists('campaign_id', $form->_params)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
}
$memParams['campaign_id'] = $campaignId;
}
$memParams['custom'] = $customFieldsFormatted;
$membership = self::create($memParams, $ids, FALSE, $activityType);
// not sure why this statement is here, seems quite odd :( - Lobo: 12/26/2010
// related to: http://forum.civicrm.org/index.php/topic,11416.msg49072.html#msg49072
$membership->find(TRUE);
if (!empty($dates)) {
$form->assign('mem_start_date', CRM_Utils_Date::customFormat($dates['start_date'], $format));
$form->assign('mem_end_date', CRM_Utils_Date::customFormat($dates['end_date'], $format));
}
return $membership;
}
示例14: completeTransaction
function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE)
{
$contribution =& $objects['contribution'];
$primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
$memberships =& $objects['membership'];
if (is_numeric($memberships)) {
$memberships = array($objects['membership']);
}
$participant =& $objects['participant'];
$event =& $objects['event'];
$changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
$recurContrib =& $objects['contributionRecur'];
$values = array();
if (isset($input['is_email_receipt'])) {
$values['is_email_receipt'] = $input['is_email_receipt'];
}
$source = NULL;
if ($input['component'] == 'contribute') {
if ($contribution->contribution_page_id) {
CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
$source = ts('Online Contribution') . ': ' . $values['title'];
} elseif ($recurContrib && $recurContrib->id) {
$contribution->contribution_page_id = NULL;
$values['amount'] = $recurContrib->amount;
$values['financial_type_id'] = $objects['contributionType']->id;
$values['title'] = $source = ts('Offline Recurring Contribution');
$domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
$values['receipt_from_name'] = $domainValues[0];
$values['receipt_from_email'] = $domainValues[1];
}
if ($recurContrib && $recurContrib->id && !isset($input['is_email_receipt'])) {
//CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting
// but CRM-16124 if $input['is_email_receipt'] is set then that should not be overridden.
$values['is_email_receipt'] = $recurContrib->is_email_receipt;
}
$contribution->source = $source;
if (CRM_Utils_Array::value('is_email_receipt', $values)) {
$contribution->receipt_date = self::$_now;
}
if (!empty($memberships)) {
$membershipsUpdate = array();
foreach ($memberships as $membershipTypeIdKey => $membership) {
if ($membership) {
$format = '%Y%m%d';
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
// CRM-8141 update the membership type with the value recorded in log when membership created/renewed
// this picks up membership type changes during renewals
$sql = "\nSELECT membership_type_id\nFROM civicrm_membership_log\nWHERE membership_id={$membership->id}\nORDER BY id DESC\nLIMIT 1;";
$dao = new CRM_Core_DAO();
$dao->query($sql);
if ($dao->fetch()) {
if (!empty($dao->membership_type_id)) {
$membership->membership_type_id = $dao->membership_type_id;
$membership->save();
}
// else fall back to using current membership type
}
// else fall back to using current membership type
$dao->free();
$num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id, $primaryContributionID);
if ($currentMembership) {
/*
* Fixed FOR CRM-4433
* In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
* when Contribution mode is notify and membership is for renewal )
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
// @todo - we should pass membership_type_id instead of null here but not
// adding as not sure of testing
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday, NULL, $num_terms);
$dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
} else {
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, NULL, NULL, NULL, $num_terms);
}
//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membership->membership_type_id, (array) $membership);
$formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format));
//we might be renewing membership,
//so make status override false.
$formatedParams['is_override'] = FALSE;
$membership->copyValues($formatedParams);
$membership->save();
//updating the membership log
$membershipLog = array();
$membershipLog = $formatedParams;
$logStartDate = $formatedParams['start_date'];
if (CRM_Utils_Array::value('log_start_date', $dates)) {
$logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
$logStartDate = CRM_Utils_Date::isoToMysql($logStartDate);
}
$membershipLog['start_date'] = $logStartDate;
$membershipLog['membership_id'] = $membership->id;
$membershipLog['modified_id'] = $membership->contact_id;
$membershipLog['modified_date'] = date('Ymd');
$membershipLog['membership_type_id'] = $membership->membership_type_id;
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
//update related Memberships.
CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
//update the membership type key of membership relatedObjects array
//if it has changed after membership update
//.........这里部分代码省略.........
示例15: import
//.........这里部分代码省略.........
if (civicrm_error($newMembership)) {
array_unshift($values, $newMembership['is_error'] . " for Membership ID " . $formatValues['membership_id'] . ". Row was skipped.");
return CRM_Member_Import_Parser::ERROR;
} else {
$this->_newMemberships[] = $newMembership->id;
return CRM_Member_Import_Parser::VALID;
}
} else {
array_unshift($values, "Matching Membership record not found for Membership ID " . $formatValues['membership_id'] . ". Row was skipped.");
return CRM_Member_Import_Parser::ERROR;
}
}
}
//Format dates
$startDate = CRM_Utils_Date::customFormat($formatted['start_date'], '%Y-%m-%d');
$endDate = CRM_Utils_Date::customFormat($formatted['end_date'], '%Y-%m-%d');
$joinDate = CRM_Utils_Date::customFormat($formatted['join_date'], '%Y-%m-%d');
if ($this->_contactIdIndex < 0) {
//retrieve contact id using contact dedupe rule
$formatValues['contact_type'] = $this->_contactType;
$error = civicrm_check_contact_dedupe($formatValues);
if (civicrm_duplicate($error)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
if (count($matchedIDs) > 1) {
array_unshift($values, "Multiple matching contact records detected for this row. The membership was not imported");
return CRM_Member_Import_Parser::ERROR;
} else {
$cid = $matchedIDs[0];
$formatted['contact_id'] = $cid;
//fix for CRM-1924
require_once 'CRM/Member/BAO/MembershipStatus.php';
require_once 'CRM/Member/BAO/MembershipType.php';
require_once 'CRM/Member/PseudoConstant.php';
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($formatted['membership_type_id'], $joinDate, $startDate, $endDate);
self::formattedDates($calcDates, $formatted);
//fix for CRM-3570, exclude the statuses those having is_admin = 1
//now user can import is_admin if is override is true.
$excludeIsAdmin = false;
if (!CRM_Utils_Array::value('is_override', $formatted)) {
$formatted['exclude_is_admin'] = $excludeIsAdmin = true;
}
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', $excludeIsAdmin);
if (!$formatted['status_id']) {
$formatted['status_id'] = $calcStatus['id'];
} elseif (!CRM_Utils_Array::value('is_override', $formatted)) {
if (empty($calcStatus)) {
array_unshift($values, "Status in import row (" . $formatValues['status_id'] . ") does not match calculated status based on your configured Membership Status Rules. Record was not imported.");
return CRM_Member_Import_Parser::ERROR;
} else {
if ($formatted['status_id'] != $calcStatus['id']) {
//Status Hold" is either NOT mapped or is FALSE
array_unshift($values, "Status in import row (" . $formatValues['status_id'] . ") does not match calculated status based on your configured Membership Status Rules (" . $calcStatus['name'] . "). Record was not imported.");
return CRM_Member_Import_Parser::ERROR;
}
}
}
$newMembership = civicrm_contact_membership_create($formatted);
if (civicrm_error($newMembership)) {
array_unshift($values, $newMembership['error_message']);
return CRM_Member_Import_Parser::ERROR;
}
$this->_newMemberships[] = $newMembership['id'];
return CRM_Member_Import_Parser::VALID;
}
} else {
// Using new Dedupe rule.