comment fixes & spelling
[civicrm-core.git] / CRM / Member / Form / MembershipBlock.php
index 33717a6efc0a39d842ab920f68c7d3d75f933af6..055b2acfabad6ca10215f47592743d36841bec79 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -87,7 +87,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
           }
         }
 
-        if (CRM_Utils_Array::value('mem_price_field_id', $defaults)) {
+        if (!empty($defaults['mem_price_field_id'])) {
           $options = array();
           $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($defaults['mem_price_field_id'], $options, 'id', 1);
           foreach ($options as $k => $v) {
@@ -162,7 +162,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
         $this->assign('auto_renew', $this->_renewOption);
       }
       $this->addGroup($membership, 'membership_type', ts('Membership Types'));
-      $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'));
+      $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'))->setAttribute('allowClear', TRUE);
 
       $this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id);
     }
@@ -202,6 +202,9 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
    *
    * @param array $params (ref.) an assoc array of name/value pairs
    *
+   * @param $files
+   * @param null $contributionPageId
+   *
    * @return mixed true or array of errors
    * @access public
    * @static
@@ -209,7 +212,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
   static function formRule($params, $files, $contributionPageId = NULL) {
     $errors = array();
 
-    if (CRM_Utils_Array::value('member_price_set_id', $params)) {
+    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::checkMembershipPriceSet($params['member_price_set_id']);
 
@@ -239,7 +242,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
         }
       }
     }
-    if (CRM_Utils_Array::value('member_is_active', $params)) {
+    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))) {
@@ -251,12 +254,12 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
         }
       }
 
-      if ($contributionPageId && CRM_Utils_Array::value('member_price_set_id', $params) &&
+      if ($contributionPageId && !empty($params['member_price_set_id']) &&
         CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active')) {
         $errors['member_price_set_id'] = ts('You cannot use Membership Price Sets with the Contribution Amounts section. However, a membership price set may include additional fields for non-membership options that requires an additional fee (e.g. magazine subscription) or an additional voluntary contribution.');
       }
 
-      if (CRM_Utils_Array::value('member_price_set_id', $params)) {
+      if (!empty($params['member_price_set_id'])) {
         return $errors;
       }
 
@@ -291,7 +294,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
       if ($contributionPageId) {
         $amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
 
-        if (!$amountBlock && CRM_Utils_Array::value('is_separate_payment', $params)) {
+        if (!$amountBlock && !empty($params['is_separate_payment'])) {
           $errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
         }
       }
@@ -333,9 +336,9 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
 
       // check for price set.
       $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
-      if (CRM_Utils_Array::value('member_is_active', $params) && is_array($membershipTypes) && !$priceSetID) {
+      if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
         $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
-        if (!CRM_Utils_Array::value('mem_price_field_id', $params) && !$usedPriceSetId) {
+        if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
           $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
           $setParams['title'] = $this->_values['title'];
           if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
@@ -373,10 +376,10 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
         );
         $editedResults = array();
         CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
-        if (!CRM_Utils_Array::value('id', $editedResults)) {
+        if (empty($editedResults['id'])) {
           $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
-          $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : ts('Membership');
-          if (!CRM_Utils_Array::value('mem_price_field_id', $params)) {
+          $fieldParams['label'] = !empty($params['new_title']) ? $params['new_title'] : ts('Membership');
+          if (empty($params['mem_price_field_id'])) {
             CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
           }
           $fieldParams['weight'] = 1;
@@ -387,11 +390,11 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
 
         $fieldParams['is_active'] = 1;
         $fieldParams['html_type'] = 'Radio';
-        $fieldParams['is_required'] = CRM_Utils_Array::value('is_required', $params) ? 1 : 0;
-        $fieldParams['is_display_amounts'] = CRM_Utils_Array::value('display_min_fee', $params) ? 1 : 0;
+        $fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
+        $fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
         $rowCount = 1;
         $options = array();
-        if (CRM_Utils_Array::value('id', $fieldParams)) {
+        if (!empty($fieldParams['id'])) {
           CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
         }
 
@@ -453,7 +456,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
           );
 
           CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs);
-          if (!CRM_Utils_Array::value('id', $pFIDs)) {
+          if (empty($pFIDs['id'])) {
             CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
             CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0');
           }