CRM-15851 search builder fix for custom date fields
[civicrm-core.git] / CRM / Financial / BAO / FinancialTypeAccount.php
index 6538e520d1ac7d3f17d5ddbae16d1bc9f2c49a7a..d73aa779c2425237f4a447fa8b1be19af25fd9b1 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * $Id$
  *
  */
-
 class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFinancialAccount {
 
   /**
    * Class constructor
    */
-  function __construct( ) {
-    parent::__construct( );
+  public function __construct() {
+    parent::__construct();
   }
 
   /**
    * Financial account
    * @var array
-   * @static
    */
   private static $financialAccount;
 
   /**
    * 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
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
    * @param array $allValues
    *
-   * @return CRM_Contribute_BAO_ContributionType object
-   * @access public
-   * @static
+   * @return CRM_Contribute_BAO_ContributionType
    */
-  static function retrieve(&$params, &$defaults, &$allValues = array()) {
+  public static function retrieve(&$params, &$defaults, &$allValues = array()) {
     $financialTypeAccount = new CRM_Financial_DAO_EntityFinancialAccount();
     $financialTypeAccount->copyValues($params);
     $financialTypeAccount->find();
@@ -75,14 +73,14 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin
   /**
    * Add the financial types
    *
-   * @param array $params reference array contains the values submitted by the form
-   * @param array $ids    reference array contains the id
+   * @param array $params
+   *   Reference array contains the values submitted by the form.
+   * @param array $ids
+   *   Reference array contains the id.
    *
-   * @access public
-   * @static
    * @return object
    */
-  static function add(&$params, &$ids = NULL) {
+  public static function add(&$params, &$ids = NULL) {
     // action is taken depending upon the mode
     $financialTypeAccount = new CRM_Financial_DAO_EntityFinancialAccount();
     if ($params['entity_table'] != 'civicrm_financial_type') {
@@ -107,14 +105,13 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin
    * @param int $financialTypeAccountId
    * @param int $accountId
    *
-   * @static
    */
-  static function del($financialTypeAccountId, $accountId = null) {
+  public static function del($financialTypeAccountId, $accountId = NULL) {
     //checking if financial type is present
-    $check = false;
+    $check = FALSE;
     $relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
 
-    $financialTypeId = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'entity_id' );
+    $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'entity_id');
     //check dependencies
     // FIXME more table containing financial_type_id to come
     $dependancy = array(
@@ -132,8 +129,8 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin
       $daoString = 'CRM_' . $name[0] . '_DAO_' . $name[1];
       $dao = new $daoString();
       $dao->financial_type_id = $financialTypeId;
-      if ($dao->find(true)) {
-        $check = true;
+      if ($dao->find(TRUE)) {
+        $check = TRUE;
         break;
       }
     }
@@ -144,13 +141,13 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin
       }
       else {
         $accountRelationShipId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'account_relationship');
-        CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship because it is being referenced by one or more of the following types of records: Contributions, Contribution Pages, or Membership Types. Consider disabling this type instead if you no longer want it used.', array(1 => $relationValues[$accountRelationShipId])), NUll, 'error');
+        CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship because it is being referenced by one or more of the following types of records: Contributions, Contribution Pages, or Membership Types. Consider disabling this type instead if you no longer want it used.', array(1 => $relationValues[$accountRelationShipId])), NULL, 'error');
       }
-      return CRM_Utils_System::redirect( CRM_Utils_System::url( 'civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$accountId}" ));
+      return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$accountId}"));
     }
 
     //delete from financial Type table
-    $financialType = new CRM_Financial_DAO_EntityFinancialAccount( );
+    $financialType = new CRM_Financial_DAO_EntityFinancialAccount();
     $financialType->id = $financialTypeAccountId;
     $financialType->find(TRUE);
     $financialType->delete();
@@ -164,12 +161,12 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin
    *
    * @param string $entityTable
    *
-   * @param string $columnName Column to fetch
+   * @param string $columnName
+   *   Column to fetch.
    *
    * @return null|string
-   * @static
    */
-  static function getFinancialAccount($entityId, $entityTable, $columnName = 'name') {
+  public static function getFinancialAccount($entityId, $entityTable, $columnName = 'name') {
     $join = $columnName == 'name' ? 'LEFT JOIN civicrm_financial_account ON civicrm_entity_financial_account.financial_account_id = civicrm_financial_account.id' : NULL;
     $query = "
 SELECT {$columnName}
@@ -188,12 +185,12 @@ AND entity_id = %2";
   /**
    * Financial Account for payment instrument
    *
-   * @param int $paymentInstrumentValue payment instrument value
+   * @param int $paymentInstrumentValue
+   *   Payment instrument value.
    *
    * @return array|null|string
-   * @static
    */
-  static function getInstrumentFinancialAccount($paymentInstrumentValue = NULL) {
+  public static function getInstrumentFinancialAccount($paymentInstrumentValue = NULL) {
     if (!self::$financialAccount) {
       $query = "SELECT ceft.financial_account_id, cov.value
 FROM civicrm_entity_financial_account ceft
@@ -225,20 +222,19 @@ WHERE cog.name = 'payment_instrument' ";
    * @param $financialType
    *
    * @return array
-   * @static
    */
-  static function createDefaultFinancialAccounts($financialType) {
+  public static function createDefaultFinancialAccounts($financialType) {
     $titles = array();
     $financialAccountTypeID = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type');
     $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship');
-    $relationships = array (
+    $relationships = array(
       array_search('Accounts Receivable Account is', $accountRelationship) => array_search('Asset', $financialAccountTypeID),
       array_search('Expense Account is', $accountRelationship) => array_search('Expenses', $financialAccountTypeID),
       array_search('Cost of Sales Account is', $accountRelationship) => array_search('Cost of Sales', $financialAccountTypeID),
       array_search('Income Account is', $accountRelationship) => array_search('Revenue', $financialAccountTypeID),
     );
 
-    $dao =  CRM_Core_DAO::executeQuery('SELECT id, financial_account_type_id FROM civicrm_financial_account WHERE name LIKE %1',
+    $dao = CRM_Core_DAO::executeQuery('SELECT id, financial_account_type_id FROM civicrm_financial_account WHERE name LIKE %1',
       array(1 => array($financialType->name, 'String'))
     );
     $dao->fetch();
@@ -257,7 +253,7 @@ WHERE cog.name = 'payment_instrument' ";
     else {
       $existingFinancialAccount[$dao->financial_account_type_id] = $dao->id;
     }
-    $params = array (
+    $params = array(
       'entity_table' => 'civicrm_financial_type',
       'entity_id' => $financialType->id,
     );
@@ -290,8 +286,8 @@ WHERE cog.name = 'payment_instrument' ";
         }
       }
       else {
-         $params['financial_account_id'] = $existingFinancialAccount[$value];
-         $titles[] = $financialType->name;
+        $params['financial_account_id'] = $existingFinancialAccount[$value];
+        $titles[] = $financialType->name;
       }
       $params['account_relationship'] = $key;
       self::add($params);
@@ -301,5 +297,5 @@ WHERE cog.name = 'payment_instrument' ";
     }
     return $titles;
   }
-}
 
+}