Merge pull request #18867 from sunilpawar/sms_provider
[civicrm-core.git] / ext / financialacls / financialacls.php
1 <?php
2
3 require_once 'financialacls.civix.php';
4 // phpcs:disable
5 use CRM_Financialacls_ExtensionUtil as E;
6 // phpcs:enable
7
8 /**
9 * Implements hook_civicrm_config().
10 *
11 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
12 */
13 function financialacls_civicrm_config(&$config) {
14 _financialacls_civix_civicrm_config($config);
15 }
16
17 /**
18 * Implements hook_civicrm_xmlMenu().
19 *
20 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
21 */
22 function financialacls_civicrm_xmlMenu(&$files) {
23 _financialacls_civix_civicrm_xmlMenu($files);
24 }
25
26 /**
27 * Implements hook_civicrm_install().
28 *
29 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
30 */
31 function financialacls_civicrm_install() {
32 _financialacls_civix_civicrm_install();
33 }
34
35 /**
36 * Implements hook_civicrm_postInstall().
37 *
38 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
39 */
40 function financialacls_civicrm_postInstall() {
41 _financialacls_civix_civicrm_postInstall();
42 }
43
44 /**
45 * Implements hook_civicrm_uninstall().
46 *
47 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
48 */
49 function financialacls_civicrm_uninstall() {
50 _financialacls_civix_civicrm_uninstall();
51 }
52
53 /**
54 * Implements hook_civicrm_enable().
55 *
56 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
57 */
58 function financialacls_civicrm_enable() {
59 _financialacls_civix_civicrm_enable();
60 }
61
62 /**
63 * Implements hook_civicrm_disable().
64 *
65 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
66 */
67 function financialacls_civicrm_disable() {
68 _financialacls_civix_civicrm_disable();
69 }
70
71 /**
72 * Implements hook_civicrm_upgrade().
73 *
74 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
75 */
76 function financialacls_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
77 return _financialacls_civix_civicrm_upgrade($op, $queue);
78 }
79
80 /**
81 * Implements hook_civicrm_managed().
82 *
83 * Generate a list of entities to create/deactivate/delete when this module
84 * is installed, disabled, uninstalled.
85 *
86 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
87 */
88 function financialacls_civicrm_managed(&$entities) {
89 _financialacls_civix_civicrm_managed($entities);
90 }
91
92 /**
93 * Implements hook_civicrm_caseTypes().
94 *
95 * Generate a list of case-types.
96 *
97 * Note: This hook only runs in CiviCRM 4.4+.
98 *
99 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
100 */
101 function financialacls_civicrm_caseTypes(&$caseTypes) {
102 _financialacls_civix_civicrm_caseTypes($caseTypes);
103 }
104
105 /**
106 * Implements hook_civicrm_angularModules().
107 *
108 * Generate a list of Angular modules.
109 *
110 * Note: This hook only runs in CiviCRM 4.5+. It may
111 * use features only available in v4.6+.
112 *
113 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
114 */
115 function financialacls_civicrm_angularModules(&$angularModules) {
116 _financialacls_civix_civicrm_angularModules($angularModules);
117 }
118
119 /**
120 * Implements hook_civicrm_alterSettingsFolders().
121 *
122 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
123 */
124 function financialacls_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
125 _financialacls_civix_civicrm_alterSettingsFolders($metaDataFolders);
126 }
127
128 /**
129 * Implements hook_civicrm_entityTypes().
130 *
131 * Declare entity types provided by this module.
132 *
133 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
134 */
135 function financialacls_civicrm_entityTypes(&$entityTypes) {
136 _financialacls_civix_civicrm_entityTypes($entityTypes);
137 }
138
139 /**
140 * Implements hook_civicrm_thems().
141 */
142 function financialacls_civicrm_themes(&$themes) {
143 _financialacls_civix_civicrm_themes($themes);
144 }
145
146 /**
147 * Intervene to prevent deletion, where permissions block it.
148 *
149 * @param string $op
150 * @param string $objectName
151 * @param int|null $id
152 * @param array $params
153 *
154 * @throws \API_Exception
155 * @throws \CRM_Core_Exception
156 */
157 function financialacls_civicrm_pre($op, $objectName, $id, &$params) {
158 if ($objectName === 'LineItem' && !empty($params['check_permissions'])) {
159 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
160 $operationMap = ['delete' => CRM_Core_Action::DELETE, 'edit' => CRM_Core_Action::UPDATE, 'create' => CRM_Core_Action::ADD];
161 CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $operationMap[$op]);
162 if (empty($params['financial_type_id'])) {
163 $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_LineItem', $params['id'], 'financial_type_id');
164 }
165 if (!in_array($params['financial_type_id'], array_keys($types))) {
166 throw new API_Exception('You do not have permission to ' . $op . ' this line item');
167 }
168 }
169 }
170 }
171
172 /**
173 * Implements hook_civicrm_selectWhereClause().
174 *
175 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_selectWhereClause
176 */
177 function financialacls_civicrm_selectWhereClause($entity, &$clauses) {
178 if ($entity === 'LineItem') {
179 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
180 $types = [];
181 CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
182 if ($types) {
183 $clauses['financial_type_id'] = 'IN (' . implode(',', array_keys($types)) . ')';
184 }
185 else {
186 $clauses['financial_type_id'] = '= 0';
187 }
188 }
189 }
190
191 }
192
193 /**
194 * Remove un.
195 *
196 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildAmount
197 *
198 * @param string $component
199 * @param \CRM_Core_Form $form
200 * @param array $feeBlock
201 */
202 function financialacls_civicrm_buildAmount($component, $form, &$feeBlock) {
203 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
204 foreach ($feeBlock as $key => $value) {
205 foreach ($value['options'] as $k => $options) {
206 if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) {
207 unset($feeBlock[$key]['options'][$k]);
208 }
209 }
210 if (empty($feeBlock[$key]['options'])) {
211 unset($feeBlock[$key]);
212 }
213 }
214 }
215 }
216
217 /**
218 * Remove unpermitted membership types from selection availability..
219 *
220 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_membershipTypeValues
221 *
222 * @param \CRM_Core_Form $form
223 * @param array $membershipTypeValues
224 */
225 function financialacls_civicrm_membershipTypeValues($form, &$membershipTypeValues) {
226 $financialTypes = NULL;
227 $financialTypes = CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
228 foreach ($membershipTypeValues as $id => $type) {
229 if (!isset($financialTypes[$type['financial_type_id']])) {
230 unset($membershipTypeValues[$id]);
231 }
232 }
233 }
234
235 /**
236 * Remove unpermitted financial types from field Options in search context.
237 *
238 * Search context is described as
239 * 'search' => "search: searchable options are returned; labels are translated.",
240 * So this is appropriate to removing the options from search screens.
241 *
242 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_fieldOptions
243 *
244 * @param string $entity
245 * @param string $field
246 * @param array $options
247 * @param array $params
248 */
249 function financialacls_civicrm_fieldOptions($entity, $field, &$options, $params) {
250 if ($entity === 'Contribution' && $field === 'financial_type_id' && $params['context'] === 'search') {
251 $action = CRM_Core_Action::VIEW;
252 // At this stage we are only considering the view action. Code from
253 // CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes().
254 $actions = [
255 CRM_Core_Action::VIEW => 'view',
256 CRM_Core_Action::UPDATE => 'edit',
257 CRM_Core_Action::ADD => 'add',
258 CRM_Core_Action::DELETE => 'delete',
259 ];
260 $cacheKey = 'available_types_' . $action;
261 if (!isset(\Civi::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey])) {
262 foreach ($options as $finTypeId => $type) {
263 if (!CRM_Core_Permission::check($actions[$action] . ' contributions of type ' . $type)) {
264 unset($options[$finTypeId]);
265 }
266 }
267 \Civi::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey] = $options;
268 }
269 $options = \Civi::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey];
270 }
271 }
272
273 // --- Functions below this ship commented out. Uncomment as required. ---
274
275 /**
276 * Implements hook_civicrm_preProcess().
277 *
278 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
279 */
280 //function financialacls_civicrm_preProcess($formName, &$form) {
281 //
282 //}
283
284 /**
285 * Implements hook_civicrm_navigationMenu().
286 *
287 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
288 */
289 //function financialacls_civicrm_navigationMenu(&$menu) {
290 // _financialacls_civix_insert_navigation_menu($menu, 'Mailings', array(
291 // 'label' => E::ts('New subliminal message'),
292 // 'name' => 'mailing_subliminal_message',
293 // 'url' => 'civicrm/mailing/subliminal',
294 // 'permission' => 'access CiviMail',
295 // 'operator' => 'OR',
296 // 'separator' => 0,
297 // ));
298 // _financialacls_civix_navigationMenu($menu);
299 //}