Merge pull request #12285 from eileenmcnaughton/master
[civicrm-core.git] / CRM / Mailing / Info.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
8c9251b3 34 * @copyright CiviCRM LLC (c) 2004-2018
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'),
e300cf31 52 'title' => ts('CiviCRM Mailing Engine'),
6a488035
TO
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 }
8456e727 74 global $civicrm_root;
56621a6c 75
78414681
SL
76 $reportIds = array();
77 $reportTypes = array('detail', 'opened', 'bounce', 'clicks');
78 foreach ($reportTypes as $report) {
79 $result = civicrm_api3('ReportInstance', 'get', array(
80 'sequential' => 1,
81 'report_id' => 'mailing/' . $report));
56e3a6f6 82 if (!empty($result['values'])) {
83 $reportIds[$report] = $result['values'][0]['id'];
84 }
78414681 85 }
4aef704e 86 $result = array();
8456e727
TO
87 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
88 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
89 $result['crmD3'] = include "$civicrm_root/ang/crmD3.ang.php";
983052fe 90
8099bfee 91 $config = CRM_Core_Config::singleton();
6bea4a47
TO
92 $session = CRM_Core_Session::singleton();
93 $contactID = $session->get('userID');
d979898e 94
25606795 95 // Generic params.
a0f40af4
CW
96 $params = array(
97 'options' => array('limit' => 0),
98 'sequential' => 1,
99 );
31815c2b
SL
100 $groupNames = civicrm_api3('Group', 'get', $params + array(
101 'is_active' => 1,
102 'check_permissions' => TRUE,
103 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
104 ));
a0f40af4
CW
105 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
106 'is_active' => 1,
0499685e 107 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
72dd949e 108 ));
6bea4a47 109
44a7c67d
TO
110 $emailAdd = civicrm_api3('Email', 'get', array(
111 'sequential' => 1,
112 'return' => "email",
113 'contact_id' => $contactID,
114 ));
a0f40af4 115
d979898e 116 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
44a7c67d 117 'sequential' => 1,
a0f40af4 118 'is_active' => 1,
3637550f 119 'return' => array("id", "msg_title"),
44a7c67d
TO
120 'workflow_id' => array('IS NULL' => ""),
121 ));
a0f40af4
CW
122 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
123 'entity' => array('contact', 'mailing'),
8099bfee 124 'sequential' => 1,
a0f40af4 125 ));
d979898e
CW
126 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
127 'option_group_id' => "from_email_address",
84deca8b 128 'domain_id' => CRM_Core_Config::domainID(),
4aef704e 129 ));
c00b95ef
ML
130 $enabledLanguages = CRM_Core_I18n::languages(TRUE);
131 $isMultiLingual = (count($enabledLanguages) > 1);
b845ba46 132 // FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
2d7b8444 133 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS, array()) : CRM_Utils_Token::getRequiredTokens();
a0f40af4
CW
134 CRM_Core_Resources::singleton()
135 ->addSetting(array(
136 'crmMailing' => array(
703875d8 137 'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(),
836bf6b7 138 'civiMails' => array(),
8099bfee 139 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
836bf6b7 140 'groupNames' => array(),
d1aefa39 141 // @todo this is not used in core. Remove once Mosaico no longer depends on it.
31815c2b 142 'testGroupNames' => $groupNames['values'],
a0f40af4
CW
143 'headerfooterList' => $headerfooterList['values'],
144 'mesTemplate' => $mesTemplate['values'],
145 'emailAdd' => $emailAdd['values'],
a0f40af4
CW
146 'mailTokens' => $mailTokens['values'],
147 'contactid' => $contactID,
2d7b8444 148 'requiredTokens' => $requiredTokens,
aaffa79f 149 'enableReplyTo' => (int) Civi::settings()->get('replyTo'),
150 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'),
a0f40af4
CW
151 'fromAddress' => $fromAddress['values'],
152 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
153 'id' => 'user_contact_id',
154 'return' => 'email',
155 )),
156 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
157 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
78414681 158 'reportIds' => $reportIds,
c00b95ef
ML
159 'enabledLanguages' => $enabledLanguages,
160 'isMultiLingual' => $isMultiLingual,
a0f40af4
CW
161 ),
162 ))
163 ->addPermissions(array(
164 'view all contacts',
84fd40f3 165 'edit all contacts',
a0f40af4
CW
166 'access CiviMail',
167 'create mailings',
168 'schedule mailings',
169 'approve mailings',
170 'delete in CiviMail',
867299da 171 'edit message templates',
a0f40af4 172 ));
983052fe 173
4aef704e 174 return $result;
175 }
983052fe 176
4aef704e 177 /**
e0ef6999
EM
178 * @return bool
179 */
00be9182 180 public static function workflowEnabled() {
6a488035
TO
181 $config = CRM_Core_Config::singleton();
182
183 // early exit, since not true for most
184 if (!$config->userSystem->is_drupal ||
185 !function_exists('module_exists')
186 ) {
187 return FALSE;
188 }
189
190 if (!module_exists('rules')) {
191 return FALSE;
192 }
193
aaffa79f 194 $enableWorkflow = Civi::settings()->get('civimail_workflow');
6a488035
TO
195
196 return ($enableWorkflow &&
197 $config->userSystem->is_drupal
198 ) ? TRUE : FALSE;
199 }
200
e0ef6999 201 /**
e7c15cb6 202 * @inheritDoc
e0ef6999 203 * @param bool $getAllUnconditionally
221b21b4
AH
204 * @param bool $descriptions
205 * Whether to return permission descriptions
e0ef6999
EM
206 *
207 * @return array
208 */
221b21b4 209 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
6a488035 210 $permissions = array(
221b21b4
AH
211 'access CiviMail' => array(
212 ts('access CiviMail'),
213 ),
214 'access CiviMail subscribe/unsubscribe pages' => array(
215 ts('access CiviMail subscribe/unsubscribe pages'),
216 ts('Subscribe/unsubscribe from mailing list group'),
217 ),
218 'delete in CiviMail' => array(
219 ts('delete in CiviMail'),
220 ts('Delete Mailing'),
221 ),
222 'view public CiviMail content' => array(
223 ts('view public CiviMail content'),
224 ),
6a488035
TO
225 );
226
33777e4a 227 if (self::workflowEnabled() || $getAllUnconditionally) {
de4bf197
TO
228 $permissions['create mailings'] = array(
229 ts('create mailings'),
221b21b4 230 );
de4bf197
TO
231 $permissions['schedule mailings'] = array(
232 ts('schedule mailings'),
221b21b4 233 );
de4bf197
TO
234 $permissions['approve mailings'] = array(
235 ts('approve mailings'),
221b21b4
AH
236 );
237 }
238
239 if (!$descriptions) {
240 foreach ($permissions as $name => $attr) {
241 $permissions[$name] = array_shift($attr);
242 }
6a488035
TO
243 }
244
245 return $permissions;
246 }
247
248
e0ef6999 249 /**
e7c15cb6 250 * @inheritDoc
e0ef6999
EM
251 * @return null
252 */
6a488035
TO
253 public function getUserDashboardElement() {
254 // no dashboard element for this component
255 return NULL;
256 }
257
e0ef6999
EM
258 /**
259 * @return null
260 */
6a488035
TO
261 public function getUserDashboardObject() {
262 // no dashboard element for this component
263 return NULL;
264 }
265
e0ef6999 266 /**
e7c15cb6 267 * @inheritDoc
e0ef6999
EM
268 * @return array
269 */
6a488035 270 public function registerTab() {
2ede60ec
DL
271 return array(
272 'title' => ts('Mailings'),
273 'id' => 'mailing',
274 'url' => 'mailing',
275 'weight' => 45,
276 );
6a488035
TO
277 }
278
e0ef6999 279 /**
e7c15cb6 280 * @inheritDoc
e0ef6999
EM
281 * @return array
282 */
6a488035 283 public function registerAdvancedSearchPane() {
35f7561f 284 return array(
353ffa53 285 'title' => ts('Mailings'),
6a488035
TO
286 'weight' => 20,
287 );
288 }
289
e0ef6999 290 /**
e7c15cb6 291 * @inheritDoc
e0ef6999
EM
292 * @return null
293 */
6a488035
TO
294 public function getActivityTypes() {
295 return NULL;
296 }
297
e0ef6999 298 /**
fe482240 299 * add shortcut to Create New.
e0ef6999
EM
300 * @param $shortCuts
301 */
35f7561f
TO
302 public function creatNewShortcut(&$shortCuts) {
303 }
96025800 304
6a488035 305}