Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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-2013 | |
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 | * The action links that we need to display for the browse screen | |
42 | * | |
43 | * @var array | |
44 | * @static | |
45 | */ | |
46 | static $_links = null; | |
47 | ||
48 | /** | |
49 | * Get BAO Name | |
50 | * | |
51 | * @return string Classname of BAO. | |
52 | */ | |
53 | function getBAOName() { | |
54 | return 'CRM_Financial_BAO_FinancialType'; | |
55 | } | |
56 | ||
57 | /** | |
58 | * Get action Links | |
59 | * | |
60 | * @return array (reference) of action links | |
61 | */ | |
62 | function &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'), | |
70 | ), | |
71 | CRM_Core_Action::UPDATE => array( | |
72 | 'name' => ts('Edit'), | |
73 | 'url' => 'civicrm/admin/financial/financialType', | |
74 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
75 | 'title' => ts('Edit Financial Type'), | |
76 | ), | |
77 | CRM_Core_Action::DISABLE => array( | |
78 | 'name' => ts('Disable'), | |
79 | 'extra' => 'onclick = "enableDisable( %%id%%,\''. 'CRM_Financial_BAO_FinancialType' . '\',\'' . 'enable-disable' . '\' );"', | |
80 | 'ref' => 'disable-action', | |
81 | 'title' => ts('Disable Financial Type'), | |
82 | ), | |
83 | CRM_Core_Action::ENABLE => array( | |
84 | 'name' => ts('Enable'), | |
85 | 'extra' => 'onclick = "enableDisable( %%id%%,\''. 'CRM_Financial_BAO_FinancialType' . '\',\'' . 'disable-enable' . '\' );"', | |
86 | 'ref' => 'enable-action', | |
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 | * @access public | |
109 | * | |
110 | */ | |
111 | function run() { | |
112 | // get the requested action | |
113 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse' | |
114 | ||
115 | // assign vars to templates | |
116 | $this->assign('action', $action); | |
117 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); | |
118 | ||
119 | // what action to take ? | |
120 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
121 | $this->edit($action, $id) ; | |
122 | } | |
123 | ||
124 | // parent run | |
125 | return parent::run(); | |
126 | } | |
127 | ||
128 | /** | |
129 | * Browse all financial types | |
130 | * | |
131 | * | |
132 | * @return void | |
133 | * @access public | |
134 | * @static | |
135 | */ | |
136 | function browse() { | |
137 | // get all financial types sorted by weight | |
138 | $financialType = array(); | |
139 | $dao = new CRM_Financial_DAO_FinancialType(); | |
140 | $dao->orderBy('name'); | |
141 | $dao->find(); | |
142 | ||
143 | while ($dao->fetch()) { | |
144 | $financialType[$dao->id] = array(); | |
145 | CRM_Core_DAO::storeValues( $dao, $financialType[$dao->id]); | |
146 | $defaults = $financialAccountId = array(); | |
ecc1e0ef PN |
147 | $financialAccounts = CRM_Contribute_PseudoConstant::financialAccount(); |
148 | $financialAccountIds = array(); | |
03e04002 | 149 | |
ecc1e0ef PN |
150 | $params['entity_id'] = $dao->id; |
151 | $params['entity_table'] = 'civicrm_financial_type'; | |
152 | CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, CRM_Core_DAO::$_nullArray, $financialAccountIds); | |
6a488035 TO |
153 | |
154 | foreach( $financialAccountIds as $key => $values){ | |
155 | if (CRM_Utils_Array::value($values['financial_account_id'], $financialAccounts)) { | |
156 | $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value( | |
157 | $values['financial_account_id'], $financialAccounts ); | |
158 | } | |
159 | } | |
160 | ||
161 | if (!empty($financialAccountId)) { | |
162 | $financialType[$dao->id]['financial_account'] = implode( ',', $financialAccountId ); | |
163 | } | |
164 | ||
165 | // form all action links | |
166 | $action = array_sum(array_keys($this->links())); | |
167 | ||
168 | // update enable/disable links depending on if it is is_reserved or is_active | |
169 | if ($dao->is_reserved) { | |
170 | $action -= CRM_Core_Action::ENABLE; | |
171 | $action -= CRM_Core_Action::DISABLE; | |
172 | $action -= CRM_Core_Action::DELETE; | |
173 | //continue; | |
174 | } | |
175 | else { | |
176 | if ($dao->is_active) { | |
177 | $action -= CRM_Core_Action::ENABLE; | |
178 | } | |
179 | else { | |
180 | $action -= CRM_Core_Action::DISABLE; | |
181 | } | |
182 | } | |
183 | ||
184 | $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
87dab4a4 AH |
185 | array('id' => $dao->id), |
186 | ts('more'), | |
187 | FALSE, | |
188 | 'financialType.manage.action', | |
189 | 'FinancialType', | |
190 | $dao->id | |
191 | ); | |
6a488035 TO |
192 | } |
193 | $this->assign('rows', $financialType); | |
194 | } | |
195 | ||
196 | /** | |
197 | * Get name of edit form | |
198 | * | |
199 | * @return string Classname of edit form. | |
200 | */ | |
201 | function editForm() { | |
202 | return 'CRM_Financial_Form_FinancialType'; | |
203 | } | |
204 | ||
205 | /** | |
206 | * Get edit form name | |
207 | * | |
208 | * @return string name of this page. | |
209 | */ | |
210 | function editName() { | |
211 | return 'Financial Types'; | |
212 | } | |
213 | ||
214 | /** | |
215 | * Get user context. | |
216 | * | |
217 | * @return string user context. | |
218 | */ | |
219 | function userContext($mode = null) { | |
220 | return 'civicrm/admin/financial/financialType'; | |
221 | } | |
222 | } |