-
Notifications
You must be signed in to change notification settings - Fork 4
/
phonenumbervalidator.php
executable file
·126 lines (106 loc) · 3.44 KB
/
phonenumbervalidator.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
require_once 'phonenumbervalidator.civix.php';
require_once 'CRM/Phonenumbervalidator/Utils.php';
const PV_SUBMENU_LABEL = 'Contact Validation';
/**
* Implements hook_civicrm_config().
*/
function phonenumbervalidator_civicrm_config(&$config) {
_phonenumbervalidator_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_xmlMenu().
*/
function phonenumbervalidator_civicrm_xmlMenu(&$files) {
_phonenumbervalidator_civix_civicrm_xmlMenu($files);
}
/**
* Implements hook_civicrm_install().
*/
function phonenumbervalidator_civicrm_install() {
CRM_Phonenumbervalidator_Utils::installDefaults();
return _phonenumbervalidator_civix_civicrm_install();
}
/**
* Implements hook_civicrm_uninstall().
*/
function phonenumbervalidator_civicrm_uninstall() {
CRM_Phonenumbervalidator_Utils::deleteDbSettings();
return _phonenumbervalidator_civix_civicrm_uninstall();
}
/**
* Implements hook_civicrm_enable().
*/
function phonenumbervalidator_civicrm_enable() {
return _phonenumbervalidator_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_disable().
*/
function phonenumbervalidator_civicrm_disable() {
return _phonenumbervalidator_civix_civicrm_disable();
}
/**
* Implements hook_civicrm_upgrade().
*/
function phonenumbervalidator_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _phonenumbervalidator_civix_civicrm_upgrade($op, $queue);
}
/**
* Implements hook_civicrm_managed().
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*/
function phonenumbervalidator_civicrm_managed(&$entities) {
return _phonenumbervalidator_civix_civicrm_managed($entities);
}
function phonenumbervalidator_civicrm_navigationMenu_getSubmenuKey(&$params, $contactMenuId) {
foreach ($params[$contactMenuId]['child'] as $key => $item) {
if ($item['attributes']['label'] == PV_SUBMENU_LABEL) {
return $item['attributes']['navID'];
}
}
return NULL;
}
/**
* Implements hook_civicrm_navigationMenu().
*/
function phonenumbervalidator_civicrm_navigationMenu(&$params) {
// get the id of the Contact Menu
$contactMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Navigation', 'Contacts', 'id', 'name');
// Add the "Contact Validation" submenu to 'Contacts', if it doesn't alrady exist
$subMenuId = phonenumbervalidator_civicrm_navigationMenu_getSubmenuKey($params, $contactMenuId);
if (!$subMenuId) {
// Get the maximum key of $params
$maxKey = max(array_keys($params[$contactMenuId]['child']));
$subMenuId = $maxKey + 1;
$params[$contactMenuId]['child'][$subMenuId] = array(
'attributes' => array(
'label' => PV_SUBMENU_LABEL,
'name' => PV_SUBMENU_LABEL,
'url' => NULL,
'permission' => NULL,
'operator' => NULL,
'separator' => NULL,
'parentID' => $contactMenuId,
'navID' => $subMenuId,
'active' => 1,
),
);
}
$phoneValidatorKey = max(array_keys($params[$contactMenuId]['child'])) + 1;
$params[$contactMenuId]['child'][$subMenuId]['child'][$phoneValidatorKey] = array(
'attributes' => array(
'label' => 'Phone Number Validator',
'name' => 'PhoneValidator',
'url' => 'civicrm/phonenumbervalidator',
'permission' => 'view all contacts',
'operator' => NULL,
'separator' => FALSE,
'parentID' => $subMenuId,
'navID' => $phoneValidatorKey,
'active' => 1,
),
);
}