Merge pull request #4291 from mrpaulc/CRM-12920
[civicrm-core.git] / CRM / Financial / Page / FinancialAccount.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
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 */
39class 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 */
48 static $_links = null;
49
50 /**
51 * Get BAO Name
52 *
53 * @return string Classname of BAO.
54 */
55 function getBAOName() {
56 return 'CRM_Financial_BAO_FinancialAccount';
57 }
58
59 /**
60 * Get action Links
61 *
62 * @return array (reference) of action links
63 */
64 function &links() {
65 if (!(self::$_links)) {
66 self::$_links = array(
67 CRM_Core_Action::UPDATE => array(
68 'name' => ts('Edit'),
69 'url' => 'civicrm/admin/financial/financialAccount',
70 'qs' => 'action=update&id=%%id%%&reset=1',
71 'title' => ts('Edit Financial Type'),
72 ),
73 CRM_Core_Action::DISABLE => array(
74 'name' => ts('Disable'),
134bc82c 75 'ref' => 'crm-enable-disable',
6a488035
TO
76 'title' => ts('Disable Financial Type'),
77 ),
78 CRM_Core_Action::ENABLE => array(
79 'name' => ts('Enable'),
134bc82c 80 'ref' => 'crm-enable-disable',
6a488035
TO
81 'title' => ts('Enable Financial Type'),
82 ),
83 CRM_Core_Action::DELETE => array(
84 'name' => ts('Delete'),
85 'url' => 'civicrm/admin/financial/financialAccount',
86 'qs' => 'action=delete&id=%%id%%',
87 'title' => ts('Delete Financial Type'),
88 ),
89 );
90 }
91 return self::$_links;
92 }
93
94 /**
95 * Run the page.
96 *
97 * This method is called after the page is created. It checks for the
98 * type of action and executes that action.
99 * Finally it calls the parent's run method.
100 *
101 * @return void
102 * @access public
103 *
104 */
105 function run() {
106 // get the requested action
107 $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse'
108
109 // assign vars to templates
110 $this->assign('action', $action);
111 $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0);
112
113 // what action to take ?
114 if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
115 $this->edit($action, $id) ;
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
127 * @access public
128 * @static
129 */
130 function browse() {
131 // get all custom groups sorted by weight
132 $contributionType = array();
133 $dao = new CRM_Financial_DAO_FinancialAccount();
134 $dao->orderBy('financial_account_type_id, name');
135 $dao->find();
7611ae71 136 $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
6a488035
TO
137
138 while ($dao->fetch()) {
139 $contributionType[$dao->id] = array();
140 CRM_Core_DAO::storeValues( $dao, $contributionType[$dao->id]);
141 $contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id];
142 // form all action links
143 $action = array_sum(array_keys($this->links()));
144
145 // update enable/disable links depending on if it is is_reserved or is_active
146 if ($dao->is_reserved) {
147 continue;
148 }
149 else {
150 if ($dao->is_active) {
151 $action -= CRM_Core_Action::ENABLE;
152 }
153 else {
154 $action -= CRM_Core_Action::DISABLE;
155 }
156 }
157
158 $contributionType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
87dab4a4
AH
159 array('id' => $dao->id),
160 ts('more'),
161 FALSE,
162 'financialAccount.manage.action',
163 'FinancialAccount',
164 $dao->id
165 );
6a488035
TO
166 }
167 $this->assign('rows', $contributionType);
168 }
169
170 /**
171 * Get name of edit form
172 *
173 * @return string Classname of edit form.
174 */
175 function editForm() {
176 return 'CRM_Financial_Form_FinancialAccount';
177 }
178
179 /**
180 * Get edit form name
181 *
182 * @return string name of this page.
183 */
184 function editName() {
185 return 'Financial Types';
186 }
187
188 /**
189 * Get user context.
190 *
da6b46f4
EM
191 * @param null $mode
192 *
6a488035
TO
193 * @return string user context.
194 */
195 function userContext($mode = null) {
196 return 'civicrm/admin/financial/financialAccount';
197 }
198}
199
200