send most action links thru hook_civicrm_links
[civicrm-core.git] / CRM / Financial / Page / FinancialTypeAccount.php
index 2f2f3a08a0721c602b7c23696cdc53227b5a6381..346d783628789ced730fcf349877b5c7b26d6cab 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -51,7 +51,7 @@ class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page {
    * @var array
    * @static
    */
-  static $_aid = null;
+  protected $_aid = null;
 
   /**
    * Get BAO Name
@@ -71,15 +71,15 @@ class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page {
     if (!(self::$_links)) {
       self::$_links = array(
         CRM_Core_Action::UPDATE  => array(
-          'name'  => ts('Edit'),
-          'url'   => 'civicrm/admin/financial/financialType/accounts',
-          'qs'    => 'action=update&id=%%id%%&aid=%%aid%%&reset=1',
+          'name' => ts('Edit'),
+          'url' => 'civicrm/admin/financial/financialType/accounts',
+          'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1',
           'title' => ts('Edit Financial Type Account'),
         ),
         CRM_Core_Action::DELETE  => array(
-          'name'  => ts('Delete'),
-          'url'   => 'civicrm/admin/financial/financialType/accounts',
-          'qs'    => 'action=delete&id=%%id%%&aid=%%aid%%',
+          'name' => ts('Delete'),
+          'url' => 'civicrm/admin/financial/financialType/accounts',
+          'qs' => 'action=delete&id=%%id%%&aid=%%aid%%',
           'title' => ts('Delete Financial Type Account'),
         ),
       );
@@ -134,17 +134,18 @@ class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page {
     $params['entity_id'] = $this->_aid;
     $params['entity_table'] = 'civicrm_financial_type';
     if ($this->_aid) {
+      $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
       $this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name');
       CRM_Utils_System::setTitle($this->_title .' - '.ts( 'Assigned Financial Accounts'));
-      $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type');
-      $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship');
+      $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
+      $accountRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
       $dao->copyValues($params);
       $dao->find();
       while ($dao->fetch()) {
         $financialType[$dao->id] = array();
-        CRM_Core_DAO::storeValues( $dao, $financialType[$dao->id] );
+        CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
 
-        $params = array( 'id' => $dao->financial_account_id );
+        $params = array('id' => $dao->financial_account_id);
         $defaults = array();
         $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
         if (!empty($financialAccount)) {
@@ -165,14 +166,24 @@ class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page {
             $financialType[$dao->id]['account_relationship'] = CRM_Utils_Array::value($dao->account_relationship, $accountRelationship);
           }
         }
-
         // form all action links
         $action = array_sum(array_keys($this->links()));
-        $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
+        $links = self::links();
+
+        //CRM-12492
+        if ($dao->account_relationship == $relationTypeId) {
+          unset($links[CRM_Core_Action::DELETE]);
+        }
+        $financialType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action,
           array(
             'id' => $dao->id,
             'aid'=> $dao->entity_id,
-          )
+          ),
+          ts('more'),
+          FALSE,
+          'financialTypeAccount.manage.action',
+          'FinancialTypeAccount',
+          $dao->id
         );
       }
       $this->assign('rows', $financialType);