-
Notifications
You must be signed in to change notification settings - Fork 19
/
campaign.php
228 lines (212 loc) · 8.19 KB
/
campaign.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
/*-------------------------------------------------------+
| CAMPAIGN MANAGER |
| Copyright (C) 2015-2017 SYSTOPIA |
| Author: N. Bochan |
| 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 'campaign.civix.php';
/**
* Implementation of hook_civicrm_config
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function campaign_civicrm_config(&$config) {
_campaign_civix_civicrm_config($config);
if (isset(Civi::$statics[__FUNCTION__])) {
return;
}
Civi::$statics[__FUNCTION__] = 1;
Civi::dispatcher()->addListener(
'hook_civicrm_alterMenu',
['CRM_CampaignManager_MenuReplacer', 'replaceCampaignMenu'],
-1000
);
}
/**
* Implementation of hook_civicrm_install
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function campaign_civicrm_install() {
_campaign_civix_civicrm_install();
CRM_CampaignManager_Config::installScheduledJob();
}
/**
* Implementation of hook_civicrm_enable
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function campaign_civicrm_enable() {
_campaign_civix_civicrm_enable();
//add/check the required option groups
campaign_civicrm_install_options(campaign_civicrm_options());
}
/**
* Implementation of hook_civicrm_angularModules
*/
function campaign_civicrm_angularModules(&$angularModules) {
$angularModules['crmD3'] = array(
'ext' => 'civicrm',
'js' => array('ang/crmD3.js', 'bower_components/d3/d3.min.js'),
);
$angularModules['campaign'] = array(
'ext' => 'de.systopia.campaign',
'js' => array('js/campaign.js'),
'partials' => array('partials'),
'css' => array('css/lib/d3-context-menu.css', 'css/campaign.css'),
'requires' => array('crmD3'),
);
}
/**
* Implementation of hook_civicrm_buildForm:
*/
function campaign_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Campaign_Form_Campaign') {
$action = $form->getAction();
if($action == CRM_Core_Action::NONE && !isset($_GET['qfKey'])) {
// pre-select element
if(isset($_GET['pid'])){
$select = $form->getElement('parent_id');
$select->setSelected($_GET['pid']);
}
CRM_Core_Region::instance('form-body')->add(array(
'template' => 'CRM/CampaignManager/Form/ExtendedCampaign.tpl',
));
}elseif (($action == CRM_Core_Action::UPDATE || $action == CRM_Core_Action::ADD) && !isset($_GET['qfKey'])) {
$cid = $form->get('id');
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value('parent_id', $form->get('values')), $cid);
if (!empty($campaigns)) {
$form->addElement('select', 'parent_id', ts('Parent ID', array('domain' => 'de.systopia.campaign')),
array('' => ts('- select Parent -', array('domain' => 'de.systopia.campaign'))) + $campaigns,
array('class' => 'crm-select2')
);
}
CRM_Core_Region::instance('form-body')->add(array(
'template' => 'CRM/CampaignManager/Form/ExtendedCampaign.tpl',
));
}
}
}
function campaign_civicrm_links( $op, $objectName, $objectId, &$links, &$mask, &$values ) {
if($objectName == 'Campaign' && $op == 'campaign.dashboard.row') {
$viewLink = array(
'name' => ts('View', array('domain' => 'de.systopia.campaign')),
'title' => ts('View Campaign', array('domain' => 'de.systopia.campaign')),
'class' => 'no-popup',
'url' => CRM_Utils_System::url("civicrm/a/#/campaign/{$objectId}/view"),
);
array_unshift($links, $viewLink);
}
}
function campaign_civicrm_install_options($data) {
foreach ($data as $groupName => $group) {
// check group existence
$result = civicrm_api('option_group', 'getsingle', array('version' => 3, 'name' => $groupName));
if (isset($result['is_error']) && $result['is_error']) {
$params = array(
'version' => 3,
'sequential' => 1,
'name' => $groupName,
'is_reserved' => 1,
'is_active' => 1,
'title' => $group['title'],
'description' => $group['description'],
);
$result = civicrm_api('option_group', 'create', $params);
$group_id = $result['values'][0]['id'];
} else {
$group_id = $result['id'];
}
if (is_array($group['values'])) {
$groupValues = $group['values'];
$weight = 1;
foreach ($groupValues as $valueName => $value) {
$result = civicrm_api('option_value', 'getsingle', array('version' => 3, 'name' => $valueName));
if (isset($result['is_error']) && $result['is_error']) {
$params = array(
'version' => 3,
'sequential' => 1,
'option_group_id' => $group_id,
'name' => $valueName,
'label' => $value['label'],
'weight' => isset($value['weight']) ? $value['weight'] : $weight,
'is_default' => $value['is_default'],
'is_active' => 1,
);
if (isset($value['value'])) {
$params['value'] = $value['value'];
}
$result = civicrm_api('option_value', 'create', $params);
} else {
$weight = $result['weight'] + 1;
}
}
}
}
}
function campaign_civicrm_options() {
return array(
'campaign_expense_types' => array(
'title' => ts('Campaign Expense Types', array('domain' => 'de.systopia.campaign')),
'description' => '',
'is_reserved' => 1,
'is_active' => 1,
'values' => array(
'Default' => array(
'label' => ts('Default', array('domain' => 'de.systopia.campaign')),
'is_default' => 1,
'is_reserved' => 1,
'value' => 1,
),
),
),
);
}
/**
* alterAPIPermissions() hook allows you to change the permissions checked when doing API 3 calls.
*/
function campaign_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
{
// Mend Campaign API
$permissions['campaign']['getsingle'] = array('manage campaign');
$permissions['campaign']['create'] = array('manage campaign');
$permissions['campaign']['update'] = array('manage campaign');
$permissions['campaign']['get'] = array('manage campaign');
$permissions['campaign']['delete'] = array('manage campaign');
// CampaignExpense API
$permissions['campaign_expense']['get'] = array('manage campaign');
$permissions['campaign_expense']['getsingle'] = array('manage campaign');
$permissions['campaign_expense']['getsum'] = array('manage campaign');
$permissions['campaign_expense']['create'] = array('manage campaign');
$permissions['campaign_expense']['update'] = array('manage campaign');
$permissions['campaign_expense']['delete'] = array('manage campaign');
// CampaignKPI API
$permissions['campaign_kpi']['get'] = array('manage campaign');
// CampaignTree API
$permissions['campaign_tree']['getids'] = array('manage campaign');
$permissions['campaign_tree']['getparentids'] = array('manage campaign');
$permissions['campaign_tree']['gettree'] = array('manage campaign');
$permissions['campaign_tree']['setnodeparent'] = array('manage campaign');
$permissions['campaign_tree']['clone'] = array('manage campaign');
$permissions['campaign_tree']['getcustominfo'] = array('manage campaign');
$permissions['campaign_tree']['getlinks'] = array('manage campaign');
}
/**
* Implements hook_coreResourceList
*
* @param array $list
* @param string $region
*/
function campaign_civicrm_coreResourceList(&$list, $region) {
Civi::resources()
->addStyleFile('de.systopia.campaign', 'css/campaign.css', 0, $region);
}