INFRA 32 - Batch #17
[civicrm-core.git] / CRM / Price / BAO / PriceSet.php
index c6d0c1668e9b937cf3e619cae04b2e8b84ff43b3..d03b8b2c7b5ad60dffb2d1afe149ab06a9d4fd32 100644 (file)
@@ -43,7 +43,6 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
    * Static field for default price set details
    *
    * @var array
-   * @static
    */
   static $_defaultPriceSet = NULL;
 
@@ -60,8 +59,7 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
    *
-   * @return CRM_Price_DAO_PriceSet object
-   * @static
+   * @return CRM_Price_DAO_PriceSet
    */
   public static function create(&$params) {
     if (empty($params['id']) && empty($params['name'])) {
@@ -86,8 +84,7 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
    * @param array $defaults
    *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Price_DAO_PriceSet object
-   * @static
+   * @return CRM_Price_DAO_PriceSet
    */
   public static function retrieve(&$params, &$defaults) {
     return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceSet', $params, $defaults);
@@ -104,7 +101,6 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
    *
    * @return Object
    *   DAO object on sucess, null otherwise
-   * @static
    */
   public static function setIsActive($id, $isActive) {
     return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_active', $isActive);
@@ -119,7 +115,6 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
    * @return array
    *   default price set
    *
-   * @static
    */
   public static function getDefaultPriceSet($entity = 'contribution') {
     if (!empty(self::$_defaultPriceSet[$entity])) {
@@ -142,14 +137,14 @@ WHERE       ps.name = '{$entityName}'
     self::$_defaultPriceSet[$entity] = array();
     while ($dao->fetch()) {
       self::$_defaultPriceSet[$entity][$dao->priceFieldValueID] = array(
-       'setID' => $dao->setID,
-       'priceFieldID' => $dao->priceFieldID,
-       'name' => $dao->name,
-       'label' => $dao->label,
-       'priceFieldValueID' => $dao->priceFieldValueID,
-       'membership_type_id' => $dao->membership_type_id,
-       'amount' => $dao->amount,
-       'financial_type_id' => $dao->financial_type_id,
+        'setID' => $dao->setID,
+        'priceFieldID' => $dao->priceFieldID,
+        'name' => $dao->name,
+        'label' => $dao->label,
+        'priceFieldValueID' => $dao->priceFieldValueID,
+        'membership_type_id' => $dao->membership_type_id,
+        'amount' => $dao->amount,
+        'financial_type_id' => $dao->financial_type_id,
       );
     }
 
@@ -165,7 +160,6 @@ WHERE       ps.name = '{$entityName}'
    * @return string
    *   title
    *
-   * @static
    */
   public static function getTitle($id) {
     return CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $id, 'title');
@@ -285,11 +279,10 @@ WHERE     ct.id = cp.financial_type_id AND
    * @param int $id
    *   Price Set id.
    *
-   * @return boolean
+   * @return bool
    *   false if fields exist for this set, true if the
-   * set could be deleted
+   *   set could be deleted
    *
-   * @static
    */
   public static function deleteSet($id) {
     // remove from all inactive forms
@@ -357,9 +350,9 @@ WHERE     ct.id = cp.financial_type_id AND
    * @return mixed
    */
   public static function removeFrom($entityTable, $entityId) {
-    $dao               = new CRM_Price_DAO_PriceSetEntity();
+    $dao = new CRM_Price_DAO_PriceSetEntity();
     $dao->entity_table = $entityTable;
-    $dao->entity_id    = $entityId;
+    $dao->entity_id = $entityId;
     return $dao->delete();
   }
 
@@ -375,7 +368,8 @@ WHERE     ct.id = cp.financial_type_id AND
    * @param null $isQuickConfig
    * @param null $setName
    *
-   * @return integer|false price_set_id, or false if none found
+   * @return int|false
+   *   price_set_id, or false if none found
    */
   public static function getFor($entityTable, $entityId, $usedFor = NULL, $isQuickConfig = NULL, &$setName = NULL) {
     if (!$entityTable || !$entityId) {
@@ -390,8 +384,8 @@ WHERE     ct.id = cp.financial_type_id AND
       $sql .= ' AND ps.is_quick_config = 0 ';
     }
     $params = array(
-    1 => array($entityTable, 'String'),
-              2 => array($entityId, 'Integer'),
+      1 => array($entityTable, 'String'),
+      2 => array($entityId, 'Integer'),
     );
     if ($usedFor) {
       $sql .= " AND ps.extends LIKE '%%3%' ";
@@ -412,8 +406,8 @@ WHERE     ct.id = cp.financial_type_id AND
    *                      array may contain either option id or
    *                      price field id
    *
-   * @return integer|NULL price set id on success, null  otherwise
-   * @static
+   * @return int|NULL
+   *   price set id on success, null  otherwise
    */
   public static function getSetId(&$params) {
     $fid = NULL;
@@ -525,9 +519,9 @@ WHERE     ct.id = cp.financial_type_id AND
     $select = 'SELECT ' . implode(',', $priceFields);
     $from = ' FROM civicrm_price_field';
 
-    $params    = array();
+    $params = array();
     $params[1] = array($setID, 'Integer');
-    $where     = '
+    $where = '
 WHERE price_set_id = %1
 AND is_active = 1
 ';
@@ -832,8 +826,8 @@ WHERE  id = %1";
             $params['amount_priceset_level_checkbox']["{$field['options'][$optionId]['id']}"] = $optionLabel;
             if (isset($checkboxLevel)) {
               $checkboxLevel = array_unique(array_merge(
-                $checkboxLevel,
-                array_keys($params['amount_priceset_level_checkbox'])
+                  $checkboxLevel,
+                  array_keys($params['amount_priceset_level_checkbox'])
                 )
               );
             }
@@ -908,12 +902,14 @@ WHERE  id = %1";
     $validFieldsOnly = TRUE;
     $className = CRM_Utils_System::getClassName($form);
     if (in_array($className, array(
-          'CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
+      'CRM_Contribute_Form_Contribution',
+      'CRM_Member_Form_Membership',
+    ))) {
       $validFieldsOnly = FALSE;
     }
 
-    $priceSet           = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
-    $form->_priceSet    = CRM_Utils_Array::value($priceSetId, $priceSet);
+    $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
+    $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $validPriceFieldIds = array_keys($form->_priceSet['fields']);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
@@ -1080,6 +1076,7 @@ WHERE  id = %1";
       //}
     }
   }
+
   /**
    * Get field ids of a price set
    *
@@ -1087,9 +1084,8 @@ WHERE  id = %1";
    *   Price Set id.
    *
    * @return array
-   *   of the field ids
+   *   Array of the field ids
    *
-   * @static
    */
   public static function getFieldIds($id) {
     $priceField = new CRM_Price_DAO_PriceField();
@@ -1102,14 +1098,12 @@ WHERE  id = %1";
   }
 
   /**
-   * make a copy of a price set, including
-   * all the fields
+   * Copy a price set, including all the fields
    *
    * @param int $id
    *   The price set id to copy.
    *
-   * @return the copy object
-   * @static
+   * @return CRM_Price_DAO_PriceSet
    */
   public static function copy($id) {
     $maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set");
@@ -1117,21 +1111,21 @@ WHERE  id = %1";
     $title = ts('[Copy id %1]', array(1 => $maxId + 1));
     $fieldsFix = array(
       'suffix' => array(
-    'title' => ' ' . $title,
-                'name' => '__Copy_id_' . ($maxId + 1) . '_',
+        'title' => ' ' . $title,
+        'name' => '__Copy_id_' . ($maxId + 1) . '_',
       ),
     );
 
     $copy = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSet',
-            array('id' => $id),
-            NULL,
-            $fieldsFix
+      array('id' => $id),
+      NULL,
+      $fieldsFix
     );
 
     //copying all the blocks pertaining to the price set
     $copyPriceField = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceField',
-                      array('price_set_id' => $id),
-                      array('price_set_id' => $copy->id)
+      array('price_set_id' => $id),
+      array('price_set_id' => $copy->id)
     );
     if (!empty($copyPriceField)) {
       $price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id));
@@ -1178,7 +1172,6 @@ WHERE  id = %1";
    * @param bool $onlyActive
    *
    * @return int|null|string
-   * @static
    */
   public static function getPricesetCount($sid, $onlyActive = TRUE) {
     $count = 0;
@@ -1256,9 +1249,9 @@ GROUP BY     mt.member_of_contact_id";
 
     $params = array(1 => array($priceSetId, 'Integer'));
 
-    $dao             = CRM_Core_DAO::executeQuery($query, $params);
+    $dao = CRM_Core_DAO::executeQuery($query, $params);
     $autoRenewOption = 2;
-    $interval        = $unit = array();
+    $interval = $unit = array();
     while ($dao->fetch()) {
       if (!$dao->auto_renew) {
         $autoRenewOption = 0;
@@ -1288,7 +1281,6 @@ GROUP BY     mt.member_of_contact_id";
    *
    * @return array
    *   associate array of frequency interval and unit
-   * @static
    */
   public static function getRecurDetails($priceSetId) {
     $query = 'SELECT mt.duration_interval, mt.duration_unit
@@ -1318,12 +1310,11 @@ GROUP BY     mt.member_of_contact_id";
    *
    * @param int $id
    *   Id of the database record.
-   * @param bool $isQuickConfigValue we want to set the is_quick_config field.
+   * @param bool $isQuickConfig we want to set the is_quick_config field.
    *   Value we want to set the is_quick_config field.
    *
    * @return Object
    *   DAO object on sucess, null otherwise
-   * @static
    */
   public static function setIsQuickConfig($id, $isQuickConfig) {
     return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_quick_config', $isQuickConfig);
@@ -1333,12 +1324,10 @@ GROUP BY     mt.member_of_contact_id";
    * Check if price set id provides option for
    * user to select both auto-renew and non-auto-renew memberships
    *
-   * @static
    */
   public static function checkMembershipPriceSet($id) {
-    $query =
-    "
-SELECT      pfv.id, pfv.price_field_id, pfv.name, pfv.membership_type_id, pf.html_type, mt.auto_renew
+    $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
@@ -1417,8 +1406,14 @@ WHERE       ps.id = %1
     }
   }
 
-  /*
+  /**
    * Function to set tax_amount and tax_rate in LineItem
+   *
+   * @param array $field
+   * @param array $lineItem
+   * @param int $optionValueId
+   *
+   * @return array
    */
   public static function setLineItem($field, $lineItem, $optionValueId) {
     if ($field['html_type'] == 'Text') {