3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * Page for displaying list of financial types
39 class CRM_Financial_Page_FinancialType
extends CRM_Core_Page_Basic
{
41 * The action links that we need to display for the browse screen
46 static $_links = null;
51 * @return string Classname of BAO.
53 function getBAOName() {
54 return 'CRM_Financial_BAO_FinancialType';
60 * @return array (reference) of action links
63 if (!(self
::$_links)) {
64 self
::$_links = array(
65 CRM_Core_Action
::BROWSE
=> array(
66 'name' => ts('Accounts'),
67 'url' => 'civicrm/admin/financial/financialType/accounts',
68 'qs' => 'reset=1&action=browse&aid=%%id%%',
69 'title' => ts('Accounts'),
71 CRM_Core_Action
::UPDATE
=> array(
73 'url' => 'civicrm/admin/financial/financialType',
74 'qs' => 'action=update&id=%%id%%&reset=1',
75 'title' => ts('Edit Financial Type'),
77 CRM_Core_Action
::DISABLE
=> array(
78 'name' => ts('Disable'),
79 'ref' => 'crm-enable-disable',
80 'title' => ts('Disable Financial Type'),
82 CRM_Core_Action
::ENABLE
=> array(
83 'name' => ts('Enable'),
84 'ref' => 'crm-enable-disable',
85 'title' => ts('Enable Financial Type'),
87 CRM_Core_Action
::DELETE
=> array(
88 'name' => ts('Delete'),
89 'url' => 'civicrm/admin/financial/financialType',
90 'qs' => 'action=delete&id=%%id%%',
91 'title' => ts('Delete Financial Type'),
101 * This method is called after the page is created. It checks for the
102 * type of action and executes that action.
103 * Finally it calls the parent's run method.
110 // get the requested action
111 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse'
113 // assign vars to templates
114 $this->assign('action', $action);
115 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, false, 0);
117 // what action to take ?
118 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
119 $this->edit($action, $id) ;
123 return parent
::run();
127 * Browse all financial types
135 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
136 // get all financial types sorted by weight
137 $financialType = array();
138 $dao = new CRM_Financial_DAO_FinancialType();
139 $dao->orderBy('name');
142 while ($dao->fetch()) {
143 $financialType[$dao->id
] = array();
144 CRM_Core_DAO
::storeValues( $dao, $financialType[$dao->id
]);
145 $defaults = $financialAccountId = array();
146 $financialAccounts = CRM_Contribute_PseudoConstant
::financialAccount();
147 $financialAccountIds = array();
149 $params['entity_id'] = $dao->id
;
150 $params['entity_table'] = 'civicrm_financial_type';
151 CRM_Financial_BAO_FinancialTypeAccount
::retrieve($params, CRM_Core_DAO
::$_nullArray, $financialAccountIds);
153 foreach( $financialAccountIds as $key => $values){
154 if (!empty($financialAccounts[$values['financial_account_id']])) {
155 $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array
::value(
156 $values['financial_account_id'], $financialAccounts );
160 if (!empty($financialAccountId)) {
161 $financialType[$dao->id
]['financial_account'] = implode( ',', $financialAccountId );
164 // form all action links
165 $action = array_sum(array_keys($this->links()));
167 // update enable/disable links depending on if it is is_reserved or is_active
168 if ($dao->is_reserved
) {
169 $action -= CRM_Core_Action
::ENABLE
;
170 $action -= CRM_Core_Action
::DISABLE
;
171 $action -= CRM_Core_Action
::DELETE
;
175 if ($dao->is_active
) {
176 $action -= CRM_Core_Action
::ENABLE
;
179 $action -= CRM_Core_Action
::DISABLE
;
183 $financialType[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(), $action,
184 array('id' => $dao->id
),
187 'financialType.manage.action',
192 $this->assign('rows', $financialType);
196 * Get name of edit form
198 * @return string Classname of edit form.
200 function editForm() {
201 return 'CRM_Financial_Form_FinancialType';
207 * @return string name of this page.
209 function editName() {
210 return 'Financial Types';
216 * @return string user context.
218 function userContext($mode = null) {
219 return 'civicrm/admin/financial/financialType';