3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
48 static $_links = NULL;
53 * @return string Classname of BAO.
55 public function getBAOName() {
56 return 'CRM_Financial_BAO_FinancialType';
62 * @return array (reference) of action links
64 public function &links() {
65 if (!(self
::$_links)) {
66 self
::$_links = array(
67 CRM_Core_Action
::BROWSE
=> array(
68 'name' => ts('Accounts'),
69 'url' => 'civicrm/admin/financial/financialType/accounts',
70 'qs' => 'reset=1&action=browse&aid=%%id%%',
71 'title' => ts('Accounts'),
73 CRM_Core_Action
::UPDATE
=> array(
75 'url' => 'civicrm/admin/financial/financialType',
76 'qs' => 'action=update&id=%%id%%&reset=1',
77 'title' => ts('Edit Financial Type'),
79 CRM_Core_Action
::DISABLE
=> array(
80 'name' => ts('Disable'),
81 'ref' => 'crm-enable-disable',
82 'title' => ts('Disable Financial Type'),
84 CRM_Core_Action
::ENABLE
=> array(
85 'name' => ts('Enable'),
86 'ref' => 'crm-enable-disable',
87 'title' => ts('Enable Financial Type'),
89 CRM_Core_Action
::DELETE
=> array(
90 'name' => ts('Delete'),
91 'url' => 'civicrm/admin/financial/financialType',
92 'qs' => 'action=delete&id=%%id%%',
93 'title' => ts('Delete Financial Type'),
103 * This method is called after the page is created. It checks for the
104 * type of action and executes that action.
105 * 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
134 public function browse() {
135 // get all financial types sorted by weight
136 $financialType = array();
137 $dao = new CRM_Financial_DAO_FinancialType();
138 $dao->orderBy('name');
141 while ($dao->fetch()) {
142 $financialType[$dao->id
] = array();
143 CRM_Core_DAO
::storeValues($dao, $financialType[$dao->id
]);
144 $defaults = $financialAccountId = array();
145 $financialAccounts = CRM_Contribute_PseudoConstant
::financialAccount();
146 $financialAccountIds = array();
148 $params['entity_id'] = $dao->id
;
149 $params['entity_table'] = 'civicrm_financial_type';
150 CRM_Financial_BAO_FinancialTypeAccount
::retrieve($params, CRM_Core_DAO
::$_nullArray, $financialAccountIds);
152 foreach ($financialAccountIds as $key => $values) {
153 if (!empty($financialAccounts[$values['financial_account_id']])) {
154 $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array
::value(
155 $values['financial_account_id'], $financialAccounts);
159 if (!empty($financialAccountId)) {
160 $financialType[$dao->id
]['financial_account'] = implode(',', $financialAccountId);
163 // form all action links
164 $action = array_sum(array_keys($this->links()));
166 // update enable/disable links depending on if it is is_reserved or is_active
167 if ($dao->is_reserved
) {
168 $action -= CRM_Core_Action
::ENABLE
;
169 $action -= CRM_Core_Action
::DISABLE
;
170 $action -= CRM_Core_Action
::DELETE
;
174 if ($dao->is_active
) {
175 $action -= CRM_Core_Action
::ENABLE
;
178 $action -= CRM_Core_Action
::DISABLE
;
182 $financialType[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(), $action,
183 array('id' => $dao->id
),
186 'financialType.manage.action',
191 $this->assign('rows', $financialType);
195 * Get name of edit form
197 * @return string Classname of edit form.
199 public function editForm() {
200 return 'CRM_Financial_Form_FinancialType';
206 * @return string name of this page.
208 public function editName() {
209 return 'Financial Types';
217 * @return string user context.
219 public function userContext($mode = NULL) {
220 return 'civicrm/admin/financial/financialType';