Merge pull request #5488 from eileenmcnaughton/CRM-16184
[civicrm-core.git] / CRM / Price / Form / Set.php
index 9482ef3f5a9dbfd6295cf66af70a938128e71c4f..b79ac5b80bd48b770471e659d818589c8c1690bf 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Price_Form_Set extends CRM_Core_Form {
 
   /**
-   * The set id saved to the session for an update
+   * The set id saved to the session for an update.
    *
    * @var int
-   * @access protected
    */
   protected $_sid;
 
   /**
-   * Set variables up before form is built
-   *
-   * @param null
+   * Set variables up before form is built.
    *
    * @return void
-   * @access public
    */
   public function preProcess() {
     // current set id
@@ -72,24 +68,29 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
     CRM_Utils_System::setTitle($title);
 
     $url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1');
-    $breadCrumb = array(array('title' => ts('Price Sets'),
+    $breadCrumb = array(
+      array(
+        'title' => ts('Price Sets'),
         'url' => $url,
-      ));
+      ),
+    );
     CRM_Utils_System::appendBreadCrumb($breadCrumb);
   }
 
   /**
-   * Global form rule
+   * Global form rule.
    *
-   * @param array $fields  the input form values
-   * @param array $files   the uploaded files if any
-   * @param array $options additional user data
+   * @param array $fields
+   *   The input form values.
+   * @param array $files
+   *   The uploaded files if any.
+   * @param array $options
+   *   Additional user data.
    *
-   * @return true if no errors, else array of errors
-   * @access public
-   * @static
+   * @return bool|array
+   *   true if no errors, else array of errors
    */
-  static function formRule($fields, $files, $options) {
+  public static function formRule($fields, $files, $options) {
     $errors = array();
     $count = count(CRM_Utils_Array::value('extends', $fields));
     //price sets configured for membership
@@ -109,12 +110,9 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
   }
 
   /**
-   * Build the form object
-   *
-   * @param null
+   * Build the form object.
    *
    * @return void
-   * @access public
    */
   public function buildQuickForm() {
     $this->applyFilter('__ALL__', 'trim');
@@ -132,7 +130,7 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
       $priceSetUsedTables = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid, 'table');
     }
 
-    $config           = CRM_Core_Config::singleton();
+    $config = CRM_Core_Config::singleton();
     $showContribution = FALSE;
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
 
@@ -150,6 +148,7 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
           }
           $extends[] = $option;
           break;
+
         case 'CiviContribute':
           $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Contribution'));
           if (!empty($priceSetUsedTables)) {
@@ -162,6 +161,7 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
           }
           $extends[] = $option;
           break;
+
         case 'CiviMember':
           $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Membership'));
           if (!empty($priceSetUsedTables)) {
@@ -193,7 +193,7 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
 
     $this->add('select', 'financial_type_id',
       ts('Default Financial Type'),
-          array('' => ts('- select -')) + $financialType, 'required'
+      array('' => ts('- select -')) + $financialType, 'required'
     );
 
     // help text
@@ -234,31 +234,28 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
    * Set default values for the form. Note that in edit/view mode
    * the default values are retrieved from the database
    *
-   * @param null
-   *
-   * @return array   array of default values
-   * @access public
+   * @return array
+   *   array of default values
    */
-  function setDefaultValues() {
+  public function setDefaultValues() {
     $defaults = array('is_active' => TRUE);
     if ($this->_sid) {
       $params = array('id' => $this->_sid);
       CRM_Price_BAO_PriceSet::retrieve($params, $defaults);
       $extends = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['extends']);
       unset($defaults['extends']);
-      foreach ($extends as $compId) $defaults['extends'][$compId] = 1;
+      foreach ($extends as $compId) {
+        $defaults['extends'][$compId] = 1;
+      }
     }
 
     return $defaults;
   }
 
   /**
-   * Process the form
-   *
-   * @param null
+   * Process the form.
    *
    * @return void
-   * @access public
    */
   public function postProcess() {
     // get the submitted form values.
@@ -270,7 +267,11 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
     $compIds = array();
     $extends = CRM_Utils_Array::value('extends', $params);
     if (is_array($extends)) {
-      foreach ($extends as $compId => $selected) if ($selected) {   $compIds[] = $compId; }
+      foreach ($extends as $compId => $selected) {
+        if ($selected) {
+          $compIds[] = $compId;
+        }
+      }
     }
     $params['extends'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $compIds);
 
@@ -289,13 +290,18 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
     else {
       // Jump directly to adding a field if popups are disabled
       $action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? 'browse' : 'add';
-      $url = CRM_Utils_System::url('civicrm/admin/price/field', array('reset' => 1, 'action' => $action, 'sid' => $set->id, 'new' => 1));
+      $url = CRM_Utils_System::url('civicrm/admin/price/field', array(
+          'reset' => 1,
+          'action' => $action,
+          'sid' => $set->id,
+          'new' => 1,
+        ));
       CRM_Core_Session::setStatus(ts("Your Set '%1' has been added. You can add fields to this set now.",
-          array(1 => $set->title)
-        ), ts('Saved'), 'success');
+        array(1 => $set->title)
+      ), ts('Saved'), 'success');
       $session = CRM_Core_Session::singleton();
       $session->replaceUserContext($url);
     }
   }
-}
 
+}