-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
membershiprelationshiptypeeditor.php
109 lines (97 loc) · 3.94 KB
/
membershiprelationshiptypeeditor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
require_once 'membershiprelationshiptypeeditor.civix.php';
use CRM_Membershiprelationshiptypeeditor_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function membershiprelationshiptypeeditor_civicrm_config(&$config) {
_membershiprelationshiptypeeditor_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function membershiprelationshiptypeeditor_civicrm_install() {
_membershiprelationshiptypeeditor_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function membershiprelationshiptypeeditor_civicrm_enable() {
_membershiprelationshiptypeeditor_civix_civicrm_enable();
}
/**
* Enabled relationship type field on edit membership type form.
*
* @param $formName
* @param $form
*/
function membershiprelationshiptypeeditor_civicrm_buildForm($formName, &$form) {
if ($formName === 'CRM_Member_Form_MembershipType' && isset($form->_id) && isset($form->_action) && $form->_action == CRM_Core_Action::UPDATE) {
CRM_Core_Resources::singleton()->addScriptFile('au.com.agileware.membershiprelationshiptypeeditor', 'js/membership_type.js');
$form->assign('membershipRecordsExists', FALSE);
$form->_elements[$form->_elementIndex['relationship_type_id']]->_flagFrozen = 0;
$form->assign('selectedRelationshipTypes', $form->_elements[$form->_elementIndex['relationship_type_id']]->_values);
}
if ($formName == "CRM_Member_Form_MembershipType") {
$form->assign('formAction', $form->_action);
CRM_Core_Region::instance('page-footer')->add([
'template' => E::path('templates/membership_type_relationship.tpl'),
]);
}
}
/**
* Add membership type in queue to process if relationship types value has been changed.
*
* @param $formName
* @param $form
*/
function membershiprelationshiptypeeditor_civicrm_postProcess($formName, &$form) {
if ($formName == "CRM_Member_Form_MembershipType" && isset($form->_id) && isset($form->_action) && $form->_action == CRM_Core_Action::UPDATE) {
$defaultRelationshipTypes = $form->_defaultValues['relationship_type_id'];
$submittedRelationshipTypes = $form->_submitValues['relationship_type_id'];
if (!is_array($defaultRelationshipTypes)) {
$defaultRelationshipTypes = [];
}
if (!is_array($submittedRelationshipTypes)) {
$submittedRelationshipTypes = [];
}
$modifiedRelationshipTypes = array_diff($defaultRelationshipTypes, $submittedRelationshipTypes);
$modifiedRelationshipTypes = array_merge(array_diff($submittedRelationshipTypes, $defaultRelationshipTypes), $modifiedRelationshipTypes);
if (count($modifiedRelationshipTypes) > 0) {
$typesToProcess = Civi::settings()->get('membershiprelationshiptypeeditor_mtypes_process');
if ($typesToProcess == '' || $typesToProcess == NULL) {
$typesToProcess = [];
}
$typesToProcess[$form->_id] = TRUE;
Civi::settings()->set('membershiprelationshiptypeeditor_mtypes_process', $typesToProcess);
}
}
}
/**
* Manipulates CiviCRM menu.
*
* @param $menu
*/
function membershiprelationshiptypeeditor_civicrm_navigationMenu(&$menu) {
_membershiprelationshiptypeeditor_civix_insert_navigation_menu($menu, 'Administer', [
'label' => E::ts('Membership Relationship Type Editor'),
'name' => 'MembershipRelationshipTypeEditor',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
]);
_membershiprelationshiptypeeditor_civix_insert_navigation_menu($menu, 'Administer/MembershipRelationshipTypeEditor', [
'label' => E::ts('Settings'),
'name' => 'MembershipRelationshipTypeEditorSettings',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'url' => 'civicrm/membershiprelationshiptypeeditor/settings',
'separator' => 0,
]);
}