/** * 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; }