From 0fb22dad1eed788b056a30e20452fbcb4070ad51 Mon Sep 17 00:00:00 2001 From: Lisa Marie Maginnis Date: Mon, 21 Sep 2015 13:28:53 -0400 Subject: [PATCH] Priceset 2nd half --- CRM/Price/BAO/PriceSet.php | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 621f2aac28..09b17dfc8b 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -1065,7 +1065,7 @@ GROUP BY mt.member_of_contact_id"; // Auto renew checkbox should be frozen if for all the membership type auto renew is required // get the membership type auto renew option and check if required or optional - $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit + $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit, pf.id, pf.html_type FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id @@ -1077,7 +1077,10 @@ GROUP BY mt.member_of_contact_id"; $dao = CRM_Core_DAO::executeQuery($query, $params); $autoRenewOption = 2; - $interval = $unit = array(); + $interval = array(); + $unit = array(); + $type = array(); + while ($dao->fetch()) { if (!$dao->auto_renew) { $autoRenewOption = 0; @@ -1089,9 +1092,22 @@ GROUP BY mt.member_of_contact_id"; $interval[$dao->duration_interval] = $dao->duration_interval; $unit[$dao->duration_unit] = $dao->duration_unit; + $type[$dao->id] = $dao->html_type; } - if (count($interval) == 1 && count($unit) == 1 && $autoRenewOption > 0) { + // Autorenew is only a valid option when: + // + // * Only a single membership can be chosen (i.e. a single radio + // button group) + // + // OR + // + // * There is no variation in the duration intervals or units for + // all of the relevant membership types. + $sameDuration = count($interval) == 1 && count($unit) == 1; + $singleRadioGroup = array_values($type) == array('Radio'); + + if ($sameDuration || $singleRadioGroup) { return $autoRenewOption; } else { @@ -1103,17 +1119,24 @@ GROUP BY mt.member_of_contact_id"; * Function to retrieve auto renew frequency and interval * * @param int $priceSetId price set id + * @param array $priceFieldValueIds price field value ids (line items) * * @return array associate array of frequency interval and unit * @static * @access public */ - public static function getRecurDetails($priceSetId) { + public static function getRecurDetails($priceSetId, $priceFieldValueIds) { + // Escape the array of ids. + foreach ($priceFieldValueIds as $index => $id) { + $priceFieldValueIds[$index] = CRM_Utils_Type::escape($id, 'Integer'); + } + $query = 'SELECT mt.duration_interval, mt.duration_unit FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id - WHERE pf.price_set_id = %1 LIMIT 1'; + WHERE pf.price_set_id = %1 AND pfv.id IN (' + . implode(',', $priceFieldValueIds) . ') LIMIT 1'; $params = array(1 => array($priceSetId, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); -- 2.25.1