本文整理汇总了PHP中CRM_Member_BAO_Membership::getContactMembership方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_Membership::getContactMembership方法的具体用法?PHP CRM_Member_BAO_Membership::getContactMembership怎么用?PHP CRM_Member_BAO_Membership::getContactMembership使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Member_BAO_Membership
的用法示例。
在下文中一共展示了CRM_Member_BAO_Membership::getContactMembership方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renewMembership
/**
* @param int $contactID
* @param int $membershipTypeID
* @param bool $is_test
* @param $changeToday
* @param int $modifiedID
* @param $customFieldsFormatted
* @param $numRenewTerms
* @param int $membershipID
* @param $pending
* @param int $contributionRecurID
* @param $membershipSource
* @param $isPayLater
* @param int $campaignId
* @param array $formDates
*
* @throws CRM_Core_Exception
* @return array
*/
public static function renewMembership($contactID, $membershipTypeID, $is_test, $changeToday, $modifiedID, $customFieldsFormatted, $numRenewTerms, $membershipID, $pending, $contributionRecurID, $membershipSource, $isPayLater, $campaignId, $formDates = array())
{
$renewalMode = $updateStatusId = FALSE;
$allStatus = CRM_Member_PseudoConstant::membershipStatus();
$format = '%Y%m%d';
$statusFormat = '%Y-%m-%d';
$membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID);
$dates = array();
// CRM-7297 - allow membership type to be be changed during renewal so long as the parent org of new membershipType
// is the same as the parent org of an existing membership of the contact
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($contactID, $membershipTypeID, $is_test, $membershipID, TRUE);
if ($currentMembership) {
$activityType = 'Membership Renewal';
$renewalMode = TRUE;
// Do NOT do anything.
//1. membership with status : PENDING/CANCELLED (CRM-2395)
//2. Paylater/IPN renew. CRM-4556.
if ($pending || in_array($currentMembership['status_id'], array(array_search('Pending', $allStatus), array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE))))) {
$membership = new CRM_Member_DAO_Membership();
$membership->id = $currentMembership['id'];
$membership->find(TRUE);
// CRM-8141 create a membership_log entry so that we will know the membership_type_id to change to when payment completed
$format = '%Y%m%d';
// note that we are logging the requested new membership_type_id that may be different than current membership_type_id
// it will be used when payment is received to update the membership_type_id to what was paid for
$logParams = array('membership_id' => $membership->id, 'status_id' => $membership->status_id, 'start_date' => CRM_Utils_Date::customFormat($membership->start_date, $format), 'end_date' => CRM_Utils_Date::customFormat($membership->end_date, $format), 'modified_date' => CRM_Utils_Date::customFormat(date('Ymd'), $format), 'membership_type_id' => $membershipTypeID, 'max_related' => !empty($membershipTypeDetails['max_related']) ? $membershipTypeDetails['max_related'] : NULL);
$session = CRM_Core_Session::singleton();
// If we have an authenticated session, set modified_id to that user's contact_id, else set to membership.contact_id
if ($session->get('userID')) {
$logParams['modified_id'] = $session->get('userID');
} else {
$logParams['modified_id'] = $membership->contact_id;
}
CRM_Member_BAO_MembershipLog::add($logParams);
if ($contributionRecurID) {
CRM_Core_DAO::setFieldValue('CRM_Member_DAO_Membership', $membership->id, 'contribution_recur_id', $contributionRecurID);
}
return array($membership, $renewalMode, $dates);
}
// Check and fix the membership if it is STALE
self::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
// Now Renew the membership
if (!$currentMembership['is_current_member']) {
// membership is not CURRENT
// CRM-7297 Membership Upsell - calculate dates based on new membership type
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($currentMembership['id'], $changeToday, $membershipTypeID, $numRenewTerms);
$currentMembership['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
foreach (array('start_date', 'end_date') as $dateType) {
$currentMembership[$dateType] = CRM_Utils_Array::value($dateType, $formDates);
if (empty($currentMembership[$dateType])) {
$currentMembership[$dateType] = CRM_Utils_Array::value($dateType, $dates);
}
}
$currentMembership['is_test'] = $is_test;
if (!empty($membershipSource)) {
$currentMembership['source'] = $membershipSource;
} else {
$currentMembership['source'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $currentMembership['id'], 'source');
}
if (!empty($currentMembership['id'])) {
$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', $formDates);
if (empty($memParams['end_date'])) {
$memParams['end_date'] = CRM_Utils_Array::value('end_date', $dates);
}
//.........这里部分代码省略.........
示例2: 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;
}
}
示例3: 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
//.........这里部分代码省略.........
示例4: setDefaultValues
//.........这里部分代码省略.........
$paymentAmount = 0;
$duePayment = FALSE;
foreach ($pledgePayments as $payId => $value) {
if ($value['status'] == 'Overdue') {
$this->_defaults['pledge_amount'][$payId] = 1;
$paymentAmount += $value['scheduled_amount'];
} elseif (!$duePayment && $value['status'] == 'Pending') {
$this->_defaults['pledge_amount'][$payId] = 1;
$paymentAmount += $value['scheduled_amount'];
$duePayment = TRUE;
} elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
$completedContributionIds[] = $value['contribution_id'];
}
}
$this->_defaults['price_' . $this->_priceSetId] = $paymentAmount;
if (count($completedContributionIds)) {
$softCredit = array();
foreach ($completedContributionIds as $id) {
$softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id);
}
if (isset($softCredit['soft_credit'])) {
$this->_defaults['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type'];
//since honoree profile fieldname of fields are prefixed with 'honor'
//we need to reformat the fieldname to append prefix during setting default values
CRM_Core_BAO_UFGroup::setProfileDefaults($softCredit['soft_credit'][1]['contact_id'], CRM_Core_BAO_UFGroup::getFields($this->_honoreeProfileId), $defaults);
foreach ($defaults as $fieldName => $value) {
$this->_defaults['honor[' . $fieldName . ']'] = $value;
}
}
}
} elseif (!empty($this->_values['pledge_block_id'])) {
//set default to one time contribution.
$this->_defaults['is_pledge'] = 0;
}
// to process Custom data that are appended to URL
$getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
$this->_defaults = array_merge($this->_defaults, $getDefaults);
$config = CRM_Core_Config::singleton();
// set default country from config if no country set
if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
$this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
}
// set default state/province from config if no state/province set
if (empty($this->_defaults["billing_state_province_id-{$this->_bltID}"])) {
$this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
}
$entityId = $memtypeID = NULL;
if ($this->_priceSetId) {
if ($this->_useForMember && !empty($this->_currentMemberships) || $this->_defaultMemTypeId) {
$selectedCurrentMemTypes = array();
foreach ($this->_priceSet['fields'] as $key => $val) {
foreach ($val['options'] as $keys => $values) {
$opMemTypeId = CRM_Utils_Array::value('membership_type_id', $values);
$priceFieldName = 'price_' . $values['price_field_id'];
$priceFieldValue = CRM_Price_BAO_PriceSet::getPriceFieldValueFromURL($this, $priceFieldName);
if (!empty($priceFieldValue)) {
CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $priceFieldValue, $val['html_type'], $this->_defaults);
// break here to prevent overwriting of default due to 'is_default'
// option configuration or setting of current membership or
// membership for related organization.
// The value sent via URL get's higher priority.
break;
} elseif ($opMemTypeId && in_array($opMemTypeId, $this->_currentMemberships) && !in_array($opMemTypeId, $selectedCurrentMemTypes)) {
CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
$memtypeID = $selectedCurrentMemTypes[] = $values['membership_type_id'];
} elseif (!empty($values['is_default']) && !$opMemTypeId && (!isset($this->_defaults[$priceFieldName]) || $val['html_type'] == 'CheckBox' && !isset($this->_defaults[$priceFieldName][$keys]))) {
CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
$memtypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_defaults[$priceFieldName], 'membership_type_id');
}
}
}
$entityId = CRM_Utils_Array::value('id', CRM_Member_BAO_Membership::getContactMembership($contactID, $memtypeID, NULL));
} else {
CRM_Price_BAO_PriceSet::setDefaultPriceSet($this, $this->_defaults);
}
}
//set custom field defaults set by admin if value is not set
if (!empty($this->_fields)) {
//load default campaign from page.
if (array_key_exists('contribution_campaign_id', $this->_fields)) {
$this->_defaults['contribution_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
}
//set custom field defaults
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $entityId, CRM_Profile_Form::MODE_REGISTER);
}
}
}
}
if (!empty($this->_paymentProcessors)) {
foreach ($this->_paymentProcessors as $pid => $value) {
if (!empty($value['is_default'])) {
$this->_defaults['payment_processor_id'] = $pid;
}
}
}
return $this->_defaults;
}
示例5: 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();
//.........这里部分代码省略.........
示例6: renewMembership
/**
* This method will renew / create the membership depending on
* whether the given contact has membership or not. And will add
* the modified dates for mebership and in the log table.
*
* @param int $contactID id of the contact
* @param int $membershipTypeID id of the membership type
* @param boolean $is_test if this is test contribution or live contribution
* @param object $form form object
* @param array $ipnParams array of name value pairs, to be used (for e.g source) when $form not present
* @param int $modifiedID individual contact id in case of On Behalf signup (CRM-4027 )
*
* @return object $membership object of membership
*
* @static
* @access public
*
**/
static function renewMembership($contactID, $membershipTypeID, $is_test, &$form, $changeToday = null, $modifiedID = null)
{
require_once 'CRM/Utils/Hook.php';
$statusFormat = '%Y-%m-%d';
$format = '%Y%m%d';
$ids = array();
//get all active statuses of membership.
require_once 'CRM/Member/PseudoConstant.php';
$allStatus = CRM_Member_PseudoConstant::membershipStatus();
// check is it pending. - CRM-4555
$pending = false;
if (($form->_contributeMode == 'notify' || $form->_params['is_pay_later'] || $form->_params['is_recur'] && $form->_contributeMode == 'direct') && ($form->_values['is_monetary'] && $form->_amount > 0.0)) {
$pending = true;
}
//decide status here, if needed.
$updateStatusId = null;
if ($currentMembership = CRM_Member_BAO_Membership::getContactMembership($contactID, $membershipTypeID, $is_test, $form->_membershipId)) {
$activityType = 'Membership Renewal';
$form->set("renewal_mode", true);
// Do NOT do anything.
//1. membership with status : PENDING/CANCELLED (CRM-2395)
//2. Paylater/IPN renew. CRM-4556.
if ($pending || in_array($currentMembership['status_id'], array(array_search('Pending', $allStatus), array_search('Cancelled', $allStatus)))) {
$membership = new CRM_Member_DAO_Membership();
$membership->id = $currentMembership['id'];
$membership->find(true);
return $membership;
}
//we might renew expired membership, CRM-6277
if (!$changeToday) {
if ($form->get('renewDate')) {
$changeToday = $form->get('renewDate');
} else {
if (get_class($form) == 'CRM_Contribute_Form_Contribution_Confirm') {
$changeToday = date('YmdHis');
}
}
}
// Check and fix the membership if it is STALE
self::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
// Now Renew the membership
if (!$currentMembership['is_current_member']) {
// membership is not CURRENT
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($currentMembership['id'], $changeToday);
$currentMembership['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
$currentMembership['start_date'] = CRM_Utils_Array::value('start_date', $dates);
$currentMembership['end_date'] = CRM_Utils_Array::value('end_date', $dates);
$currentMembership['reminder_date'] = CRM_Utils_Array::value('reminder_date', $dates);
$currentMembership['is_test'] = $is_test;
if ($form->_params['membership_source']) {
$currentMembership['source'] = $form->_params['membership_source'];
} else {
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'];
//.........这里部分代码省略.........
示例7: completeOrder
/**
* Complete an order.
*
* Do not call this directly - use the contribution.completetransaction api as this function is being refactored.
*
* Currently overloaded to complete a transaction & repeat a transaction - fix!
*
* Moving it out of the BaseIPN class is just the first step.
*
* @param array $input
* @param array $ids
* @param array $objects
* @param CRM_Core_Transaction $transaction
* @param int $recur
* @param CRM_Contribute_BAO_Contribution $contribution
* @param bool $isRecurring
* Duplication of param needs review. Only used by AuthorizeNetIPN
* @param int $isFirstOrLastRecurringPayment
* Deprecated param only used by AuthorizeNetIPN.
*/
public static function completeOrder(&$input, &$ids, $objects, $transaction, $recur, $contribution, $isRecurring, $isFirstOrLastRecurringPayment)
{
$primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
// The previous details are used when calculating line items so keep it before any code that 'does something'
if (!empty($contribution->id)) {
$input['prevContribution'] = CRM_Contribute_BAO_Contribution::getValues(array('id' => $contribution->id), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
}
$inputContributionWhiteList = array('fee_amount', 'net_amount', 'trxn_id', 'check_number', 'payment_instrument_id', 'is_test', 'campaign_id', 'receive_date');
$contributionParams = array_merge(array('contribution_status_id' => 'Completed'), array_intersect_key($input, array_fill_keys($inputContributionWhiteList, 1)));
$participant = CRM_Utils_Array::value('participant', $objects);
$memberships = CRM_Utils_Array::value('membership', $objects);
$recurContrib = CRM_Utils_Array::value('contributionRecur', $objects);
if (!empty($recurContrib->id)) {
$contributionParams['contribution_recur_id'] = $recurContrib->id;
}
self::repeatTransaction($contribution, $input, $contributionParams);
if (is_numeric($memberships)) {
$memberships = array($objects['membership']);
}
$changeDate = CRM_Utils_Array::value('trxn_date', $input, date('YmdHis'));
$values = array();
if (isset($input['is_email_receipt'])) {
$values['is_email_receipt'] = $input['is_email_receipt'];
}
if ($input['component'] == 'contribute') {
if ($contribution->contribution_page_id) {
CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
$contributionParams['source'] = ts('Online Contribution') . ': ' . $values['title'];
} elseif ($recurContrib && $recurContrib->id) {
$contributionParams['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;
}
if (!empty($values['is_email_receipt'])) {
$contributionParams['receipt_date'] = $changeDate;
}
if (!empty($memberships)) {
foreach ($memberships as $membershipTypeIdKey => $membership) {
if ($membership) {
$membershipParams = array('id' => $membership->id, 'contact_id' => $membership->contact_id, 'is_test' => $membership->is_test, 'membership_type_id' => $membership->membership_type_id);
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'], $membershipParams['membership_type_id'], $membershipParams['is_test'], $membershipParams['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={$membershipParams['id']}\nORDER BY id DESC\nLIMIT 1;";
$dao = CRM_Core_DAO::executeQuery($sql);
if ($dao->fetch()) {
if (!empty($dao->membership_type_id)) {
$membershipParams['membership_type_id'] = $dao->membership_type_id;
}
}
$dao->free();
$membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType($membershipParams['membership_type_id'], $primaryContributionID);
$dates = array_fill_keys(array('join_date', 'start_date', 'end_date'), NULL);
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, $changeDate);
// @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($membershipParams['id'], $changeDate, NULL, $membershipParams['num_terms']);
$dates['join_date'] = $currentMembership['join_date'];
}
//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membershipParams['membership_type_id'], $membershipParams);
$membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
//we might be renewing membership,
//so make status override false.
$membershipParams['is_override'] = FALSE;
//.........这里部分代码省略.........
示例8: preProcess
public function preProcess()
{
//custom data related code
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
$this->assign('cdType', FALSE);
if ($this->_cdType) {
$this->assign('cdType', TRUE);
return CRM_Custom_Form_CustomData::preProcess($this);
}
// get price set id.
$this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
$this->set('priceSetId', $this->_priceSetId);
$this->assign('priceSetId', $this->_priceSetId);
// action
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$this->_processors = array();
// check for edit permission
if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
}
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->assign('context', $this->_context);
if ($this->_id) {
$this->_memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "membership_type_id");
$this->_membershipIDs[] = $this->_id;
}
$this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
$this->assign('membershipMode', $this->_mode);
if ($this->_mode) {
$this->_paymentProcessor = array('billing_mode' => 1);
$validProcessors = array();
$processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
foreach ($processors as $ppID => $label) {
$paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
continue;
} elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
continue;
} else {
$paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
$error = $paymentObject->checkConfig();
if (empty($error)) {
$validProcessors[$ppID] = $label;
}
$paymentObject = NULL;
}
}
if (empty($validProcessors)) {
CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page'));
} else {
$this->_processors = $validProcessors;
}
// also check for billing information
// get the billing location type
$locationTypes = CRM_Core_PseudoConstant::locationType();
// CRM-8108 remove ts around Billing location type
//$this->_bltID = array_search( ts('Billing'), $locationTypes );
$this->_bltID = array_search('Billing', $locationTypes);
if (!$this->_bltID) {
CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
}
$this->set('bltID', $this->_bltID);
$this->assign('bltID', $this->_bltID);
$this->_fields = array();
CRM_Core_Payment_Form::setCreditCardFields($this);
// this required to show billing block
$this->assign_by_ref('paymentProcessor', $paymentProcessor);
$this->assign('hidePayPalExpress', TRUE);
}
if ($this->_action & CRM_Core_Action::ADD) {
//check whether any active membership statuses are available - redirects back to contact summary if not
CRM_Member_BAO_Membership::statusAvilability($this->_contactID);
if ($this->_contactID) {
//check whether contact has a current membership so we can alert user that they may want to do a renewal instead
$hasMembership = CRM_Member_BAO_Membership::getContactMembership($this->_contactID, NULL, 0);
if (!empty($hasMembership)) {
$hasMembership['membership_type'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $hasMembership['membership_type_id'], 'name', 'id');
$hasMembership['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $hasMembership['status_id'], 'label', 'id');
$membershipTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=member");
if ($this->_mode) {
$renewUrl = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$hasMembership['id']}&context=membership&selectedChild=member&mode=live");
} else {
$renewUrl = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$hasMembership['id']}&context=membership&selectedChild=member");
}
if (CRM_Utils_Array::value('membership_end_date', $hasMembership)) {
CRM_Core_Session::setStatus(ts('This contact has an existing %1 membership record with %2 status and end date of %3. <a href="%4">Click here if you want to renew this membership</a> (rather than creating a new membership record). <a href="%5">Click here to view all existing and / or expired memberships for this contact.</a>', array(1 => $hasMembership['membership_type'], 2 => $hasMembership['membership_status'], 3 => CRM_Utils_Date::customformat($hasMembership['membership_end_date']), 4 => $renewUrl, 5 => $membershipTab)));
} else {
CRM_Core_Session::setStatus(ts('This contact has an existing %1 membership record with %2 status. <a href="%3">Click here if you want to renew this membership</a> (rather than creating a new membership record). <a href="%4">Click here to view all existing and / or expired memberships for this contact.</a>', array(1 => $hasMembership['membership_type'], 2 => $hasMembership['membership_status'], 3 => $renewUrl, 4 => $membershipTab)));
}
}
}
}
// when custom data is included in this page
if (CRM_Utils_Array::value("hidden_custom", $_POST)) {
CRM_Custom_Form_CustomData::preProcess($this);
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
//.........这里部分代码省略.........
示例9: 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_PledgePayment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, $contributionStatusId);
$updateResult['updatedComponents']['CiviPledge'] = $contributionStatusId;
if ($processContributionObject) {
$processContribution = TRUE;
}
}
} elseif ($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;
} elseif (!$previousContriStatusId && $contribution->contribution_status_id != array_search('Pending', $contributionStatuses)) {
// this is case when we are going to process contribution object later.
return $updateResult;
}
if (is_array($memberships)) {
foreach ($memberships as $membership) {
if ($membership) {
$format = '%Y%m%d';
//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();
}
示例10: testGetContactMembership
public function testGetContactMembership()
{
$contactId = Contact::createIndividual();
$params = array('contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), 'start_date' => date('Ymd', strtotime('2006-01-21')), 'end_date' => date('Ymd', strtotime('2006-12-21')), 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID);
$ids = array();
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for created membership.');
$membership = CRM_Member_BAO_Membership::getContactMembership($contactId, $this->_membershipTypeID, FALSE);
$this->assertEquals($membership['id'], $membershipId, 'Verify membership record is retrieved.');
$this->membershipDelete($membershipId);
Contact::delete($contactId);
}
示例11: checkCurrentMembership
/**
* Check the current Membership having end date null.
*
* @param array $options
* @param int $userid
* Probably actually contact ID.
*
* @return bool
*/
public static function checkCurrentMembership(&$options, $userid)
{
if (!$userid || empty($options)) {
return FALSE;
}
static $_contact_memberships = array();
$checkLifetime = FALSE;
foreach ($options as $key => $value) {
if (!empty($value['membership_type_id'])) {
if (!isset($_contact_memberships[$userid][$value['membership_type_id']])) {
$_contact_memberships[$userid][$value['membership_type_id']] = CRM_Member_BAO_Membership::getContactMembership($userid, $value['membership_type_id'], FALSE);
}
$currentMembership = $_contact_memberships[$userid][$value['membership_type_id']];
if (!empty($currentMembership) && empty($currentMembership['end_date'])) {
unset($options[$key]);
$checkLifetime = TRUE;
}
}
}
if ($checkLifetime) {
return TRUE;
} else {
return FALSE;
}
}
示例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
/**
* @todo - this form method needs to have the interaction with the form layer removed from it
* as a BAO function. Note that the api now supports membership renewals & it is not clear this function does anything
* not done by the membership.create api (with a lot less unit tests)
*
* This method will renew / create the membership depending on
* whether the given contact has a membership or not. And will add
* the modified dates for membership and in the log table.
*
* @param int $contactID id of the contact
* @param int $membershipTypeID id of the new membership type
* @param boolean $is_test if this is test contribution or live contribution
* @param object $form form object
* @param array $ipnParams array of name value pairs, to be used (for e.g source) when $form not present
* @param int $modifiedID individual contact id in case of On Behalf signup (CRM-4027 )
* @param int $numRenewTerms how many membership terms are being added to end date (default is 1)
*
* @return object $membership object of membership
*
* @static
* @access public
*
**/
static function renewMembership($contactID, $membershipTypeID, $is_test, &$form, $changeToday = NULL, $modifiedID = NULL, $customFieldsFormatted = NULL, $numRenewTerms = 1, $paymentConfirmed = FALSE)
{
$statusFormat = '%Y-%m-%d';
$format = '%Y%m%d';
$ids = array();
//get all active statuses of membership.
$allStatus = CRM_Member_PseudoConstant::membershipStatus();
$membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID);
// check is it pending. - CRM-4555
$pending = FALSE;
//@todo this is a BAO function & should not inspect the form - the form should do this
// & pass required params to the BAO
if (CRM_Utils_Array::value('minimum_fee', $membershipTypeDetails) > 0.0) {
if ((isset($form->_contributeMode) && $form->_contributeMode == 'notify' || CRM_Utils_Array::value('is_pay_later', $form->_params) || CRM_Utils_Array::value('is_recur', $form->_params) && $form->_contributeMode == 'direct') && ($form->_values['is_monetary'] && $form->_amount > 0.0 || CRM_Utils_Array::value('separate_membership_payment', $form->_params) || CRM_Utils_Array::value('record_contribution', $form->_params))) {
$pending = TRUE;
}
}
if ($paymentConfirmed) {
$pending = FALSE;
}
//decide status here, if needed.
$updateStatusId = NULL;
$membershipID = NULL;
//@todo would be better to accept $membershipID as an FN param & make form layer responsible for extracting it
if (isset($form->_membershipId)) {
$membershipID = $form->_membershipId;
}
// CRM-7297 - allow membership type to be be changed during renewal so long as the parent org of new membershipType
// is the same as the parent org of an existing membership of the contact
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($contactID, $membershipTypeID, $is_test, $membershipID, TRUE);
if ($currentMembership) {
$activityType = 'Membership Renewal';
$form->set('renewal_mode', TRUE);
// Do NOT do anything.
//1. membership with status : PENDING/CANCELLED (CRM-2395)
//2. Paylater/IPN renew. CRM-4556.
if ($pending || in_array($currentMembership['status_id'], array(array_search('Pending', $allStatus), array_search('Cancelled', $allStatus)))) {
$membership = new CRM_Member_DAO_Membership();
$membership->id = $currentMembership['id'];
$membership->find(TRUE);
// CRM-8141 create a membership_log entry so that we will know the membership_type_id to change to when payment completed
$format = '%Y%m%d';
// note that we are logging the requested new membership_type_id that may be different than current membership_type_id
// it will be used when payment is received to update the membership_type_id to what was paid for
$logParams = array('membership_id' => $membership->id, 'status_id' => $membership->status_id, 'start_date' => CRM_Utils_Date::customFormat($membership->start_date, $format), 'end_date' => CRM_Utils_Date::customFormat($membership->end_date, $format), 'modified_date' => CRM_Utils_Date::customFormat(date('Ymd'), $format), 'membership_type_id' => $membershipTypeID, 'max_related' => $membershipTypeDetails['max_related']);
$session = CRM_Core_Session::singleton();
// If we have an authenticated session, set modified_id to that user's contact_id, else set to membership.contact_id
if ($session->get('userID')) {
$logParams['modified_id'] = $session->get('userID');
} else {
$logParams['modified_id'] = $membership->contact_id;
}
CRM_Member_BAO_MembershipLog::add($logParams, CRM_Core_DAO::$_nullArray);
if (CRM_Utils_Array::value('contributionRecurID', $form->_params)) {
CRM_Core_DAO::setFieldValue('CRM_Member_DAO_Membership', $membership->id, 'contribution_recur_id', $form->_params['contributionRecurID']);
}
return $membership;
}
//we renew expired membership, CRM-6277
if (!$changeToday) {
if ($form->get('renewalDate')) {
$changeToday = $form->get('renewalDate');
} elseif (get_class($form) == 'CRM_Contribute_Form_Contribution_Confirm') {
$changeToday = date('YmdHis');
}
}
// Check and fix the membership if it is STALE
self::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
// Now Renew the membership
if (!$currentMembership['is_current_member']) {
// membership is not CURRENT
// CRM-7297 Membership Upsell - calculate dates based on new membership type
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($currentMembership['id'], $changeToday, $membershipTypeID, $numRenewTerms);
$currentMembership['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
$currentMembership['start_date'] = CRM_Utils_Array::value('start_date', $dates);
$currentMembership['end_date'] = CRM_Utils_Array::value('end_date', $dates);
$currentMembership['is_test'] = $is_test;
//.........这里部分代码省略.........
示例14: completeOrder
/**
* Complete an order.
*
* Do not call this directly - use the contribution.completetransaction api as this function is being refactored.
*
* Currently overloaded to complete a transaction & repeat a transaction - fix!
*
* Moving it out of the BaseIPN class is just the first step.
*
* @param array $input
* @param array $ids
* @param array $objects
* @param CRM_Core_Transaction $transaction
* @param int $recur
* @param CRM_Contribute_BAO_Contribution $contribution
* @param bool $isRecurring
* Duplication of param needs review. Only used by AuthorizeNetIPN
* @param int $isFirstOrLastRecurringPayment
* Deprecated param only used by AuthorizeNetIPN.
*/
public static function completeOrder(&$input, &$ids, $objects, $transaction, $recur, $contribution, $isRecurring, $isFirstOrLastRecurringPayment)
{
$primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
// The previous details are used when calculating line items so keep it before any code that 'does something'
if (!empty($contribution->id)) {
$input['prevContribution'] = CRM_Contribute_BAO_Contribution::getValues(array('id' => $contribution->id), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
}
$inputContributionWhiteList = array('fee_amount', 'net_amount', 'trxn_id', 'check_number', 'payment_instrument_id', 'is_test', 'campaign_id', 'receive_date', 'receipt_date', 'contribution_status_id');
if (self::isSingleLineItem($primaryContributionID)) {
$inputContributionWhiteList[] = 'financial_type_id';
}
$participant = CRM_Utils_Array::value('participant', $objects);
$memberships = CRM_Utils_Array::value('membership', $objects);
$recurContrib = CRM_Utils_Array::value('contributionRecur', $objects);
$recurringContributionID = empty($recurContrib->id) ? NULL : $recurContrib->id;
$event = CRM_Utils_Array::value('event', $objects);
$paymentProcessorId = '';
if (isset($objects['paymentProcessor'])) {
if (is_array($objects['paymentProcessor'])) {
$paymentProcessorId = $objects['paymentProcessor']['id'];
} else {
$paymentProcessorId = $objects['paymentProcessor']->id;
}
}
$completedContributionStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
$contributionParams = array_merge(array('contribution_status_id' => $completedContributionStatusID, 'source' => self::getRecurringContributionDescription($contribution, $event)), array_intersect_key($input, array_fill_keys($inputContributionWhiteList, 1)));
$contributionParams['payment_processor'] = $input['payment_processor'] = $paymentProcessorId;
if ($recurringContributionID) {
$contributionParams['contribution_recur_id'] = $recurringContributionID;
}
$changeDate = CRM_Utils_Array::value('trxn_date', $input, date('YmdHis'));
if (empty($contributionParams['receive_date']) && $changeDate) {
$contributionParams['receive_date'] = $changeDate;
}
self::repeatTransaction($contribution, $input, $contributionParams, $paymentProcessorId);
$contributionParams['financial_type_id'] = $contribution->financial_type_id;
if (is_numeric($memberships)) {
$memberships = array($objects['membership']);
}
$values = array();
if (isset($input['is_email_receipt'])) {
$values['is_email_receipt'] = $input['is_email_receipt'];
}
if ($input['component'] == 'contribute') {
if ($contribution->contribution_page_id) {
// Figure out what we gain from this.
CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
} elseif ($recurContrib && $recurringContributionID) {
$values['amount'] = $recurContrib->amount;
$values['financial_type_id'] = $objects['contributionType']->id;
$values['title'] = $source = ts('Offline Recurring Contribution');
}
if ($recurContrib && $recurringContributionID && !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;
}
if (!empty($memberships)) {
foreach ($memberships as $membershipTypeIdKey => $membership) {
if ($membership) {
$membershipParams = array('id' => $membership->id, 'contact_id' => $membership->contact_id, 'is_test' => $membership->is_test, 'membership_type_id' => $membership->membership_type_id);
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'], $membershipParams['membership_type_id'], $membershipParams['is_test'], $membershipParams['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={$membershipParams['id']}\nORDER BY id DESC\nLIMIT 1;";
$dao = CRM_Core_DAO::executeQuery($sql);
if ($dao->fetch()) {
if (!empty($dao->membership_type_id)) {
$membershipParams['membership_type_id'] = $dao->membership_type_id;
}
}
$dao->free();
$membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType($membershipParams['membership_type_id'], $primaryContributionID);
$dates = array_fill_keys(array('join_date', 'start_date', 'end_date'), NULL);
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 )
*/
//.........这里部分代码省略.........