Merge pull request #16898 from civicrm/5.24
[civicrm-core.git] / CRM / Financial / Page / FinancialAccount.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * Page for displaying list of financial types
20 */
21class CRM_Financial_Page_FinancialAccount extends CRM_Core_Page_Basic {
96f50de2
CW
22
23 public $useLivePageJS = TRUE;
6a488035 24 /**
fe482240 25 * The action links that we need to display for the browse screen.
6a488035
TO
26 *
27 * @var array
6a488035 28 */
7b966967 29 public static $_links = NULL;
6a488035
TO
30
31 /**
fe482240 32 * Get BAO Name.
6a488035 33 *
a6c01b45
CW
34 * @return string
35 * Classname of BAO.
6a488035 36 */
00be9182 37 public function getBAOName() {
6a488035
TO
38 return 'CRM_Financial_BAO_FinancialAccount';
39 }
40
41 /**
fe482240 42 * Get action Links.
6a488035 43 *
a6c01b45
CW
44 * @return array
45 * (reference) of action links
6a488035 46 */
00be9182 47 public function &links() {
6a488035 48 if (!(self::$_links)) {
be2fb01f
CW
49 self::$_links = [
50 CRM_Core_Action::UPDATE => [
353ffa53
TO
51 'name' => ts('Edit'),
52 'url' => 'civicrm/admin/financial/financialAccount',
53 'qs' => 'action=update&id=%%id%%&reset=1',
6a488035 54 'title' => ts('Edit Financial Type'),
be2fb01f
CW
55 ],
56 CRM_Core_Action::DISABLE => [
353ffa53 57 'name' => ts('Disable'),
134bc82c 58 'ref' => 'crm-enable-disable',
6a488035 59 'title' => ts('Disable Financial Type'),
be2fb01f
CW
60 ],
61 CRM_Core_Action::ENABLE => [
353ffa53 62 'name' => ts('Enable'),
134bc82c 63 'ref' => 'crm-enable-disable',
6a488035 64 'title' => ts('Enable Financial Type'),
be2fb01f
CW
65 ],
66 CRM_Core_Action::DELETE => [
353ffa53
TO
67 'name' => ts('Delete'),
68 'url' => 'civicrm/admin/financial/financialAccount',
69 'qs' => 'action=delete&id=%%id%%',
6a488035 70 'title' => ts('Delete Financial Type'),
be2fb01f
CW
71 ],
72 ];
6a488035
TO
73 }
74 return self::$_links;
75 }
76
6a488035
TO
77 /**
78 * Browse all custom data groups.
6a488035 79 */
00be9182 80 public function browse() {
6a488035 81 // get all custom groups sorted by weight
be2fb01f 82 $contributionType = [];
6a488035
TO
83 $dao = new CRM_Financial_DAO_FinancialAccount();
84 $dao->orderBy('financial_account_type_id, name');
85 $dao->find();
7611ae71 86 $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
6a488035
TO
87
88 while ($dao->fetch()) {
be2fb01f 89 $contributionType[$dao->id] = [];
481a74f4 90 CRM_Core_DAO::storeValues($dao, $contributionType[$dao->id]);
045f52a3 91 $contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id];
6a488035
TO
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,
be2fb01f 109 ['id' => $dao->id],
87dab4a4
AH
110 ts('more'),
111 FALSE,
112 'financialAccount.manage.action',
113 'FinancialAccount',
114 $dao->id
115 );
6a488035
TO
116 }
117 $this->assign('rows', $contributionType);
118 }
119
120 /**
fe482240 121 * Get name of edit form.
6a488035 122 *
a6c01b45
CW
123 * @return string
124 * Classname of edit form.
6a488035 125 */
00be9182 126 public function editForm() {
6a488035
TO
127 return 'CRM_Financial_Form_FinancialAccount';
128 }
129
130 /**
fe482240 131 * Get edit form name.
6a488035 132 *
a6c01b45
CW
133 * @return string
134 * name of this page.
6a488035 135 */
00be9182 136 public function editName() {
6a488035
TO
137 return 'Financial Types';
138 }
139
140 /**
141 * Get user context.
142 *
da6b46f4
EM
143 * @param null $mode
144 *
a6c01b45
CW
145 * @return string
146 * user context.
6a488035 147 */
045f52a3 148 public function userContext($mode = NULL) {
6a488035
TO
149 return 'civicrm/admin/financial/financialAccount';
150 }
96025800 151
6a488035 152}