INFRA 32 - Batch #17
[civicrm-core.git] / CRM / Price / BAO / PriceSet.php
index 2ce05eb47b7fd4614f7e1003c9968bc0a59bbc88..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);
@@ -102,8 +99,8 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
    *
    * @internal param bool $is_active value we want to set the is_active field
    *
-   * @return Object             DAO object on sucess, null otherwise
-   * @static
+   * @return Object
+   *   DAO object on sucess, null otherwise
    */
   public static function setIsActive($id, $isActive) {
     return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_active', $isActive);
@@ -115,9 +112,8 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
    *
    * @param string $entity
    *
-   * @return array $defaultPriceSet default price set
-   *
-   * @static
+   * @return array
+   *   default price set
    *
    */
   public static function getDefaultPriceSet($entity = 'contribution') {
@@ -141,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,
       );
     }
 
@@ -161,9 +157,8 @@ WHERE       ps.name = '{$entityName}'
    * @param int $id
    *   Id of price set.
    *
-   * @return string   title
-   *
-   * @static
+   * @return string
+   *   title
    *
    */
   public static function getTitle($id) {
@@ -284,10 +279,10 @@ WHERE     ct.id = cp.financial_type_id AND
    * @param int $id
    *   Price Set id.
    *
-   * @return boolean false if fields exist for this set, true if the
-   * set could be deleted
+   * @return bool
+   *   false if fields exist for this set, true if the
+   *   set could be deleted
    *
-   * @static
    */
   public static function deleteSet($id) {
     // remove from all inactive forms
@@ -355,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();
   }
 
@@ -373,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) {
@@ -388,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%' ";
@@ -410,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;
@@ -441,7 +437,8 @@ WHERE     ct.id = cp.financial_type_id AND
    *   Whether or not to include inactive entries.
    * @param bool|string $extendComponentName name of the component like 'CiviEvent','CiviContribute'
    *
-   * @return array associative array of id => name
+   * @return array
+   *   associative array of id => name
    */
   public static function getAssoc($withInactive = FALSE, $extendComponentName = FALSE) {
     $query = '
@@ -489,7 +486,8 @@ WHERE     ct.id = cp.financial_type_id AND
    *
    * @internal param int $setId - price set id whose details are needed
    *
-   * @return array $setTree - array consisting of field details
+   * @return array
+   *   array consisting of field details
    */
   public static function getSetDetail($setID, $required = TRUE, $validOnly = FALSE) {
     // create a new tree
@@ -521,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
 ';
@@ -828,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'])
                 )
               );
             }
@@ -882,7 +880,7 @@ WHERE  id = %1";
           unset($autoRenew[$dontCare]);
         }
       }
-      if (count($autoRenew) > 1 ) {
+      if (count($autoRenew) > 1) {
         $params['autoRenew'] = $autoRenew;
       }
     }
@@ -904,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')) {
@@ -1010,7 +1010,7 @@ WHERE  id = %1";
    * @param CRM_Core_Form $form
    * @param $defaults
    *
-   * @return array $defaults
+   * @return array
    */
   public static function setDefaultPriceSet(&$form, &$defaults) {
     if (!isset($form->_priceSet) || empty($form->_priceSet['fields'])) {
@@ -1076,15 +1076,16 @@ WHERE  id = %1";
       //}
     }
   }
+
   /**
    * Get field ids of a price set
    *
    * @param int $id
    *   Price Set id.
    *
-   * @return array of the field ids
+   * @return array
+   *   Array of the field ids
    *
-   * @static
    */
   public static function getFieldIds($id) {
     $priceField = new CRM_Price_DAO_PriceField();
@@ -1097,14 +1098,12 @@ WHERE  id = %1";
   }
 
   /**
-   * This function is to 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");
@@ -1112,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));
@@ -1146,7 +1145,7 @@ WHERE  id = %1";
   }
 
   /**
-   * This function is to check price set permission
+   * check price set permission
    *
    * @param int $sid
    *   The price set id.
@@ -1173,7 +1172,6 @@ WHERE  id = %1";
    * @param bool $onlyActive
    *
    * @return int|null|string
-   * @static
    */
   public static function getPricesetCount($sid, $onlyActive = TRUE) {
     $count = 0;
@@ -1232,7 +1230,8 @@ GROUP BY     mt.member_of_contact_id";
    * @param int $priceSetId
    *   Price set id.
    *
-   * @return int $autoRenewOption ( 0:hide, 1:optional 2:required )
+   * @return int
+   *   $autoRenewOption ( 0:hide, 1:optional 2:required )
    */
   public static function checkAutoRenewForPriceSet($priceSetId) {
     // auto-renew option should be visible if membership types associated with all the fields has
@@ -1250,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;
@@ -1280,8 +1279,8 @@ GROUP BY     mt.member_of_contact_id";
    * @param int $priceSetId
    *   Price set id.
    *
-   * @return array associate array of frequency interval and unit
-   * @static
+   * @return array
+   *   associate array of frequency interval and unit
    */
   public static function getRecurDetails($priceSetId) {
     $query = 'SELECT mt.duration_interval, mt.duration_unit
@@ -1311,11 +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
+   * @return Object
+   *   DAO object on sucess, null otherwise
    */
   public static function setIsQuickConfig($id, $isQuickConfig) {
     return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_quick_config', $isQuickConfig);
@@ -1325,13 +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
@@ -1410,10 +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') {