Merge pull request #17512 from semseysandor/relative-date-filter
[civicrm-core.git] / CRM / Financial / Page / FinancialAccount.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of financial types
20 */
21 class CRM_Financial_Page_FinancialAccount extends CRM_Core_Page_Basic {
22
23 public $useLivePageJS = TRUE;
24 /**
25 * The action links that we need to display for the browse screen.
26 *
27 * @var array
28 */
29 public static $_links = NULL;
30
31 /**
32 * Get BAO Name.
33 *
34 * @return string
35 * Classname of BAO.
36 */
37 public function getBAOName() {
38 return 'CRM_Financial_BAO_FinancialAccount';
39 }
40
41 /**
42 * Get action Links.
43 *
44 * @return array
45 * (reference) of action links
46 */
47 public function &links() {
48 if (!(self::$_links)) {
49 self::$_links = [
50 CRM_Core_Action::UPDATE => [
51 'name' => ts('Edit'),
52 'url' => 'civicrm/admin/financial/financialAccount',
53 'qs' => 'action=update&id=%%id%%&reset=1',
54 'title' => ts('Edit Financial Type'),
55 ],
56 CRM_Core_Action::DISABLE => [
57 'name' => ts('Disable'),
58 'ref' => 'crm-enable-disable',
59 'title' => ts('Disable Financial Type'),
60 ],
61 CRM_Core_Action::ENABLE => [
62 'name' => ts('Enable'),
63 'ref' => 'crm-enable-disable',
64 'title' => ts('Enable Financial Type'),
65 ],
66 CRM_Core_Action::DELETE => [
67 'name' => ts('Delete'),
68 'url' => 'civicrm/admin/financial/financialAccount',
69 'qs' => 'action=delete&id=%%id%%',
70 'title' => ts('Delete Financial Type'),
71 ],
72 ];
73 }
74 return self::$_links;
75 }
76
77 /**
78 * Browse all custom data groups.
79 */
80 public function browse() {
81 // get all custom groups sorted by weight
82 $contributionType = [];
83 $dao = new CRM_Financial_DAO_FinancialAccount();
84 $dao->orderBy('financial_account_type_id, name');
85 $dao->find();
86 $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
87
88 while ($dao->fetch()) {
89 $contributionType[$dao->id] = [];
90 CRM_Core_DAO::storeValues($dao, $contributionType[$dao->id]);
91 $contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id];
92 // form all action links
93 $action = array_sum(array_keys($this->links()));
94
95 // update enable/disable links depending on if it is is_reserved or is_active
96 if ($dao->is_reserved) {
97 continue;
98 }
99 else {
100 if ($dao->is_active) {
101 $action -= CRM_Core_Action::ENABLE;
102 }
103 else {
104 $action -= CRM_Core_Action::DISABLE;
105 }
106 }
107
108 $contributionType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
109 ['id' => $dao->id],
110 ts('more'),
111 FALSE,
112 'financialAccount.manage.action',
113 'FinancialAccount',
114 $dao->id
115 );
116 }
117 $this->assign('rows', $contributionType);
118 }
119
120 /**
121 * Get name of edit form.
122 *
123 * @return string
124 * Classname of edit form.
125 */
126 public function editForm() {
127 return 'CRM_Financial_Form_FinancialAccount';
128 }
129
130 /**
131 * Get edit form name.
132 *
133 * @return string
134 * name of this page.
135 */
136 public function editName() {
137 return 'Financial Types';
138 }
139
140 /**
141 * Get user context.
142 *
143 * @param null $mode
144 *
145 * @return string
146 * user context.
147 */
148 public function userContext($mode = NULL) {
149 return 'civicrm/admin/financial/financialAccount';
150 }
151
152 }