INFRA-132 - Remove white space after an opening "(" or before a closing ")"
[civicrm-core.git] / CRM / Financial / Page / FinancialType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * Page for displaying list of financial types
38 */
39 class CRM_Financial_Page_FinancialType extends CRM_Core_Page_Basic {
40
41 public $useLivePageJS = TRUE;
42 /**
43 * The action links that we need to display for the browse screen
44 *
45 * @var array
46 * @static
47 */
48 static $_links = NULL;
49
50 /**
51 * Get BAO Name
52 *
53 * @return string Classname of BAO.
54 */
55 public function getBAOName() {
56 return 'CRM_Financial_BAO_FinancialType';
57 }
58
59 /**
60 * Get action Links
61 *
62 * @return array (reference) of action links
63 */
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'),
72 ),
73 CRM_Core_Action::UPDATE => array(
74 'name' => ts('Edit'),
75 'url' => 'civicrm/admin/financial/financialType',
76 'qs' => 'action=update&id=%%id%%&reset=1',
77 'title' => ts('Edit Financial Type'),
78 ),
79 CRM_Core_Action::DISABLE => array(
80 'name' => ts('Disable'),
81 'ref' => 'crm-enable-disable',
82 'title' => ts('Disable Financial Type'),
83 ),
84 CRM_Core_Action::ENABLE => array(
85 'name' => ts('Enable'),
86 'ref' => 'crm-enable-disable',
87 'title' => ts('Enable Financial Type'),
88 ),
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'),
94 ),
95 );
96 }
97 return self::$_links;
98 }
99
100 /**
101 * Run the page.
102 *
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.
106 *
107 * @return void
108 *
109 */
110 public function run() {
111 // get the requested action
112 $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // default to 'browse'
113
114 // assign vars to templates
115 $this->assign('action', $action);
116 $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
117
118 // what action to take ?
119 if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
120 $this->edit($action, $id);
121 }
122
123 // parent run
124 return parent::run();
125 }
126
127 /**
128 * Browse all financial types
129 *
130 *
131 * @return void
132 * @static
133 */
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');
139 $dao->find();
140
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();
147
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);
151
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);
156 }
157 }
158
159 if (!empty($financialAccountId)) {
160 $financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId);
161 }
162
163 // form all action links
164 $action = array_sum(array_keys($this->links()));
165
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;
171 //continue;
172 }
173 else {
174 if ($dao->is_active) {
175 $action -= CRM_Core_Action::ENABLE;
176 }
177 else {
178 $action -= CRM_Core_Action::DISABLE;
179 }
180 }
181
182 $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
183 array('id' => $dao->id),
184 ts('more'),
185 FALSE,
186 'financialType.manage.action',
187 'FinancialType',
188 $dao->id
189 );
190 }
191 $this->assign('rows', $financialType);
192 }
193
194 /**
195 * Get name of edit form
196 *
197 * @return string Classname of edit form.
198 */
199 public function editForm() {
200 return 'CRM_Financial_Form_FinancialType';
201 }
202
203 /**
204 * Get edit form name
205 *
206 * @return string name of this page.
207 */
208 public function editName() {
209 return 'Financial Types';
210 }
211
212 /**
213 * Get user context.
214 *
215 * @param null $mode
216 *
217 * @return string user context.
218 */
219 public function userContext($mode = NULL) {
220 return 'civicrm/admin/financial/financialType';
221 }
222 }