-
Notifications
You must be signed in to change notification settings - Fork 3
/
remotetools.php
151 lines (134 loc) · 6.1 KB
/
remotetools.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/*-------------------------------------------------------+
| SYSTOPIA Remote Tools |
| Copyright (C) 2020 SYSTOPIA |
| Author: B. Endres ([email protected]) |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/
require_once 'remotetools.civix.php';
use CRM_Remotetools_ExtensionUtil as E;
use Civi\RemoteContact\RemoteContactGetRequest as RemoteContactGetRequest;
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
function _remotetools_composer_autoload(): void {
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
}
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function remotetools_civicrm_config(&$config)
{
_remotetools_composer_autoload();
_remotetools_civix_civicrm_config($config);
// register events (with our own wrapper to avoid duplicate registrations)
$dispatcher = new \Civi\RemoteToolsDispatcher();
// EVENT REMOTECONTAT GETPROFILES
$dispatcher->addUniqueListener(
'civi.remotecontact.getprofiles',
['CRM_Remotetools_RemoteContactProfile', 'registerKnownProfiles']);
// EVENT REMOTECONTACT GETFIELDS
$dispatcher->addUniqueListener(
'civi.remotecontact.getfields',
['Civi\RemoteContact\GetFieldsEvent', 'addProfileFields'], RemoteContactGetRequest::BEFORE_EXECUTE_REQUEST);
// EVENT REMOTECONTACT GET
$dispatcher->addUniqueListener(
'civi.remotecontact.get',
['Civi\RemoteContact\RemoteContactGetRequest', 'initProfile'], RemoteContactGetRequest::INITIALISATION);
$dispatcher->addUniqueListener(
'civi.remotecontact.get',
['CRM_Remotetools_RemoteContactQueryTools', 'processMultivalueOrSearch'], RemoteContactGetRequest::INITIALISATION - 10);
$dispatcher->addUniqueListener(
'civi.remotecontact.get',
['Civi\RemoteContact\RemoteContactGetRequest', 'addProfileRequirements'], RemoteContactGetRequest::BEFORE_EXECUTE_REQUEST);
$dispatcher->addUniqueListener(
'civi.remotecontact.get',
['Civi\RemoteContact\RemoteContactGetRequest', 'addProfileRequirements'], RemoteContactGetRequest::BEFORE_EXECUTE_REQUEST);
$dispatcher->addUniqueListener(
'civi.remotecontact.get',
['Civi\RemoteContact\RemoteContactGetRequest', 'executeRequest'], RemoteContactGetRequest::EXECUTE_REQUEST);
$dispatcher->addUniqueListener(
'civi.remotecontact.get',
['Civi\RemoteContact\RemoteContactGetRequest', 'filterResult'], RemoteContactGetRequest::AFTER_EXECUTE_REQUEST);
}
function remotetools_civicrm_container(ContainerBuilder $container): void {
_remotetools_composer_autoload();
// Allow lazy service instantiation (requires symfony/proxy-manager-bridge)
if (class_exists(\ProxyManager\Configuration::class) && class_exists(RuntimeInstantiator::class)) {
$container->setProxyInstantiator(new RuntimeInstantiator());
}
$globResource = new GlobResource(__DIR__ . '/services', '/*.php', FALSE);
// Container will be rebuilt if a *.php file is added to services.
$container->addResource($globResource);
foreach ($globResource->getIterator() as $path => $info) {
// Container will be rebuilt if file changes.
$container->addResource(new FileResource($path));
require $path;
}
if (function_exists('_remotetools_test_civicrm_container')) {
// Allow to use different services in tests.
_remotetools_test_civicrm_container($container);
}
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function remotetools_civicrm_install()
{
_remotetools_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function remotetools_civicrm_enable()
{
_remotetools_civix_civicrm_enable();
}
/**
* Define custom (Drupal) permissions
*/
function remotetools_civicrm_permission(array &$permissions): void {
// remote contacts
$permissions['match remote contacts'] = [
'label' => E::ts('CiviRemote: Match and link contacts'),
'description' => E::ts('Match and link contacts via remote contact ID.')
];
$permissions['retrieve remote contact information'] = [
'label' => E::ts('CiviRemote: Retrieve contacts'),
'description' => E::ts('Retrieve information of remote contacts.')
];
$permissions['retrieve own contact information'] = [
'label' => E::ts('CiviRemote: Retrieve own contact'),
'description' => E::ts('Retrieve information of requesting remote contact.'),
];
$permissions['update remote contact information'] = [
'label' => E::ts('CiviRemote: Update contacts'),
'description' => E::ts('Update information of remote contacts.'),
];
}
/**
* Set permissions RemoteContact API
*/
function remotetools_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) {
$permissions['remote_contact']['match'] = ['match remote contacts'];
$permissions['remote_contact']['get_roles'] = ['retrieve remote contact information'];
$permissions['remote_contact']['get'] = ['retrieve remote contact information'];
$permissions['remote_contact']['get_self'] = ['retrieve own contact information'];
$permissions['remote_contact']['update'] = ['update remote contact information'];
}