本文整理汇总了PHP中CRM_Member_BAO_Membership::getAllContactMembership方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_Membership::getAllContactMembership方法的具体用法?PHP CRM_Member_BAO_Membership::getAllContactMembership怎么用?PHP CRM_Member_BAO_Membership::getAllContactMembership使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Member_BAO_Membership
的用法示例。
在下文中一共展示了CRM_Member_BAO_Membership::getAllContactMembership方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formRule
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param CRM_Core_Form $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self)
{
$errors = array();
$amount = self::computeAmount($fields, $self->_values);
if (CRM_Utils_Array::value('auto_renew', $fields) && CRM_Utils_Array::value('payment_processor_id', $fields) == 0) {
$errors['auto_renew'] = ts('You cannot have auto-renewal on if you are paying later.');
}
if (!empty($fields['selectMembership']) && $fields['selectMembership'] != 'no_thanks' || !empty($fields['priceSetId']) && $self->_useForMember) {
$isTest = $self->_action & CRM_Core_Action::PREVIEW ? TRUE : FALSE;
$lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_membershipContactID, $isTest, TRUE);
$membershipOrgDetails = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization();
$unallowedOrgs = array();
foreach (array_keys($lifeMember) as $memTypeId) {
$unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
}
}
//check for atleast one pricefields should be selected
if (!empty($fields['priceSetId']) && empty($self->_ccid)) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $fields['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$check = array();
$membershipIsActive = TRUE;
$previousId = $otherAmount = FALSE;
while ($priceField->fetch()) {
if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
$previousId = $priceField->id;
if ($priceField->name == 'membership_amount' && !$priceField->is_active) {
$membershipIsActive = FALSE;
}
}
if ($priceField->name == 'other_amount') {
if ($self->_quickConfig && empty($fields["price_{$priceField->id}"]) && array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
$otherAmount = $priceField->id;
} elseif (!empty($fields["price_{$priceField->id}"])) {
$otherAmountVal = CRM_Utils_Rule::cleanMoney($fields["price_{$priceField->id}"]);
$min = CRM_Utils_Array::value('min_amount', $self->_values);
$max = CRM_Utils_Array::value('max_amount', $self->_values);
if ($min && $otherAmountVal < $min) {
$errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1', array(1 => $min));
}
if ($max && $otherAmountVal > $max) {
$errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.', array(1 => $max));
}
}
}
if (!empty($fields["price_{$priceField->id}"]) || $previousId == $priceField->id && isset($fields["price_{$previousId}"]) && empty($fields["price_{$previousId}"])) {
$check[] = $priceField->id;
}
}
$currentMemberships = NULL;
if ($membershipIsActive) {
$is_test = $self->_mode != 'live' ? 1 : 0;
$memContactID = $self->_membershipContactID;
// For anonymous user check using dedupe rule
// if user has Cancelled Membership
if (!$memContactID) {
$dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
$memContactID = CRM_Utils_Array::value(0, $ids);
}
$currentMemberships = CRM_Member_BAO_Membership::getContactsCancelledMembership($memContactID, $is_test);
$errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.';
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array::value('price_' . $fieldKey, $fields)) {
if (!is_array($fields['price_' . $fieldKey]) && isset($fieldValue['options'][$fields['price_' . $fieldKey]])) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$fields['price_' . $fieldKey]]) && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
}
} else {
if (is_array($fields['price_' . $fieldKey])) {
foreach (array_keys($fields['price_' . $fieldKey]) as $key) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$key]) && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$key]['membership_type_id'])));
}
}
}
}
}
}
}
// CRM-12233
if ($membershipIsActive && !$self->_membershipBlock['is_required'] && $self->_values['amount_block_is_active']) {
$membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
//.........这里部分代码省略.........
示例2: formRule
/**
* global form rule
*
* @param array $fields the input form values
* @param array $files the uploaded files if any
* @param array $options additional user data
*
* @return true if no errors, else array of errors
* @access public
* @static
*/
static function formRule($fields, $files, $self)
{
$errors = array();
$amount = self::computeAmount($fields, $self);
if (!empty($fields['selectMembership']) && $fields['selectMembership'] != 'no_thanks' || !empty($fields['priceSetId']) && $self->_useForMember) {
$lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_userID, FALSE, TRUE);
$membershipOrgDetails = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization();
$unallowedOrgs = array();
foreach (array_keys($lifeMember) as $memTypeId) {
$unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
}
}
//check for atleast one pricefields should be selected
if (!empty($fields['priceSetId'])) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $fields['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$check = array();
$membershipIsActive = TRUE;
$previousId = $otherAmount = FALSE;
while ($priceField->fetch()) {
if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
$previousId = $priceField->id;
if ($priceField->name == 'membership_amount' && !$priceField->is_active) {
$membershipIsActive = FALSE;
}
}
if ($priceField->name == 'other_amount') {
if ($self->_quickConfig && empty($fields["price_{$priceField->id}"]) && array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
$otherAmount = $priceField->id;
} elseif (!empty($fields["price_{$priceField->id}"])) {
$otherAmountVal = $fields["price_{$priceField->id}"];
$min = CRM_Utils_Array::value('min_amount', $self->_values);
$max = CRM_Utils_Array::value('max_amount', $self->_values);
if ($min && $otherAmountVal < $min) {
$errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1', array(1 => $min));
}
if ($max && $otherAmountVal > $max) {
$errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.', array(1 => $max));
}
}
}
if (!empty($fields["price_{$priceField->id}"]) || $previousId == $priceField->id && isset($fields["price_{$previousId}"]) && empty($fields["price_{$previousId}"])) {
$check[] = $priceField->id;
}
}
// CRM-12233
if ($membershipIsActive && !$self->_membershipBlock['is_required'] && $self->_values['amount_block_is_active']) {
$membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
// if 'No thank you' membership is selected then set $membershipFieldId
if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldKey, $fields) == 0) {
$membershipFieldId = $fieldKey;
} elseif ($membershipFieldId) {
if ($fieldValue['name'] == 'other_amount') {
$otherFieldId = $fieldKey;
} elseif ($fieldValue['name'] == 'contribution_amount') {
$contributionFieldId = $fieldKey;
}
if (!$errorKey || CRM_Utils_Array::value('price_' . $contributionFieldId, $fields) == '0') {
$errorKey = $fieldKey;
}
}
}
// $membershipFieldId is set and additional amount is 'No thank you' or NULL then throw error
if ($membershipFieldId && !(CRM_Utils_Array::value('price_' . $contributionFieldId, $fields, -1) > 0) && empty($fields['price_' . $otherFieldId])) {
$errors["price_{$errorKey}"] = ts('Additional Contribution is required.');
}
}
if (empty($check)) {
if ($self->_useForMember == 1 && $membershipIsActive) {
$errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
} else {
$errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
}
}
if ($otherAmount && !empty($check)) {
$errors["price_{$otherAmount}"] = ts('Amount is required field.');
}
if ($self->_useForMember == 1 && !empty($check) && $membershipIsActive) {
$priceFieldIDS = array();
$priceFieldMemTypes = array();
foreach ($self->_priceSet['fields'] as $priceId => $value) {
if (!empty($fields['price_' . $priceId]) || $self->_quickConfig && $value['name'] == 'membership_amount' && empty($self->_membershipBlock['is_required'])) {
if (!empty($fields['price_' . $priceId]) && is_array($fields['price_' . $priceId])) {
foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
if ($isSet) {
$priceFieldIDS[] = $priceFldVal;
//.........这里部分代码省略.........