Merge pull request #9535 from totten/master-phpunit-phpstorm
[civicrm-core.git] / CRM / Mailing / Info.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 * This class introduces component to the system and provides all the
30 * information about it. It needs to extend CRM_Core_Component_Info
31 * abstract class.
32 *
33 * @package CRM
fa938177 34 * @copyright CiviCRM LLC (c) 2004-2016
6a488035
TO
35 */
36class CRM_Mailing_Info extends CRM_Core_Component_Info {
37
e7c15cb6
CW
38 /**
39 * @inheritDoc
40 */
6a488035
TO
41 protected $keyword = 'mailing';
42
43
e0ef6999 44 /**
e7c15cb6 45 * @inheritDoc
e0ef6999
EM
46 * @return array
47 */
6a488035
TO
48 public function getInfo() {
49 return array(
50 'name' => 'CiviMail',
51 'translatedName' => ts('CiviMail'),
52 'title' => 'CiviCRM Mailing Engine',
53 'search' => 1,
54 'showActivitiesInCore' => 1,
55 );
56 }
57
ced9bfed 58 /**
25606795 59 * Get AngularJS modules and their dependencies.
ced9bfed
EM
60 *
61 * @return array
62 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
63 * @see CRM_Utils_Hook::angularModules
64 */
4aef704e 65 public function getAngularModules() {
56621a6c
KJ
66 // load angular files only if valid permissions are granted to the user
67 if (!CRM_Core_Permission::check('access CiviMail')
011c7136
KJ
68 && !CRM_Core_Permission::check('create mailings')
69 && !CRM_Core_Permission::check('schedule mailings')
70 && !CRM_Core_Permission::check('approve mailings')
56621a6c
KJ
71 ) {
72 return array();
73 }
74
78414681
SL
75 $reportIds = array();
76 $reportTypes = array('detail', 'opened', 'bounce', 'clicks');
77 foreach ($reportTypes as $report) {
78 $result = civicrm_api3('ReportInstance', 'get', array(
79 'sequential' => 1,
80 'report_id' => 'mailing/' . $report));
81 $reportIds[$report] = $result['values'][0]['id'];
82 }
4aef704e 83 $result = array();
88e9e883 84 $result['crmMailing'] = array(
030dce01 85 'ext' => 'civicrm',
353ffa53 86 'js' => array(
81bb7011
TO
87 'ang/crmMailing.js',
88 'ang/crmMailing/*.js',
353ffa53 89 ),
81bb7011
TO
90 'css' => array('ang/crmMailing.css'),
91 'partials' => array('ang/crmMailing'),
6bea4a47 92 );
4aef704e 93 $result['crmMailingAB'] = array(
94 'ext' => 'civicrm',
353ffa53 95 'js' => array(
679996bb
TO
96 'ang/crmMailingAB.js',
97 'ang/crmMailingAB/*.js',
98 'ang/crmMailingAB/*/*.js',
353ffa53 99 ),
e9f5761a 100 'css' => array('ang/crmMailingAB.css'),
6f54251a 101 'partials' => array('ang/crmMailingAB'),
4aef704e 102 );
d74bca86
TO
103 $result['crmD3'] = array(
104 'ext' => 'civicrm',
edb34488 105 'js' => array(
6f54251a 106 'ang/crmD3.js',
edb34488
TO
107 'bower_components/d3/d3.min.js',
108 ),
d74bca86 109 );
983052fe 110
8099bfee 111 $config = CRM_Core_Config::singleton();
6bea4a47
TO
112 $session = CRM_Core_Session::singleton();
113 $contactID = $session->get('userID');
d979898e 114
25606795
SB
115 // Get past mailings.
116 // CRM-16155 - Limit to a reasonable number.
51527a6e 117 $civiMails = civicrm_api3('Mailing', 'get', array(
72dd949e 118 'is_completed' => 1,
51527a6e 119 'mailing_type' => array('IN' => array('standalone', 'winner')),
b4a37a31 120 'domain_id' => CRM_Core_Config::domainID(),
72dd949e 121 'return' => array('id', 'name', 'scheduled_date'),
51527a6e
CW
122 'sequential' => 1,
123 'options' => array(
124 'limit' => 500,
125 'sort' => 'is_archived asc, scheduled_date desc',
8099bfee 126 ),
51527a6e 127 ));
25606795 128 // Generic params.
a0f40af4
CW
129 $params = array(
130 'options' => array('limit' => 0),
131 'sequential' => 1,
132 );
8099bfee 133
a0f40af4
CW
134 $groupNames = civicrm_api3('Group', 'get', $params + array(
135 'is_active' => 1,
e7d6f8f8 136 'check_permissions' => TRUE,
a0f40af4
CW
137 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
138 ));
139 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
140 'is_active' => 1,
0499685e 141 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
72dd949e 142 ));
6bea4a47 143
44a7c67d
TO
144 $emailAdd = civicrm_api3('Email', 'get', array(
145 'sequential' => 1,
146 'return' => "email",
147 'contact_id' => $contactID,
148 ));
a0f40af4 149
d979898e 150 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
44a7c67d 151 'sequential' => 1,
a0f40af4 152 'is_active' => 1,
3637550f 153 'return' => array("id", "msg_title"),
44a7c67d
TO
154 'workflow_id' => array('IS NULL' => ""),
155 ));
a0f40af4
CW
156 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
157 'entity' => array('contact', 'mailing'),
8099bfee 158 'sequential' => 1,
a0f40af4 159 ));
d979898e
CW
160 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
161 'option_group_id' => "from_email_address",
84deca8b 162 'domain_id' => CRM_Core_Config::domainID(),
4aef704e 163 ));
c00b95ef
ML
164 $enabledLanguages = CRM_Core_I18n::languages(TRUE);
165 $isMultiLingual = (count($enabledLanguages) > 1);
a0f40af4
CW
166 CRM_Core_Resources::singleton()
167 ->addSetting(array(
168 'crmMailing' => array(
169 'civiMails' => $civiMails['values'],
8099bfee 170 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
a0f40af4
CW
171 'groupNames' => $groupNames['values'],
172 'headerfooterList' => $headerfooterList['values'],
173 'mesTemplate' => $mesTemplate['values'],
174 'emailAdd' => $emailAdd['values'],
a0f40af4
CW
175 'mailTokens' => $mailTokens['values'],
176 'contactid' => $contactID,
177 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
aaffa79f 178 'enableReplyTo' => (int) Civi::settings()->get('replyTo'),
179 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'),
a0f40af4
CW
180 'fromAddress' => $fromAddress['values'],
181 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
182 'id' => 'user_contact_id',
183 'return' => 'email',
184 )),
185 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
186 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
78414681 187 'reportIds' => $reportIds,
c00b95ef
ML
188 'enabledLanguages' => $enabledLanguages,
189 'isMultiLingual' => $isMultiLingual,
a0f40af4
CW
190 ),
191 ))
192 ->addPermissions(array(
193 'view all contacts',
84fd40f3 194 'edit all contacts',
a0f40af4
CW
195 'access CiviMail',
196 'create mailings',
197 'schedule mailings',
198 'approve mailings',
199 'delete in CiviMail',
867299da 200 'edit message templates',
a0f40af4 201 ));
983052fe 202
4aef704e 203 return $result;
204 }
983052fe 205
4aef704e 206 /**
e0ef6999
EM
207 * @return bool
208 */
00be9182 209 public static function workflowEnabled() {
6a488035
TO
210 $config = CRM_Core_Config::singleton();
211
212 // early exit, since not true for most
213 if (!$config->userSystem->is_drupal ||
214 !function_exists('module_exists')
215 ) {
216 return FALSE;
217 }
218
219 if (!module_exists('rules')) {
220 return FALSE;
221 }
222
aaffa79f 223 $enableWorkflow = Civi::settings()->get('civimail_workflow');
6a488035
TO
224
225 return ($enableWorkflow &&
226 $config->userSystem->is_drupal
227 ) ? TRUE : FALSE;
228 }
229
e0ef6999 230 /**
e7c15cb6 231 * @inheritDoc
e0ef6999 232 * @param bool $getAllUnconditionally
221b21b4
AH
233 * @param bool $descriptions
234 * Whether to return permission descriptions
e0ef6999
EM
235 *
236 * @return array
237 */
221b21b4 238 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
6a488035 239 $permissions = array(
221b21b4
AH
240 'access CiviMail' => array(
241 ts('access CiviMail'),
242 ),
243 'access CiviMail subscribe/unsubscribe pages' => array(
244 ts('access CiviMail subscribe/unsubscribe pages'),
245 ts('Subscribe/unsubscribe from mailing list group'),
246 ),
247 'delete in CiviMail' => array(
248 ts('delete in CiviMail'),
249 ts('Delete Mailing'),
250 ),
251 'view public CiviMail content' => array(
252 ts('view public CiviMail content'),
253 ),
6a488035
TO
254 );
255
33777e4a 256 if (self::workflowEnabled() || $getAllUnconditionally) {
de4bf197
TO
257 $permissions['create mailings'] = array(
258 ts('create mailings'),
221b21b4 259 );
de4bf197
TO
260 $permissions['schedule mailings'] = array(
261 ts('schedule mailings'),
221b21b4 262 );
de4bf197
TO
263 $permissions['approve mailings'] = array(
264 ts('approve mailings'),
221b21b4
AH
265 );
266 }
267
268 if (!$descriptions) {
269 foreach ($permissions as $name => $attr) {
270 $permissions[$name] = array_shift($attr);
271 }
6a488035
TO
272 }
273
274 return $permissions;
275 }
276
277
e0ef6999 278 /**
e7c15cb6 279 * @inheritDoc
e0ef6999
EM
280 * @return null
281 */
6a488035
TO
282 public function getUserDashboardElement() {
283 // no dashboard element for this component
284 return NULL;
285 }
286
e0ef6999
EM
287 /**
288 * @return null
289 */
6a488035
TO
290 public function getUserDashboardObject() {
291 // no dashboard element for this component
292 return NULL;
293 }
294
e0ef6999 295 /**
e7c15cb6 296 * @inheritDoc
e0ef6999
EM
297 * @return array
298 */
6a488035 299 public function registerTab() {
2ede60ec
DL
300 return array(
301 'title' => ts('Mailings'),
302 'id' => 'mailing',
303 'url' => 'mailing',
304 'weight' => 45,
305 );
6a488035
TO
306 }
307
e0ef6999 308 /**
e7c15cb6 309 * @inheritDoc
e0ef6999
EM
310 * @return array
311 */
6a488035 312 public function registerAdvancedSearchPane() {
35f7561f 313 return array(
353ffa53 314 'title' => ts('Mailings'),
6a488035
TO
315 'weight' => 20,
316 );
317 }
318
e0ef6999 319 /**
e7c15cb6 320 * @inheritDoc
e0ef6999
EM
321 * @return null
322 */
6a488035
TO
323 public function getActivityTypes() {
324 return NULL;
325 }
326
e0ef6999 327 /**
fe482240 328 * add shortcut to Create New.
e0ef6999
EM
329 * @param $shortCuts
330 */
35f7561f
TO
331 public function creatNewShortcut(&$shortCuts) {
332 }
96025800 333
6a488035 334}