Merge pull request #4806 from civicrm/4.5
[civicrm-core.git] / CRM / Financial / BAO / FinancialItem.php
index e3c6170454207edf5e2bee8fbb63dbb14dd126b2..273abab03878f232a181865b91cd44b3b16790e8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
 
   /**
-   * class constructor
+   * Class constructor
    */
   function __construct( ) {
     parent::__construct( );
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects. Typically the valid params are only
-   * contact_id. We'll tweak this function to be more full featured over a period
-   * of time. This is the inverse function of create. It also stores all the retrieved
-   * values in the default array
+   * Fetch object based on array of properties
    *
    * @param array $params   (reference ) an assoc array of name/value pairs
    * @param array $defaults (reference ) an assoc array to hold the flattened values
    *
-   * @return object CRM_Contribute_BAO_FinancialItem object
+   * @return CRM_Contribute_BAO_FinancialItem object
    * @access public
    * @static
    */
@@ -67,7 +63,7 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
   }
 
   /**
-   * function to add the financial items and financial trxn
+   * Add the financial items and financial trxn
    *
    * @param object $lineItem     line item object
    * @param object $contribution contribution object
@@ -131,7 +127,7 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
   }
 
   /**
-   * function to create the financial Items and financial enity trxn
+   * Create the financial Items and financial enity trxn
    *
    * @param array $params  associated array to create financial items
    * @param array $ids financial item ids
@@ -143,6 +139,14 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
    */
   static function create(&$params, $ids = NULL, $trxnIds = NULL) {
     $financialItem = new CRM_Financial_DAO_FinancialItem();
+    
+    if (!empty($ids['id'])) {
+      CRM_Utils_Hook::pre('edit', 'FinancialItem', $ids['id'], $params);
+    }
+    else {
+      CRM_Utils_Hook::pre('create', 'FinancialItem', NULL, $params);
+    }
+    
     $financialItem->copyValues($params);
     if (!empty($ids['id'])) {
       $financialItem->id = $ids['id'];
@@ -164,15 +168,21 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
       }
       $entity_trxn->save();
     }
+    if (!empty($ids['id'])) {
+      CRM_Utils_Hook::post('edit', 'FinancialItem', $financialItem->id, $financialItem);
+    }
+    else {      
+      CRM_Utils_Hook::post('create', 'FinancialItem', $financialItem->id, $financialItem);
+    }
     return $financialItem;
   }
 
   /**
-   * takes an associative array and creates a entity financial transaction object
+   * Takes an associative array and creates a entity financial transaction object
    *
    * @param array  $params (reference ) an assoc array of name/value pairs
    *
-   * @return object CRM_Core_BAO_FinancialTrxn object
+   * @return CRM_Core_BAO_FinancialTrxn object
    * @access public
    * @static
    */
@@ -184,13 +194,10 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
   }
 
   /**
-   * retrive entity financial trxn details
+   * Retrive entity financial trxn details
    *
    * @param array $params (reference ) an assoc array of name/value pairs
-   *
-   * @param bool $maxId
-   *
-   * @internal param bool $maxID to retrive max id
+   * @param bool $maxId to retrive max id
    *
    * @return array
    * @access public
@@ -223,7 +230,7 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
   }
 
   /**
-   * check if contact is present in financial_item table
+   * Check if contact is present in financial_item table
    *
    * CRM-12929
    *