From: eileenmcnaugton Date: Tue, 11 Aug 2015 12:10:15 +0000 (+1200) Subject: CRM-16996 fix regression on form rule X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e4a6290df32ba56cbbd81501e4258a2ca056347d;p=civicrm-core.git CRM-16996 fix regression on form rule --- diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 06a3c8f8c6..c92e8d1d47 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -29,8 +29,6 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * */ /** @@ -72,6 +70,20 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { */ protected $membershipTypeRenewalStatus = array(); + /** + * Price set ID configured for the form. + * + * @var int + */ + public $_priceSetId; + + /** + * Price set details as an array. + * + * @var array + */ + public $_priceSet; + public function preProcess() { // Check for edit permission. if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index a5ed82ca84..3fb8e51cdb 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -114,15 +114,15 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { /** * Get selected membership type from the form values. * - * @param int $priceSetID + * @param array $priceSet * @param array $params * * @return array */ - public static function getSelectedMemberships($priceSetID, $params) { + public static function getSelectedMemberships($priceSet, $params) { $memTypeSelected = array(); - $priceFieldIDS = self::getPriceFieldIDs($params); - if ($priceSetID && is_array($priceFieldIDS)) { + $priceFieldIDS = self::getPriceFieldIDs($params, $priceSet); + if (!empty($priceSet) && is_array($priceFieldIDS)) { foreach ($priceFieldIDS as $priceFieldId) { if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) { $memTypeSelected[$id] = $id; @@ -139,28 +139,26 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { * Extract price set fields and values from $params. * * @param array $params + * @param array $priceSet * * @return array */ - public static function getPriceFieldIDs($params) { - $priceFieldIDS = $priceSet = $fieldIds = array(); - if (isset(self::$priceSet) && is_array(self::$priceSet)) { - $priceSet = self::$_priceSet; - if (isset($priceSet['fields']) && is_array($priceSet['fields'])) { - $fieldIds = array_keys($priceSet['fields']); - } - } - foreach ($fieldIds as $fieldId) { - if (!empty($params['price_' . $fieldId])) { - if (is_array($params['price_' . $fieldId])) { - foreach ($params['price_' . $fieldId] as $priceFldVal => $isSet) { - if ($isSet) { - $priceFieldIDS[] = $priceFldVal; + public static function getPriceFieldIDs($params, $priceSet) { + $priceFieldIDS = $fieldIds = array(); + if (isset($priceSet['fields']) && is_array($priceSet['fields'])) { + $fieldIds = array_keys($priceSet['fields']); + foreach ($fieldIds as $fieldId) { + if (!empty($params['price_' . $fieldId])) { + if (is_array($params['price_' . $fieldId])) { + foreach ($params['price_' . $fieldId] as $priceFldVal => $isSet) { + if ($isSet) { + $priceFieldIDS[] = $priceFldVal; + } } } - } - else { - $priceFieldIDS[] = $params['price_' . $fieldId]; + else { + $priceFieldIDS[] = $params['price_' . $fieldId]; + } } } } @@ -746,13 +744,13 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $errors = array(); $priceSetId = CRM_Utils_Array::value('price_set_id', $params); + $priceSetDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId); - $selectedMemberships = self::getSelectedMemberships($priceSetId, $params); - + $selectedMemberships = self::getSelectedMemberships($priceSetDetails[$priceSetId], $params); if ($priceSetId) { CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $params, $errors); - $priceFieldIDS = self::getPriceFieldIDs($params, $self); + $priceFieldIDS = self::getPriceFieldIDs($params, $priceSetDetails); if (!empty($priceFieldIDS)) { $ids = implode(',', $priceFieldIDS); @@ -1166,7 +1164,11 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { // In form mode these are set in preProcess. //TODO: set memberships, fixme $this->setContextVariables($formValues); - $this->_memTypeSelected = self::getSelectedMemberships($priceSetID, $formValues); + $priceSetDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID); + $this->_memTypeSelected = self::getSelectedMemberships( + $priceSetDetails[$priceSetID], + $formValues + ); $config = CRM_Core_Config::singleton();