3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
37 * Page for displaying list of financial types
39 class CRM_Financial_Page_FinancialType
extends CRM_Core_Page_Basic
{
41 public $useLivePageJS = TRUE;
43 * The action links that we need to display for the browse screen.
47 static $_links = NULL;
55 public function getBAOName() {
56 return 'CRM_Financial_BAO_FinancialType';
63 * (reference) of action links
65 public function &links() {
66 if (!(self
::$_links)) {
67 self
::$_links = array(
68 CRM_Core_Action
::BROWSE
=> array(
69 'name' => ts('Accounts'),
70 'url' => 'civicrm/admin/financial/financialType/accounts',
71 'qs' => 'reset=1&action=browse&aid=%%id%%',
72 'title' => ts('Accounts'),
74 CRM_Core_Action
::UPDATE
=> array(
76 'url' => 'civicrm/admin/financial/financialType',
77 'qs' => 'action=update&id=%%id%%&reset=1',
78 'title' => ts('Edit Financial Type'),
80 CRM_Core_Action
::DISABLE
=> array(
81 'name' => ts('Disable'),
82 'ref' => 'crm-enable-disable',
83 'title' => ts('Disable Financial Type'),
85 CRM_Core_Action
::ENABLE
=> array(
86 'name' => ts('Enable'),
87 'ref' => 'crm-enable-disable',
88 'title' => ts('Enable Financial Type'),
90 CRM_Core_Action
::DELETE
=> array(
91 'name' => ts('Delete'),
92 'url' => 'civicrm/admin/financial/financialType',
93 'qs' => 'action=delete&id=%%id%%',
94 'title' => ts('Delete Financial Type'),
104 * This method is called after the page is created. It checks for the
105 * type of action and executes that action.
106 * Finally it calls the parent's run method.
110 public function run() {
111 // get the requested action
112 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse'); // default to 'browse'
114 // assign vars to templates
115 $this->assign('action', $action);
116 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
118 // what action to take ?
119 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
120 $this->edit($action, $id);
124 return parent
::run();
128 * Browse all financial types.
133 public function browse() {
134 // get all financial types sorted by weight
135 $financialType = array();
136 $dao = new CRM_Financial_DAO_FinancialType();
137 $dao->orderBy('name');
140 while ($dao->fetch()) {
141 $financialType[$dao->id
] = array();
142 CRM_Core_DAO
::storeValues($dao, $financialType[$dao->id
]);
143 $defaults = $financialAccountId = array();
144 $financialAccounts = CRM_Contribute_PseudoConstant
::financialAccount();
145 $financialAccountIds = array();
147 $params['entity_id'] = $dao->id
;
148 $params['entity_table'] = 'civicrm_financial_type';
149 CRM_Financial_BAO_FinancialTypeAccount
::retrieve($params, CRM_Core_DAO
::$_nullArray, $financialAccountIds);
151 foreach ($financialAccountIds as $key => $values) {
152 if (!empty($financialAccounts[$values['financial_account_id']])) {
153 $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array
::value(
154 $values['financial_account_id'], $financialAccounts);
158 if (!empty($financialAccountId)) {
159 $financialType[$dao->id
]['financial_account'] = implode(',', $financialAccountId);
162 // form all action links
163 $action = array_sum(array_keys($this->links()));
165 // update enable/disable links depending on if it is is_reserved or is_active
166 if ($dao->is_reserved
) {
167 $action -= CRM_Core_Action
::ENABLE
;
168 $action -= CRM_Core_Action
::DISABLE
;
169 $action -= CRM_Core_Action
::DELETE
;
173 if ($dao->is_active
) {
174 $action -= CRM_Core_Action
::ENABLE
;
177 $action -= CRM_Core_Action
::DISABLE
;
181 $financialType[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(), $action,
182 array('id' => $dao->id
),
185 'financialType.manage.action',
190 $this->assign('rows', $financialType);
194 * Get name of edit form.
197 * Classname of edit form.
199 public function editForm() {
200 return 'CRM_Financial_Form_FinancialType';
204 * Get edit form name.
209 public function editName() {
210 return 'Financial Types';
221 public function userContext($mode = NULL) {
222 return 'civicrm/admin/financial/financialType';