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