本文整理汇总了PHP中CRM_Member_BAO_MembershipStatus类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_MembershipStatus类的具体用法?PHP CRM_Member_BAO_MembershipStatus怎么用?PHP CRM_Member_BAO_MembershipStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Member_BAO_MembershipStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: completeOrder
//.........这里部分代码省略.........
// 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 )
*/
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;
//CRM-17723 - reset static $relatedContactIds array()
$var = TRUE;
CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
civicrm_api3('Membership', 'create', $membershipParams);
}
}
}
} else {
if (empty($input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'])) {
if ($event->is_email_confirm) {
// @todo this should be set by the function that sends the mail after sending.
$contributionParams['receipt_date'] = $changeDate;
}
$participantParams['id'] = $participant->id;
$participantParams['status_id'] = 'Registered';
civicrm_api3('Participant', 'create', $participantParams);
}
}
$contributionParams['id'] = $contribution->id;
// CRM-19309 - if you update the contribution here with financial_type_id it can/will mess with $lineItem
// unsetting it here does NOT cause any other contribution test to fail!
unset($contributionParams['financial_type_id']);
$contributionResult = civicrm_api3('Contribution', 'create', $contributionParams);
// Add new soft credit against current $contribution.
if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id) {
CRM_Contribute_BAO_ContributionRecur::addrecurSoftCredit($objects['contributionRecur']->id, $contribution->id);
}
$contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1));
示例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;
}
}
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;
}
示例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: civicrm_api3_membership_status_calc
/**
* Derives the Membership Status of a given Membership Reocrd
*
* This API is used for deriving Membership Status of a given Membership
* record using the rules encoded in the membership_status table.
*
* @param Int $membershipID Id of a membership
* @param String $statusDate
*
* @return Array Array of status id and status name
* @public
*/
function civicrm_api3_membership_status_calc($membershipParams)
{
if (!($membershipID = CRM_Utils_Array::value('membership_id', $membershipParams))) {
return civicrm_api3_create_error('membershipParams do not contain membership_id');
}
$query = "\nSELECT start_date, end_date, join_date\n FROM civicrm_membership\n WHERE id = %1\n";
$params = array(1 => array($membershipID, 'Integer'));
$dao =& CRM_Core_DAO::executeQuery($query, $params);
if ($dao->fetch()) {
require_once 'CRM/Member/BAO/MembershipStatus.php';
// Take the is_admin column in MembershipStatus into consideration when requested
if (!CRM_Utils_Array::value('ignore_admin_only', $membershipParams)) {
$result =& CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dao->start_date, $dao->end_date, $dao->join_date, 'today', TRUE);
} else {
$result =& CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dao->start_date, $dao->end_date, $dao->join_date);
}
//make is error zero only when valid status found.
if (CRM_Utils_Array::value('id', $result)) {
$result['is_error'] = 0;
}
} else {
$result = civicrm_api3_create_error('did not find a membership record');
}
$dao->free();
return $result;
}
示例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: testgetMembershipStatusCurrent
public function testgetMembershipStatusCurrent()
{
$params = array('name' => 'Current', 'is_active' => 1, 'is_current_member' => 1);
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
$result = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
$this->assertEquals(empty($result), FALSE, 'Verify membership status records is_current_member.');
}
示例7: civicrm_api3_membership_status_calc
/**
* Derives the Membership Status of a given Membership Record.
*
* This API is used for deriving Membership Status of a given Membership
* record using the rules encoded in the membership_status table.
*
* @param array $membershipParams
*
* @throws API_Exception
*
* @return array
* Array of status id and status name
*/
function civicrm_api3_membership_status_calc($membershipParams)
{
if (!($membershipID = CRM_Utils_Array::value('membership_id', $membershipParams))) {
throw new API_Exception('membershipParams do not contain membership_id');
}
if (empty($membershipParams['id'])) {
//for consistency lets make sure id is set as this will get passed to hooks downstream
$membershipParams['id'] = $membershipID;
}
$query = "\nSELECT start_date, end_date, join_date, membership_type_id\n FROM civicrm_membership\n WHERE id = %1\n";
$params = array(1 => array($membershipID, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
if ($dao->fetch()) {
$membershipTypeID = empty($membershipParams['membership_type_id']) ? $dao->membership_type_id : $membershipParams['membership_type_id'];
$result = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dao->start_date, $dao->end_date, $dao->join_date, 'today', CRM_Utils_Array::value('ignore_admin_only', $membershipParams), $membershipTypeID, $membershipParams);
//make is error zero only when valid status found.
if (!empty($result['id'])) {
$result['is_error'] = 0;
}
} else {
$dao->free();
throw new API_Exception('did not find a membership record');
}
$dao->free();
return $result;
}
示例8: civicrm_api3_membership_get
/**
* Get contact Membership record.
*
* This api will return the membership records for the contacts
* having membership based on the relationship with the direct members.
*
* @param array $params
* Key/value pairs for contact_id and some.
* options affecting the desired results; has legacy support
* for just passing the contact_id itself as the argument
*
* @return array
* Array of all found membership property values.
*/
function civicrm_api3_membership_get($params)
{
$activeOnly = $membershipTypeId = $membershipType = NULL;
$contactID = CRM_Utils_Array::value('contact_id', $params);
if (!empty($params['filters']) && is_array($params['filters']) && isset($params['filters']['is_current'])) {
$activeOnly = $params['filters']['is_current'];
unset($params['filters']['is_current']);
}
$activeOnly = CRM_Utils_Array::value('active_only', $params, $activeOnly);
if ($activeOnly && empty($params['status_id'])) {
$params['status_id'] = array('IN' => CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent());
}
$options = _civicrm_api3_get_options_from_params($params, TRUE, 'Membership', 'get');
if ($options['is_count']) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
$membershipValues = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Membership');
$return = $options['return'];
if (empty($membershipValues) || !empty($return) && !array_key_exists('related_contact_id', $return) && !array_key_exists('relationship_name', $return)) {
return civicrm_api3_create_success($membershipValues, $params, 'Membership', 'get');
}
$members = _civicrm_api3_membership_relationsship_get_customv2behaviour($params, $membershipValues, $contactID);
return civicrm_api3_create_success($members, $params, 'Membership', 'get');
}
示例9: crm_calc_membership_status
/**
* Derives the Membership Status of a given Membership Reocrd
*
* This API is used for deriving Membership Status of a given Membership
* record using the rules encoded in the membership_status table.
*
* @param Int $membershipID Id of a membership
* @param String $statusDate
*
* @return Array Array of status id and status name
* @public
*/
function crm_calc_membership_status($membershipID)
{
if (empty($membershipID)) {
return _crm_error('Invalid value for membershipID');
}
$query = "\nSELECT start_date, end_date, join_date\n FROM civicrm_membership\n WHERE id = %1\n";
$params = array(1 => array($membershipID, 'Integer'));
$dao =& CRM_Core_DAO::executeQuery($query, $params);
if ($dao->fetch()) {
require_once 'CRM/Member/BAO/MembershipStatus.php';
$result =& CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dao->start_date, $dao->end_date, $dao->join_date);
} else {
$result = null;
}
$dao->free();
return $result;
}
示例10: formRule
/**
* Function for validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @return mixed true or array of errors
* @access public
* @static
*/
static function formRule($params, $files, $contributionPageId = null)
{
$errors = array();
if (CRM_Utils_Array::value('is_active', $params)) {
// don't allow price set w/ membership signup, CRM-5095
require_once 'CRM/Price/BAO/Set.php';
if ($contributionPageId && CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $contributionPageId)) {
$errors['is_active'] = ts('You cannot enable both Membership Signup and Price Set on the same online contribution page.');
return $errors;
}
if (!isset($params['membership_type']) || !is_array($params['membership_type'])) {
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
} else {
$membershipType = array_values($params['membership_type']);
if (array_sum($membershipType) == 0) {
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
}
}
//for CRM-1302
//if Membership status is not present, then display an error message
require_once 'CRM/Member/BAO/MembershipStatus.php';
$dao = new CRM_Member_BAO_MembershipStatus();
if (!$dao->find()) {
$errors['_qf_default'] = ts('Add status rules, before configuring membership');
}
//give error if default is selected for an unchecked membership type
if (isset($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) {
$errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.');
}
if ($contributionPageId) {
require_once "CRM/Contribute/DAO/ContributionPage.php";
$amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
if (!$amountBlock && CRM_Utils_Array::value('is_separate_payment', $params)) {
$errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
}
}
}
return empty($errors) ? true : $errors;
}
示例11: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
require_once 'CRM/Member/BAO/MembershipStatus.php';
if ($this->_action & CRM_Core_Action::DELETE) {
$wt = CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipStatus', $this->_id);
CRM_Member_BAO_MembershipStatus::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'));
} else {
$params = $ids = array();
// store the submitted values in an array
$params = $this->exportValues();
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['membershipStatus'] = $this->_id;
}
if ($this->_id) {
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id');
}
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
// only for add mode, set label to name.
if ($this->_action & CRM_Core_Action::ADD) {
$params['name'] = $params['label'];
}
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', array(1 => $membershipStatus->label)));
}
}
示例12: preProcess
/**
* Heart of the viewing process. The runner gets all the meta data for
* the contact and calls the appropriate type of page to view.
*
* @return void
* @access public
*
*/
function preProcess()
{
CRM_Utils_System::setTitle(ts('CiviMember'));
$membershipSummary = array();
$preMonth = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
$preMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
$prePreMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 2, 01, date("Y"))), '%Y%m%d');
$preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
$today = getdate();
$date = CRM_Utils_Date::getToday();
$isCurrentMonth = 0;
$ym = CRM_Utils_Array::value('date', $_GET);
if ($ym) {
if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) {
CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
}
$isPreviousMonth = 0;
$isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
$ymd = date('Ymd', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4)));
$monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
$current = CRM_Utils_Date::customFormat($date, '%Y%m%d');
} else {
$ym = sprintf("%04d%02d", $today['year'], $today['mon']);
$ymd = sprintf("%04d%02d%02d", $today['year'], $today['mon'], $today['mday']);
$monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
$current = NULL;
$isCurrentMonth = 1;
$isPreviousMonth = 1;
}
$monthStart = $ym . '01';
$yearStart = substr($ym, 0, 4) . '0101';
// $preMonthStart is the day before $monthStart
$preMonthStart = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, substr($ym, 4, 2) - 1, 01, substr($ym, 0, 4))), '%Y%m%d');
// $preYearStart is the day before $yearStart
$preYearStart = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, 12, 31, substr($ym, 0, 4) - 1)), '%Y%m%d');
$membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
// added
//$membership = new CRM_Member_BAO_Membership;
foreach ($membershipTypes as $key => $value) {
$membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd), 'name' => $value);
$membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd), 'name' => $value);
$membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value);
$membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd), 'name' => $value);
$membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd), 'name' => $value);
$membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value);
$membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd), 'name' => $value);
$membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd), 'name' => $value);
$membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value);
$membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value);
$membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd));
//LCD also get summary stats for membership owners
$membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1), 'name' => $value);
$membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1), 'name' => $value);
$membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1), 'name' => $value);
$membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1), 'name' => $value);
$membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1));
//LCD end
}
// LCD debug
//CRM_Core_Error::debug($membershipSummary);
$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
$status = implode(',', $status);
foreach ($membershipSummary as $typeID => $details) {
foreach ($details as $key => $value) {
switch ($key) {
case 'premonth':
$membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$preMonth}&joinEnd={$preMonthEnd}&start={$preMonth}&end={$preMonthEnd}");
$membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$prePreMonthEnd}&start={$preMonth}&end={$preMonthEnd}");
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}");
break;
case 'month':
$membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$monthStart}&joinEnd={$ymd}&start={$monthStart}&end={$ymd}");
$membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$preMonthStart}&start={$monthStart}&end={$ymd}");
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}");
break;
case 'year':
$membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$yearStart}&joinEnd={$ymd}&start={$yearStart}&end={$ymd}");
$membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$preYearStart}&start={$yearStart}&end={$ymd}");
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}");
break;
case 'current':
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}");
break;
case 'total':
if (!$isCurrentMonth) {
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}");
} else {
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}");
}
break;
//LCD add owner urls
//LCD add owner urls
//.........这里部分代码省略.........
示例13: preProcess
/**
* Heart of the viewing process. The runner gets all the meta data for
* the contact and calls the appropriate type of page to view.
*
* @return void
* @access public
*
*/
function preProcess()
{
require_once "CRM/Member/BAO/MembershipType.php";
require_once "CRM/Member/BAO/Membership.php";
CRM_Utils_System::setTitle(ts('CiviMember'));
$membershipSummary = array();
$preMonth = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
$preMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
$preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
$today = getdate();
$date = CRM_Utils_Date::getToday();
$isCurrentMonth = 0;
if ($ym = CRM_Utils_Array::value('date', $_GET)) {
if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) {
CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
}
$isPreviousMonth = 0;
$isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
$ymd = date('Ymd', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4)));
$monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
$current = CRM_Utils_Date::customFormat($date, '%Y%m%d');
} else {
$ym = sprintf("%04d%02d", $today['year'], $today['mon']);
$ymd = sprintf("%04d%02d%02d", $today['year'], $today['mon'], $today['mday']);
$monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
$current = null;
$isCurrentMonth = 1;
$isPreviousMonth = 1;
}
$monthStart = $ym . '01';
$yearStart = substr($ym, 0, 4) . '0101';
$membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(false);
//$membership = new CRM_Member_BAO_Membership;//added
foreach ($membershipTypes as $key => $value) {
$membershipSummary[$key]['premonth'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value);
$membershipSummary[$key]['month'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value);
$membershipSummary[$key]['year'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value);
$membershipSummary[$key]['current'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value);
$membershipSummary[$key]['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd));
}
require_once "CRM/Member/BAO/MembershipStatus.php";
$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
$status = implode(',', $status);
foreach ($membershipSummary as $typeID => $details) {
foreach ($details as $key => $value) {
switch ($key) {
case 'premonth':
$membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}");
break;
case 'month':
$membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}");
break;
case 'year':
$membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}");
break;
case 'current':
$membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}");
break;
case 'total':
if (!$isCurrentMonth) {
$membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}");
} else {
$membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}");
}
break;
}
}
}
$totalCount = array();
$totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
foreach ($membershipSummary as $key => $value) {
$totalCountPreMonth = $totalCountPreMonth + $value['premonth']['count'];
$totalCountMonth = $totalCountMonth + $value['month']['count'];
$totalCountYear = $totalCountYear + $value['year']['count'];
$totalCountCurrent = $totalCountCurrent + $value['current']['count'];
$totalCountTotal = $totalCountTotal + $value['total']['count'];
}
$totalCount['premonth'] = array("count" => $totalCountPreMonth, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$preMonth}&end={$preMonthEnd}"));
$totalCount['month'] = array("count" => $totalCountMonth, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$monthStart}&end={$ymd}"));
$totalCount['year'] = array("count" => $totalCountYear, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$yearStart}&end={$ymd}"));
$totalCount['current'] = array("count" => $totalCountCurrent, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
$totalCount['total'] = array("count" => $totalCountTotal, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
if (!$isCurrentMonth) {
$totalCount['total'] = array("count" => $totalCountTotal, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}"));
}
$this->assign('membershipSummary', $membershipSummary);
$this->assign('totalCount', $totalCount);
$this->assign('month', date('F', $monthStartTs));
$this->assign('year', date('Y', $monthStartTs));
$this->assign('premonth', date('F', $preMonthYear));
$this->assign('currentMonth', date('F'));
$this->assign('currentYear', date('Y'));
//.........这里部分代码省略.........
示例14: formRule
/**
* Function for validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @return mixed true or array of errors
* @access public
* @static
*/
static function formRule($params, $files, $contributionPageId = NULL)
{
$errors = array();
if (CRM_Utils_Array::value('member_price_set_id', $params)) {
//check if this price set has membership type both auto-renew and non-auto-renew memberships.
$bothTypes = CRM_Price_BAO_PriceSet::checkMembershipPriceSet($params['member_price_set_id']);
//check for supporting payment processors
//if both auto-renew and non-auto-renew memberships
if ($bothTypes) {
$paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'payment_processor');
$paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
if (!empty($paymentProcessorId)) {
$paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
foreach ($paymentProcessorId as $pid) {
if ($pid) {
$paymentProcessorTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $pid, 'payment_processor_type_id');
}
if (!($paymentProcessorTypeId == CRM_Utils_Array::key('PayPal', $paymentProcessorType) || $paymentProcessorTypeId == CRM_Utils_Array::key('AuthNet', $paymentProcessorType))) {
$errors['member_price_set_id'] = ts('The membership price set associated with this online contribution allows a user to select BOTH an auto-renew AND a non-auto-renew membership. This requires submitting multiple processor transactions, and is not supported for one or more of the payment processors enabled under the Fees tab.');
}
}
}
}
}
if (CRM_Utils_Array::value('member_is_active', $params)) {
// don't allow price set w/ membership signup, CRM-5095
if ($contributionPageId && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $contributionPageId, NULL, 1))) {
$extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
if ($extends != CRM_Core_Component::getComponentID('CiviMember')) {
$errors['member_is_active'] = ts('You cannot enable both Membership Signup and a Contribution Price Set on the same online contribution page.');
return $errors;
}
}
if ($contributionPageId && CRM_Utils_Array::value('member_price_set_id', $params) && CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active')) {
$errors['member_price_set_id'] = ts('You cannot use Membership Price Sets with the Contribution Amounts section. However, a membership price set may include additional fields for non-membership options that requires an additional fee (e.g. magazine subscription) or an additional voluntary contribution.');
}
if (CRM_Utils_Array::value('member_price_set_id', $params)) {
return $errors;
}
if (!isset($params['membership_type']) || !is_array($params['membership_type'])) {
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
} else {
$membershipType = array_values($params['membership_type']);
if (array_sum($membershipType) == 0) {
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
} elseif (array_sum($membershipType) > CRM_Price_Form_Field::NUM_OPTION) {
// for CRM-13079
$errors['membership_type'] = ts('You cannot select more than %1 choices. For more complex functionality, please use a Price Set.', array(1 => CRM_Price_Form_Field::NUM_OPTION));
}
}
//for CRM-1302
//if Membership status is not present, then display an error message
$dao = new CRM_Member_BAO_MembershipStatus();
if (!$dao->find()) {
$errors['_qf_default'] = ts('Add status rules, before configuring membership');
}
//give error if default is selected for an unchecked membership type
if (!empty($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) {
$errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.');
}
if ($contributionPageId) {
$amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
if (!$amountBlock && CRM_Utils_Array::value('is_separate_payment', $params)) {
$errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
}
}
}
return empty($errors) ? TRUE : $errors;
}
示例15: formRule
/**
* Validation.
*
* @param array $params
* (ref.) an assoc array of name/value pairs.
*
* @param $files
* @param int $contributionPageId
*
* @return bool|array
* mixed true or array of errors
*/
public static function formRule($params, $files, $contributionPageId = NULL)
{
$errors = array();
if (!empty($params['member_price_set_id'])) {
//check if this price set has membership type both auto-renew and non-auto-renew memberships.
$bothTypes = CRM_Price_BAO_PriceSet::isMembershipPriceSetContainsMixOfRenewNonRenew($params['member_price_set_id']);
//check for supporting payment processors
//if both auto-renew and non-auto-renew memberships
if ($bothTypes) {
$paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'payment_processor');
$paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
if (!empty($paymentProcessorId)) {
foreach ($paymentProcessorId as $pid) {
if ($pid) {
$processor = Civi\Payment\System::singleton()->getById($pid);
if (!$processor->supports('MultipleConcurrentPayments')) {
$errors['member_price_set_id'] = ts('The membership price set associated with this online contribution allows a user to select BOTH an auto-renew AND a non-auto-renew membership. This requires submitting multiple processor transactions, and is not supported for one or more of the payment processors enabled under the Amounts tab.');
}
}
}
}
}
}
if (!empty($params['member_is_active'])) {
// don't allow price set w/ membership signup, CRM-5095
if ($contributionPageId && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $contributionPageId, NULL, 1))) {
$extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
if ($extends != CRM_Core_Component::getComponentID('CiviMember')) {
$errors['member_is_active'] = ts('You cannot enable both Membership Signup and a Contribution Price Set on the same online contribution page.');
return $errors;
}
}
if (!empty($params['member_price_set_id'])) {
return $errors;
}
if (!isset($params['membership_type']) || !is_array($params['membership_type'])) {
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
} else {
$membershipType = array_values($params['membership_type']);
$isRecur = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_recur');
if (array_sum($membershipType) == 0) {
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
} elseif (array_sum($membershipType) > CRM_Price_Form_Field::NUM_OPTION) {
// for CRM-13079
$errors['membership_type'] = ts('You cannot select more than %1 choices. For more complex functionality, please use a Price Set.', array(1 => CRM_Price_Form_Field::NUM_OPTION));
} elseif ($isRecur) {
if (empty($params['is_separate_payment']) && array_sum($membershipType) != 0) {
$errors['is_separate_payment'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution');
} elseif (!empty($params['is_separate_payment'])) {
foreach ($params['membership_type'] as $mt => $dontCare) {
if (!empty($params["auto_renew_{$mt}"])) {
$errors["auto_renew_{$mt}"] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page');
break;
}
}
}
}
}
//for CRM-1302
//if Membership status is not present, then display an error message
$dao = new CRM_Member_BAO_MembershipStatus();
if (!$dao->find()) {
$errors['_qf_default'] = ts('Add status rules, before configuring membership');
}
//give error if default is selected for an unchecked membership type
if (!empty($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) {
$errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.');
}
if ($contributionPageId) {
$amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
if (!$amountBlock && !empty($params['is_separate_payment'])) {
$errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
}
}
}
return empty($errors) ? TRUE : $errors;
}