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