Merge pull request #14004 from mfb/set-utf8
[civicrm-core.git] / CRM / Financial / Page / FinancialType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
32 */
33
34 /**
35 * Page for displaying list of financial types
36 */
37 class CRM_Financial_Page_FinancialType extends CRM_Core_Page_Basic {
38
39 public $useLivePageJS = TRUE;
40 /**
41 * The action links that we need to display for the browse screen.
42 *
43 * @var array
44 */
45 public static $_links = NULL;
46
47 /**
48 * Get BAO Name.
49 *
50 * @return string
51 * Classname of BAO.
52 */
53 public function getBAOName() {
54 return 'CRM_Financial_BAO_FinancialType';
55 }
56
57 /**
58 * Get action Links.
59 *
60 * @return array
61 * (reference) of action links
62 */
63 public function &links() {
64 if (!(self::$_links)) {
65 self::$_links = [
66 CRM_Core_Action::BROWSE => [
67 'name' => ts('Accounts'),
68 'url' => 'civicrm/admin/financial/financialType/accounts',
69 'qs' => 'reset=1&action=browse&aid=%%id%%',
70 'title' => ts('Accounts'),
71 ],
72 CRM_Core_Action::UPDATE => [
73 'name' => ts('Edit'),
74 'url' => 'civicrm/admin/financial/financialType',
75 'qs' => 'action=update&id=%%id%%&reset=1',
76 'title' => ts('Edit Financial Type'),
77 ],
78 CRM_Core_Action::DISABLE => [
79 'name' => ts('Disable'),
80 'ref' => 'crm-enable-disable',
81 'title' => ts('Disable Financial Type'),
82 ],
83 CRM_Core_Action::ENABLE => [
84 'name' => ts('Enable'),
85 'ref' => 'crm-enable-disable',
86 'title' => ts('Enable Financial Type'),
87 ],
88 CRM_Core_Action::DELETE => [
89 'name' => ts('Delete'),
90 'url' => 'civicrm/admin/financial/financialType',
91 'qs' => 'action=delete&id=%%id%%',
92 'title' => ts('Delete Financial Type'),
93 ],
94 ];
95 }
96 return self::$_links;
97 }
98
99 /**
100 * Browse all financial types.
101 */
102 public function browse() {
103 // Check permission for Financial Type when ACL-FT is enabled
104 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
105 && !CRM_Core_Permission::check('administer CiviCRM Financial Types')
106 ) {
107 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
108 }
109 // get all financial types sorted by weight
110 $financialType = [];
111 $dao = new CRM_Financial_DAO_FinancialType();
112 $dao->orderBy('name');
113 $dao->find();
114
115 while ($dao->fetch()) {
116 $financialType[$dao->id] = [];
117 CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
118 $defaults = $financialAccountId = [];
119 $financialAccounts = CRM_Contribute_PseudoConstant::financialAccount();
120 $financialAccountIds = [];
121
122 $params['entity_id'] = $dao->id;
123 $params['entity_table'] = 'civicrm_financial_type';
124 CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, CRM_Core_DAO::$_nullArray, $financialAccountIds);
125
126 foreach ($financialAccountIds as $key => $values) {
127 if (!empty($financialAccounts[$values['financial_account_id']])) {
128 $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value(
129 $values['financial_account_id'], $financialAccounts);
130 }
131 }
132
133 if (!empty($financialAccountId)) {
134 $financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId);
135 }
136
137 // form all action links
138 $action = array_sum(array_keys($this->links()));
139
140 // update enable/disable links depending on if it is is_reserved or is_active
141 if ($dao->is_reserved) {
142 $action -= CRM_Core_Action::ENABLE;
143 $action -= CRM_Core_Action::DISABLE;
144 $action -= CRM_Core_Action::DELETE;
145 }
146 else {
147 if ($dao->is_active) {
148 $action -= CRM_Core_Action::ENABLE;
149 }
150 else {
151 $action -= CRM_Core_Action::DISABLE;
152 }
153 }
154
155 $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
156 ['id' => $dao->id],
157 ts('more'),
158 FALSE,
159 'financialType.manage.action',
160 'FinancialType',
161 $dao->id
162 );
163 }
164 $this->assign('rows', $financialType);
165 }
166
167 /**
168 * Get name of edit form.
169 *
170 * @return string
171 * Classname of edit form.
172 */
173 public function editForm() {
174 return 'CRM_Financial_Form_FinancialType';
175 }
176
177 /**
178 * Get edit form name.
179 *
180 * @return string
181 * name of this page.
182 */
183 public function editName() {
184 return 'Financial Types';
185 }
186
187 /**
188 * Get user context.
189 *
190 * @param null $mode
191 *
192 * @return string
193 * user context.
194 */
195 public function userContext($mode = NULL) {
196 return 'civicrm/admin/financial/financialType';
197 }
198
199 }