3 require_once 'financialacls.civix.php';
5 use CRM_Financialacls_ExtensionUtil
as E
;
9 * Implements hook_civicrm_config().
11 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
13 function financialacls_civicrm_config(&$config) {
14 _financialacls_civix_civicrm_config($config);
18 * Implements hook_civicrm_xmlMenu().
20 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
22 function financialacls_civicrm_xmlMenu(&$files) {
23 _financialacls_civix_civicrm_xmlMenu($files);
27 * Implements hook_civicrm_install().
29 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
31 function financialacls_civicrm_install() {
32 _financialacls_civix_civicrm_install();
36 * Implements hook_civicrm_postInstall().
38 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
40 function financialacls_civicrm_postInstall() {
41 _financialacls_civix_civicrm_postInstall();
45 * Implements hook_civicrm_uninstall().
47 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
49 function financialacls_civicrm_uninstall() {
50 _financialacls_civix_civicrm_uninstall();
54 * Implements hook_civicrm_enable().
56 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
58 function financialacls_civicrm_enable() {
59 _financialacls_civix_civicrm_enable();
63 * Implements hook_civicrm_disable().
65 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
67 function financialacls_civicrm_disable() {
68 _financialacls_civix_civicrm_disable();
72 * Implements hook_civicrm_upgrade().
74 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
76 function financialacls_civicrm_upgrade($op, CRM_Queue_Queue
$queue = NULL) {
77 return _financialacls_civix_civicrm_upgrade($op, $queue);
81 * Implements hook_civicrm_managed().
83 * Generate a list of entities to create/deactivate/delete when this module
84 * is installed, disabled, uninstalled.
86 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
88 function financialacls_civicrm_managed(&$entities) {
89 _financialacls_civix_civicrm_managed($entities);
93 * Implements hook_civicrm_caseTypes().
95 * Generate a list of case-types.
97 * Note: This hook only runs in CiviCRM 4.4+.
99 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
101 function financialacls_civicrm_caseTypes(&$caseTypes) {
102 _financialacls_civix_civicrm_caseTypes($caseTypes);
106 * Implements hook_civicrm_angularModules().
108 * Generate a list of Angular modules.
110 * Note: This hook only runs in CiviCRM 4.5+. It may
111 * use features only available in v4.6+.
113 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
115 function financialacls_civicrm_angularModules(&$angularModules) {
116 _financialacls_civix_civicrm_angularModules($angularModules);
120 * Implements hook_civicrm_alterSettingsFolders().
122 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
124 function financialacls_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
125 _financialacls_civix_civicrm_alterSettingsFolders($metaDataFolders);
129 * Implements hook_civicrm_entityTypes().
131 * Declare entity types provided by this module.
133 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
135 function financialacls_civicrm_entityTypes(&$entityTypes) {
136 _financialacls_civix_civicrm_entityTypes($entityTypes);
140 * Implements hook_civicrm_thems().
142 function financialacls_civicrm_themes(&$themes) {
143 _financialacls_civix_civicrm_themes($themes);
147 * Intervene to prevent deletion, where permissions block it.
150 * @param string $objectName
151 * @param int|null $id
152 * @param array $params
154 * @throws \API_Exception
155 * @throws \CRM_Core_Exception
157 function financialacls_civicrm_pre($op, $objectName, $id, &$params) {
158 if (!financialacls_is_acl_limiting_enabled()) {
161 if ($objectName === 'LineItem' && !empty($params['check_permissions'])) {
162 $operationMap = ['delete' => CRM_Core_Action
::DELETE
, 'edit' => CRM_Core_Action
::UPDATE
, 'create' => CRM_Core_Action
::ADD
];
163 CRM_Financial_BAO_FinancialType
::getAvailableFinancialTypes($types, $operationMap[$op]);
164 if (empty($params['financial_type_id'])) {
165 $params['financial_type_id'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_LineItem', $params['id'], 'financial_type_id');
167 if (!in_array($params['financial_type_id'], array_keys($types))) {
168 throw new API_Exception('You do not have permission to ' . $op . ' this line item');
174 * Implements hook_civicrm_selectWhereClause().
176 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_selectWhereClause
178 function financialacls_civicrm_selectWhereClause($entity, &$clauses) {
179 if (!financialacls_is_acl_limiting_enabled()) {
182 if ($entity === 'LineItem') {
184 CRM_Financial_BAO_FinancialType
::getAvailableFinancialTypes($types);
186 $clauses['financial_type_id'] = 'IN (' . implode(',', array_keys($types)) . ')';
189 $clauses['financial_type_id'] = '= 0';
196 * Remove unpermitted options.
198 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildAmount
200 * @param string $component
201 * @param \CRM_Core_Form $form
202 * @param array $feeBlock
204 function financialacls_civicrm_buildAmount($component, $form, &$feeBlock) {
205 if (!financialacls_is_acl_limiting_enabled()) {
209 foreach ($feeBlock as $key => $value) {
210 foreach ($value['options'] as $k => $options) {
211 if (!CRM_Core_Permission
::check('add contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($options['financial_type_id']))) {
212 unset($feeBlock[$key]['options'][$k]);
215 if (empty($feeBlock[$key]['options'])) {
216 unset($feeBlock[$key]);
222 * Remove unpermitted membership types from selection availability..
224 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_membershipTypeValues
226 * @param \CRM_Core_Form $form
227 * @param array $membershipTypeValues
229 function financialacls_civicrm_membershipTypeValues($form, &$membershipTypeValues) {
230 if (!financialacls_is_acl_limiting_enabled()) {
233 $financialTypes = NULL;
234 $financialTypes = CRM_Financial_BAO_FinancialType
::getAvailableFinancialTypes($financialTypes, CRM_Core_Action
::ADD
);
235 foreach ($membershipTypeValues as $id => $type) {
236 if (!isset($financialTypes[$type['financial_type_id']])) {
237 unset($membershipTypeValues[$id]);
243 * Remove unpermitted financial types from field Options in search context.
245 * Search context is described as
246 * 'search' => "search: searchable options are returned; labels are translated.",
247 * So this is appropriate to removing the options from search screens.
249 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_fieldOptions
251 * @param string $entity
252 * @param string $field
253 * @param array $options
254 * @param array $params
256 function financialacls_civicrm_fieldOptions($entity, $field, &$options, $params) {
257 if (!financialacls_is_acl_limiting_enabled()) {
260 if ($entity === 'Contribution' && $field === 'financial_type_id' && $params['context'] === 'search') {
261 $action = CRM_Core_Action
::VIEW
;
262 // At this stage we are only considering the view action. Code from
263 // CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes().
265 CRM_Core_Action
::VIEW
=> 'view',
266 CRM_Core_Action
::UPDATE
=> 'edit',
267 CRM_Core_Action
::ADD
=> 'add',
268 CRM_Core_Action
::DELETE
=> 'delete',
270 $cacheKey = 'available_types_' . $action;
271 if (!isset(\Civi
::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey])) {
272 foreach ($options as $finTypeId => $type) {
273 if (!CRM_Core_Permission
::check($actions[$action] . ' contributions of type ' . $type)) {
274 unset($options[$finTypeId]);
277 \Civi
::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey] = $options;
279 $options = \Civi
::$statics['CRM_Financial_BAO_FinancialType'][$cacheKey];
284 * Is financial acl limiting enabled.
286 * Once this extension is detangled enough to be optional this will go
287 * and the status of the extension rather than the setting will dictate.
291 function financialacls_is_acl_limiting_enabled() {
292 return (bool) Civi
::settings()->get('acl_financial_type');
295 // --- Functions below this ship commented out. Uncomment as required. ---
298 * Implements hook_civicrm_preProcess().
300 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
302 //function financialacls_civicrm_preProcess($formName, &$form) {
307 * Implements hook_civicrm_navigationMenu().
309 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
311 //function financialacls_civicrm_navigationMenu(&$menu) {
312 // _financialacls_civix_insert_navigation_menu($menu, 'Mailings', array(
313 // 'label' => E::ts('New subliminal message'),
314 // 'name' => 'mailing_subliminal_message',
315 // 'url' => 'civicrm/mailing/subliminal',
316 // 'permission' => 'access CiviMail',
317 // 'operator' => 'OR',
320 // _financialacls_civix_navigationMenu($menu);