Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Page for displaying list of financial types | |
38 | */ | |
39 | class CRM_Financial_Page_FinancialAccount extends CRM_Core_Page_Basic { | |
96f50de2 CW |
40 | |
41 | public $useLivePageJS = TRUE; | |
6a488035 TO |
42 | /** |
43 | * The action links that we need to display for the browse screen | |
44 | * | |
45 | * @var array | |
46 | * @static | |
47 | */ | |
045f52a3 | 48 | static $_links = NULL; |
6a488035 TO |
49 | |
50 | /** | |
51 | * Get BAO Name | |
52 | * | |
a6c01b45 CW |
53 | * @return string |
54 | * Classname of BAO. | |
6a488035 | 55 | */ |
00be9182 | 56 | public function getBAOName() { |
6a488035 TO |
57 | return 'CRM_Financial_BAO_FinancialAccount'; |
58 | } | |
59 | ||
60 | /** | |
61 | * Get action Links | |
62 | * | |
a6c01b45 CW |
63 | * @return array |
64 | * (reference) of action links | |
6a488035 | 65 | */ |
00be9182 | 66 | public function &links() { |
6a488035 TO |
67 | if (!(self::$_links)) { |
68 | self::$_links = array( | |
69 | CRM_Core_Action::UPDATE => array( | |
70 | 'name' => ts('Edit'), | |
71 | 'url' => 'civicrm/admin/financial/financialAccount', | |
72 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
73 | 'title' => ts('Edit Financial Type'), | |
74 | ), | |
75 | CRM_Core_Action::DISABLE => array( | |
76 | 'name' => ts('Disable'), | |
134bc82c | 77 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
78 | 'title' => ts('Disable Financial Type'), |
79 | ), | |
80 | CRM_Core_Action::ENABLE => array( | |
81 | 'name' => ts('Enable'), | |
134bc82c | 82 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
83 | 'title' => ts('Enable Financial Type'), |
84 | ), | |
85 | CRM_Core_Action::DELETE => array( | |
86 | 'name' => ts('Delete'), | |
87 | 'url' => 'civicrm/admin/financial/financialAccount', | |
88 | 'qs' => 'action=delete&id=%%id%%', | |
89 | 'title' => ts('Delete Financial Type'), | |
90 | ), | |
91 | ); | |
92 | } | |
93 | return self::$_links; | |
94 | } | |
95 | ||
96 | /** | |
97 | * Run the page. | |
98 | * | |
99 | * This method is called after the page is created. It checks for the | |
100 | * type of action and executes that action. | |
101 | * Finally it calls the parent's run method. | |
102 | * | |
103 | * @return void | |
6a488035 | 104 | */ |
00be9182 | 105 | public function run() { |
6a488035 | 106 | // get the requested action |
045f52a3 | 107 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // default to 'browse' |
6a488035 TO |
108 | |
109 | // assign vars to templates | |
110 | $this->assign('action', $action); | |
045f52a3 | 111 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); |
6a488035 TO |
112 | |
113 | // what action to take ? | |
114 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
045f52a3 | 115 | $this->edit($action, $id); |
6a488035 TO |
116 | } |
117 | ||
03e04002 | 118 | // parent run |
6a488035 TO |
119 | return parent::run(); |
120 | } | |
121 | ||
122 | /** | |
123 | * Browse all custom data groups. | |
124 | * | |
125 | * | |
126 | * @return void | |
6a488035 TO |
127 | * @static |
128 | */ | |
00be9182 | 129 | public function browse() { |
6a488035 TO |
130 | // get all custom groups sorted by weight |
131 | $contributionType = array(); | |
132 | $dao = new CRM_Financial_DAO_FinancialAccount(); | |
133 | $dao->orderBy('financial_account_type_id, name'); | |
134 | $dao->find(); | |
7611ae71 | 135 | $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id'); |
6a488035 TO |
136 | |
137 | while ($dao->fetch()) { | |
138 | $contributionType[$dao->id] = array(); | |
481a74f4 | 139 | CRM_Core_DAO::storeValues($dao, $contributionType[$dao->id]); |
045f52a3 | 140 | $contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id]; |
6a488035 TO |
141 | // form all action links |
142 | $action = array_sum(array_keys($this->links())); | |
143 | ||
144 | // update enable/disable links depending on if it is is_reserved or is_active | |
145 | if ($dao->is_reserved) { | |
146 | continue; | |
147 | } | |
148 | else { | |
149 | if ($dao->is_active) { | |
150 | $action -= CRM_Core_Action::ENABLE; | |
151 | } | |
152 | else { | |
153 | $action -= CRM_Core_Action::DISABLE; | |
154 | } | |
155 | } | |
156 | ||
157 | $contributionType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
87dab4a4 AH |
158 | array('id' => $dao->id), |
159 | ts('more'), | |
160 | FALSE, | |
161 | 'financialAccount.manage.action', | |
162 | 'FinancialAccount', | |
163 | $dao->id | |
164 | ); | |
6a488035 TO |
165 | } |
166 | $this->assign('rows', $contributionType); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Get name of edit form | |
171 | * | |
a6c01b45 CW |
172 | * @return string |
173 | * Classname of edit form. | |
6a488035 | 174 | */ |
00be9182 | 175 | public function editForm() { |
6a488035 TO |
176 | return 'CRM_Financial_Form_FinancialAccount'; |
177 | } | |
178 | ||
179 | /** | |
180 | * Get edit form name | |
181 | * | |
a6c01b45 CW |
182 | * @return string |
183 | * name of this page. | |
6a488035 | 184 | */ |
00be9182 | 185 | public function editName() { |
6a488035 TO |
186 | return 'Financial Types'; |
187 | } | |
188 | ||
189 | /** | |
190 | * Get user context. | |
191 | * | |
da6b46f4 EM |
192 | * @param null $mode |
193 | * | |
a6c01b45 CW |
194 | * @return string |
195 | * user context. | |
6a488035 | 196 | */ |
045f52a3 | 197 | public function userContext($mode = NULL) { |
6a488035 TO |
198 | return 'civicrm/admin/financial/financialAccount'; |
199 | } | |
200 | } |