INFRA-132 - Put space after flow-control (if/switch/for/foreach/while)
[civicrm-core.git] / CRM / Price / BAO / PriceFieldValue.php
index c3e0a7d7eaa1129316ad2ffa8dd01454e81d7046..05404c1f18b9d6f1feb8ab83fe0085eebd4d5ad1 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
 
   /**
-   * insert/update a new entry in the database.
+   * Insert/update a new entry in the database.
    *
-   * @param array $params (reference), array $ids
+   * @param array $params
+   *   (reference), array $ids.
    *
    * @param $ids
    *
-   * @return object CRM_Price_DAO_PriceFieldValue object
-   * @access public
+   * @return CRM_Price_DAO_PriceFieldValue object
    * @static
    */
-  static function add(&$params, $ids = array()) {
+  public static function add(&$params, $ids = array()) {
 
     $fieldValueBAO = new CRM_Price_BAO_PriceFieldValue();
     $fieldValueBAO->copyValues($params);
@@ -71,25 +71,26 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
   /**
    * Creates a new entry in the database.
    *
-   * @param array $params (reference), array $ids
+   * @param array $params
+   *   (reference), array $ids.
    *
    * @param $ids
    *
-   * @return object CRM_Price_DAO_PriceFieldValue object
-   * @access public
+   * @return CRM_Price_DAO_PriceFieldValue object
    * @static
    */
-  static function create(&$params, $ids = array()) {
-
+  public static function create(&$params, $ids = array()) {
+    $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
     if (!is_array($params) || empty($params)) {
       return;
     }
-    if(empty($params['id']) && empty($params['name'])) {
+    if (!$id && empty($params['name'])) {
       $params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242));
     }
 
-    if ($id = CRM_Utils_Array::value('id', $ids) && !empty($params['weight'])) {
-      if (isset($params['name']))unset($params['name']);
+    if ($id  && !empty($params['weight'])) {
+      if (isset($params['name'])) { unset($params['name']);
+      }
 
       $oldWeight = NULL;
       if ($id) {
@@ -100,47 +101,60 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
       $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceFieldValue', $oldWeight, $params['weight'], $fieldValues);
     }
     else {
-      if (!$id && empty($params['name'])) {
-        $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64);
-      }
-      if (empty($params['weight'])) {
-        $params['weight'] = 1;
+      if (!$id) {
+        CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
+        if (empty($params['name'])) {
+          $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64);
+        }
       }
     }
-    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
-
     return self::add($params, $ids);
   }
 
+  /**
+   * Get defaults for new entity
+   * @return array
+   */
+  public static function getDefaults() {
+    return array(
+      'is_active' => 1,
+      'weight' => 1,
+    );
+
+  }
+
   /**
    * Takes a bunch of params that are needed to match certain criteria and
    * retrieves the relevant objects.
    *
-   * @param array $params   (reference ) an assoc array
-   * @param array $defaults (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return object CRM_Price_DAO_PriceFieldValue object
-   * @access public
+   * @return CRM_Price_DAO_PriceFieldValue object
    * @static
    */
-  static function retrieve(&$params, &$defaults) {
+  public static function retrieve(&$params, &$defaults) {
     return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceFieldValue', $params, $defaults);
   }
 
   /**
    * Retrive the all values for given field id
    *
-   * @param int $fieldId price_field_id
-   * @param array $values (reference ) to hold the values
-   * @param string $orderBy for order by, default weight
+   * @param int $fieldId
+   *   Price_field_id.
+   * @param array $values
+   *   (reference ) to hold the values.
+   * @param string $orderBy
+   *   For order by, default weight.
    * @param bool|int $isActive is_active, default false
    *
    * @return array $values
    *
-   * @access public
    * @static
    */
-  static function getValues($fieldId, &$values, $orderBy = 'weight', $isActive = FALSE) {
+  public static function getValues($fieldId, &$values, $orderBy = 'weight', $isActive = FALSE) {
     $fieldValueDAO = new CRM_Price_DAO_PriceFieldValue();
     $fieldValueDAO->price_field_id = $fieldId;
     $fieldValueDAO->orderBy($orderBy, 'label');
@@ -159,11 +173,11 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
   /**
    * Get the price field option label.
    *
-   * @param int $id id of field option.
+   * @param int $id
+   *   Id of field option.
    *
    * @return string name
    *
-   * @access public
    * @static
    *
    */
@@ -172,30 +186,31 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
   }
 
   /**
-   * update the is_active flag in the db
+   * Update the is_active flag in the db
    *
-   * @param int      $id         Id of the database record
-   * @param boolean  $is_active  Value we want to set the is_active field
+   * @param int $id
+   *   Id of the database record.
+   * @param bool $is_active
+   *   Value we want to set the is_active field.
    *
    * @return   Object            DAO object on sucess, null otherwise
    *
-   * @access public
    * @static
    */
-  static function setIsActive($id, $is_active) {
+  public static function setIsActive($id, $is_active) {
     return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $id, 'is_active', $is_active);
   }
 
   /**
-   * delete all values of the given field id
+   * Delete all values of the given field id
    *
-   * @param  int    $fieldId    Price field id
+   * @param int $fieldId
+   *   Price field id.
    *
    *
-   * @access public
    * @static
    */
-  static function deleteValues($fieldId) {
+  public static function deleteValues($fieldId) {
     if (!$fieldId) {
       return;
     }
@@ -208,14 +223,14 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
   /**
    * Delete the value.
    *
-   * @param   int   $id  Id
+   * @param int $id
+   *   Id.
    *
    * @return  boolean
    *
-   * @access public
    * @static
    */
-  static function del($id) {
+  public static function del($id) {
     if (!$id) {
       return FALSE;
     }
@@ -229,14 +244,16 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
    * Update civicrm_price_field_value.financial_type_id
    * when financial_type_id of contribution_page or event is changed
    *
-   * @param   int $entityId Id
-   * @param   String $entityTable entity table
-   * @param   String $financialTypeID financial type id
+   * @param int $entityId
+   *   Id.
+   * @param string $entityTableEntity table.
+   *   Entity table.
+   * @param string $financialTypeIDFinancial type id.
+   *   Financial type id.
    *
-   * @access public
    * @static
    */
-  static function updateFinancialType($entityId, $entityTable, $financialTypeID) {
+  public static function updateFinancialType($entityId, $entityTable, $financialTypeID) {
     if (!$entityId || !$entityTable || !$financialTypeID) {
       return;
     }
@@ -267,4 +284,3 @@ WHERE cpse.id IS NOT NULL {$where}";
     CRM_Core_DAO::executeQuery($sql, $params);
   }
 }
-