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