Skip to content

Commit

Permalink
Merge pull request #6264 from eileenmcnaughton/CRM-16867-extra-fn
Browse files Browse the repository at this point in the history
CRM-16867 add function to determin combination of membership types in  a priceset
  • Loading branch information
davecivicrm committed Jul 21, 2015
2 parents 06f898e + 37b1106 commit e6c58f8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
*
* @var array
*/
public $_params;
public $_params = array();

/**
* The fields involved in this contribution page
Expand Down
3 changes: 1 addition & 2 deletions CRM/Contribute/Form/ContributionPage/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
*/

/**
* form to process actions on the group aspect of Custom Data
* Form to process actions on the group aspect of Custom Data.
*/
class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_ContributionPage {

Expand Down
48 changes: 48 additions & 0 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,54 @@ public static function checkMembershipPriceSet($id) {
return FALSE;
}

/**
* Get an array of the membership types in a price set.
*
* @param int $id
*
* @return array(
* Membership types in the price set
*/
public static function getMembershipTypesFromPriceSet($id) {
$query
= "SELECT pfv.id, pfv.price_field_id, pfv.name, pfv.membership_type_id, pf.html_type, mt.auto_renew
FROM civicrm_price_field_value pfv
LEFT JOIN civicrm_price_field pf ON pf.id = pfv.price_field_id
LEFT JOIN civicrm_price_set ps ON ps.id = pf.price_set_id
LEFT JOIN civicrm_membership_type mt ON mt.id = pfv.membership_type_id
WHERE ps.id = %1
";

$params = array(1 => array($id, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);

$membershipTypes = array(
'all' => array(),
'autorenew' => array(),
'autorenew_required' => array(),
'autorenew_optional' => array(),
);
while ($dao->fetch()) {
if (empty($dao->membership_type_id)) {
continue;
}
$membershipTypes['all'][] = $dao->membership_type_id;
if (!empty($dao->auto_renew)) {
$membershipTypes['autorenew'][] = $dao->membership_type_id;
if ($dao->auto_renew == 2) {
$membershipTypes['autorenew_required'][] = $dao->membership_type_id;
}
else {
$membershipTypes['autorenew_optional'][] = $dao->membership_type_id;
}
}
else {
$membershipTypes['non_renew'][] = $dao->membership_type_id;
}
}
return $membershipTypes;
}

/**
* Copy priceSet when event/contibution page is copied
*
Expand Down

0 comments on commit e6c58f8

Please sign in to comment.