-
Notifications
You must be signed in to change notification settings - Fork 5
/
civioffice.php
188 lines (175 loc) · 6.42 KB
/
civioffice.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
declare(strict_types = 1);
require_once 'civioffice.civix.php';
use CRM_Civioffice_ExtensionUtil as E;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
function _civioffice_composer_autoload(): void {
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
$classLoader = require_once __DIR__ . '/vendor/autoload.php';
if ($classLoader instanceof \Composer\Autoload\ClassLoader) {
// Re-register class loader to append it. (It's automatically prepended.)
$classLoader->unregister();
$classLoader->register();
}
}
}
/**
* Implements hook_civicrm_container().
*/
function civioffice_civicrm_container(ContainerBuilder $container): void
{
_civioffice_composer_autoload();
$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('_civioffice_test_civicrm_container')) {
// Allow to use different services in tests.
_civioffice_test_civicrm_container($container);
}
}
function civioffice_civicrm_searchTasks($objectType, &$tasks)
{
switch ($objectType) {
case 'contact':
$tasks['civioffice'] = [
'title' => E::ts('Create Documents (CiviOffice)'),
'class' => 'CRM_Civioffice_Form_Task_CreateDocuments',
'result' => false,
];
break;
case 'contribution':
$tasks['civioffice'] = [
'title' => E::ts('Create Documents (CiviOffice)'),
'class' => 'CRM_Civioffice_Form_Task_CreateContributionDocuments',
'result' => false,
];
break;
case 'event':
$tasks['civioffice'] = [
'title' => E::ts('Create Documents (CiviOffice)'),
'class' => 'CRM_Civioffice_Form_Task_CreateParticipantDocuments',
'result' => false,
];
break;
case 'membership':
$tasks['civioffice'] = [
'title' => E::ts('Create Documents (CiviOffice)'),
'class' => 'CRM_Civioffice_Form_Task_CreateMembershipDocuments',
'result' => false,
];
break;
case 'activity':
$tasks['civioffice'] = [
'title' => E::ts('Create Documents (CiviOffice)'),
'class' => 'CRM_Civioffice_Form_Task_CreateActivityDocuments',
'result' => false,
];
break;
case 'case':
$tasks['civioffice'] = [
'title' => E::ts('Create Documents (CiviOffice)'),
'class' => 'CRM_Civioffice_Form_Task_CreateCaseDocuments',
'result' => false,
];
}
}
function civioffice_civicrm_summaryActions(&$actions, $contactID)
{
// add "open document with single contact" action
$actions['open_document_with_single_contact'] = [
'ref' => 'civioffice-render-single',
'title' => E::ts('Create CiviOffice document'),
'weight' => -110, // to the top!
'key' => 'open_document_with_single_contact',
'class' => 'medium-popup',
'href' => CRM_Utils_System::url('civicrm/civioffice/document_from_single_contact', "reset=1"), // fixme contact id is passed twice as pid
'permissions' => ['access CiviOffice']
];
}
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function civioffice_civicrm_config(&$config)
{
_civioffice_composer_autoload();
_civioffice_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_permission().
*/
function civioffice_civicrm_permission(&$permissions) {
$permissions['access CiviOffice'] = [
'label' => E::ts('Access CiviOffice'),
'description' => E::ts('Create documents using CiviOffice.'),
];
}
// --- Functions below this ship commented out. Uncomment as required. ---
/**
* Implements hook_civicrm_preProcess().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
*/
//function civioffice_civicrm_preProcess($formName, &$form) {
//
//}
/**
* Implements hook_civicrm_navigationMenu().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
*/
function civioffice_civicrm_navigationMenu(&$menu) {
_civioffice_civix_insert_navigation_menu($menu, 'Administer/Communications', array(
'label' => E::ts('CiviOffice Settings'),
'name' => 'civioffice_settings',
'url' => 'civicrm/admin/civioffice/settings',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
'icon' => 'crm-i fa-file-text',
));
_civioffice_civix_insert_navigation_menu($menu, '', array(
'label' => E::ts('CiviOffice'),
'name' => 'civioffice',
'permission' => 'access CiviOffice',
'operator' => 'OR',
'separator' => 0,
'icon' => 'crm-i fa-file-text',
));
_civioffice_civix_insert_navigation_menu($menu, 'civioffice', array(
'label' => E::ts('CiviOffice Settings'),
'name' => 'civioffice_settings',
'url' => 'civicrm/admin/civioffice/settings',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
'icon' => 'crm-i fa-cogs',
));
_civioffice_civix_insert_navigation_menu($menu, 'civioffice', array(
'label' => E::ts('Upload Documents'),
'name' => 'civioffice_document_upload',
'url' => 'civicrm/civioffice/document_upload',
'permission' => 'access CiviOffice',
'operator' => 'OR',
'separator' => 0,
'icon' => 'crm-i fa-upload',
));
_civioffice_civix_insert_navigation_menu($menu, 'civioffice', array(
'label' => E::ts('Available Tokens'),
'name' => 'civioffice_tokens',
'url' => 'civicrm/civioffice/tokens',
'permission' => 'access CiviOffice',
'operator' => 'OR',
'separator' => 0,
'icon' => 'crm-i fa-code',
));
_civioffice_civix_navigationMenu($menu);
}