-
Notifications
You must be signed in to change notification settings - Fork 0
/
unlinkuser.php
88 lines (81 loc) · 2.95 KB
/
unlinkuser.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
<?php
require_once 'unlinkuser.civix.php';
use CRM_Unlinkuser_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function unlinkuser_civicrm_config(&$config): void {
_unlinkuser_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function unlinkuser_civicrm_install(): void {
_unlinkuser_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function unlinkuser_civicrm_enable(): void {
_unlinkuser_civix_civicrm_enable();
}
function unlinkuser_civicrm_summaryActions( &$actions, $contactID ) {
if (CRM_Core_Permission::check('add contacts')) {
$uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
if ($uid) {
// Add Unlink user Url in Action Dropdown list on contact summary page.
$actions['otherActions']['unlink-user-record'] = [
'title' => ts('Unlink User record from Contact'),
'description' => ts('Unlink the user record for this contact.'),
'weight' => 21,
'ref' => 'crm-contact-unlink-user-record',
'key' => 'unlink-user-record',
'tab' => 'unlink-user-record',
'class' => 'unlink-user-record',
'href' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&action=detach'),
'icon' => 'crm-i fa-unlink',
'permissions' => ['add contacts']
];
}
}
}
function unlinkuser_civicrm_pageRun(&$page) {
if (get_class($page) == 'CRM_Contact_Page_View_Summary') {
if (CRM_Core_Permission::check('add contacts')) {
// Get action and contact id from url parameter.
$action = CRM_Utils_Request::retrieve('action', 'String');
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive');
// if the action is detach then get UID from contact id.
if ($action & CRM_Core_Action::DETACH) {
$uid = CRM_Core_BAO_UFMatch::getUFId($contactId);
if ($contactId && $uid) {
// Find the UF match entry using contact id and user id for current
// domain.
$uFMatches = \Civi\Api4\UFMatch::get(TRUE)
->addWhere('uf_id', '=', $uid)
->addWhere('contact_id', '=', $contactId)
->addWhere('domain_id', '=', 'current_domain')
->setLimit(1)
->execute()->first();
if (!empty ($uFMatches)) {
// Delete the entry from UF match table.
\Civi\Api4\UFMatch::delete(TRUE)
->addWhere('id', '=', $uFMatches['id'])
->execute();
$viewContact = CRM_Utils_System::url('civicrm/contact/view',
"action=view&reset=1&cid={$contactId}"
);
CRM_Core_Error::statusBounce(ts('Unlinked user successfully.'), $viewContact,
'Unlinked user successfully');
}
}
}
}
}
}