Merge pull request #23742 from eileenmcnaughton/import_remove
[civicrm-core.git] / CRM / Mailing / Info.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 * This class introduces component to the system and provides all the
14 * information about it. It needs to extend CRM_Core_Component_Info
15 * abstract class.
16 *
17 * @package CRM
ca5cec67 18 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
19 */
20class CRM_Mailing_Info extends CRM_Core_Component_Info {
21
e7c15cb6 22 /**
7e8c8317 23 * @var string
e7c15cb6
CW
24 * @inheritDoc
25 */
6a488035
TO
26 protected $keyword = 'mailing';
27
e0ef6999
EM
28 /**
29 * @return array
30 */
522c72dd 31 public static function createAngularSettings():array {
be2fb01f
CW
32 $reportIds = [];
33 $reportTypes = ['detail', 'opened', 'bounce', 'clicks'];
78414681 34 foreach ($reportTypes as $report) {
522c72dd 35 $rptResult = civicrm_api3('ReportInstance', 'get', [
78414681 36 'sequential' => 1,
7e8c8317
SL
37 'report_id' => 'mailing/' . $report,
38 ]);
522c72dd
TO
39 if (!empty($rptResult['values'])) {
40 $reportIds[$report] = $rptResult['values'][0]['id'];
56e3a6f6 41 }
78414681 42 }
983052fe 43
6bea4a47
TO
44 $session = CRM_Core_Session::singleton();
45 $contactID = $session->get('userID');
d979898e 46
25606795 47 // Generic params.
be2fb01f
CW
48 $params = [
49 'options' => ['limit' => 0],
a0f40af4 50 'sequential' => 1,
be2fb01f 51 ];
be2fb01f 52 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + [
a0f40af4 53 'is_active' => 1,
522c72dd
TO
54 'return' => [
55 'name',
56 'component_type',
57 'is_default',
58 'body_html',
59 'body_text',
60 ],
be2fb01f 61 ]);
6bea4a47 62
be2fb01f 63 $emailAdd = civicrm_api3('Email', 'get', [
44a7c67d 64 'sequential' => 1,
31340b59 65 'return' => 'email',
44a7c67d 66 'contact_id' => $contactID,
be2fb01f 67 ]);
a0f40af4 68
be2fb01f 69 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + [
44a7c67d 70 'sequential' => 1,
a0f40af4 71 'is_active' => 1,
31340b59
EM
72 'return' => ['id', 'msg_title'],
73 'workflow_name' => ['IS NULL' => ''],
be2fb01f
CW
74 ]);
75 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
76 'entity' => ['contact', 'mailing'],
8099bfee 77 'sequential' => 1,
be2fb01f
CW
78 ]);
79 $fromAddress = civicrm_api3('OptionValue', 'get', $params + [
d979898e 80 'option_group_id' => "from_email_address",
84deca8b 81 'domain_id' => CRM_Core_Config::domainID(),
be2fb01f 82 ]);
c00b95ef
ML
83 $enabledLanguages = CRM_Core_I18n::languages(TRUE);
84 $isMultiLingual = (count($enabledLanguages) > 1);
b845ba46 85 // 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.
522c72dd
TO
86 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver::singleton()
87 ->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS,
88 []) : CRM_Utils_Token::getRequiredTokens();
89 $crmMailingSettings = [
90 'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(),
91 'civiMails' => [],
e46f73c7 92 'campaignEnabled' => CRM_Core_Component::isEnabled('CiviCampaign'),
522c72dd 93 'groupNames' => [],
522c72dd
TO
94 'headerfooterList' => $headerfooterList['values'],
95 'mesTemplate' => $mesTemplate['values'],
96 'emailAdd' => $emailAdd['values'],
97 'mailTokens' => $mailTokens['values'],
98 'contactid' => $contactID,
99 'requiredTokens' => $requiredTokens,
100 'enableReplyTo' => (int) Civi::settings()->get('replyTo'),
101 'disableMandatoryTokensCheck' => (int) Civi::settings()
102 ->get('disable_mandatory_tokens_check'),
103 'fromAddress' => $fromAddress['values'],
104 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [
105 'id' => 'user_contact_id',
106 'return' => 'email',
107 ]),
108 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
109 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
110 'reportIds' => $reportIds,
111 'enabledLanguages' => $enabledLanguages,
112 'isMultiLingual' => $isMultiLingual,
113 ];
0022fd1b 114 return $crmMailingSettings;
522c72dd
TO
115 }
116
117 /**
118 * @inheritDoc
119 * @return array
120 */
121 public function getInfo() {
122 return [
123 'name' => 'CiviMail',
124 'translatedName' => ts('CiviMail'),
125 'title' => ts('CiviCRM Mailing Engine'),
126 'search' => 1,
127 'showActivitiesInCore' => 1,
128 ];
129 }
130
131 /**
132 * Get AngularJS modules and their dependencies.
133 *
134 * @return array
135 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
136 * @see CRM_Utils_Hook::angularModules
137 */
138 public function getAngularModules() {
139 // load angular files only if valid permissions are granted to the user
140 if (!CRM_Core_Permission::check('access CiviMail')
141 && !CRM_Core_Permission::check('create mailings')
142 && !CRM_Core_Permission::check('schedule mailings')
143 && !CRM_Core_Permission::check('approve mailings')
144 ) {
145 return [];
146 }
147 global $civicrm_root;
148
149 $result = [];
150 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
151 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
522c72dd 152
4aef704e 153 return $result;
154 }
983052fe 155
4aef704e 156 /**
e0ef6999
EM
157 * @return bool
158 */
00be9182 159 public static function workflowEnabled() {
6a488035
TO
160 $config = CRM_Core_Config::singleton();
161
162 // early exit, since not true for most
163 if (!$config->userSystem->is_drupal ||
164 !function_exists('module_exists')
165 ) {
166 return FALSE;
167 }
168
169 if (!module_exists('rules')) {
170 return FALSE;
171 }
172
aaffa79f 173 $enableWorkflow = Civi::settings()->get('civimail_workflow');
6a488035 174
f7dbf5d9 175 return $enableWorkflow && $config->userSystem->is_drupal;
6a488035
TO
176 }
177
e0ef6999 178 /**
e7c15cb6 179 * @inheritDoc
e0ef6999 180 * @param bool $getAllUnconditionally
221b21b4
AH
181 * @param bool $descriptions
182 * Whether to return permission descriptions
e0ef6999
EM
183 *
184 * @return array
185 */
221b21b4 186 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
be2fb01f
CW
187 $permissions = [
188 'access CiviMail' => [
221b21b4 189 ts('access CiviMail'),
be2fb01f
CW
190 ],
191 'access CiviMail subscribe/unsubscribe pages' => [
221b21b4
AH
192 ts('access CiviMail subscribe/unsubscribe pages'),
193 ts('Subscribe/unsubscribe from mailing list group'),
be2fb01f
CW
194 ],
195 'delete in CiviMail' => [
221b21b4
AH
196 ts('delete in CiviMail'),
197 ts('Delete Mailing'),
be2fb01f
CW
198 ],
199 'view public CiviMail content' => [
221b21b4 200 ts('view public CiviMail content'),
be2fb01f
CW
201 ],
202 ];
6a488035 203
33777e4a 204 if (self::workflowEnabled() || $getAllUnconditionally) {
be2fb01f 205 $permissions['create mailings'] = [
de4bf197 206 ts('create mailings'),
be2fb01f
CW
207 ];
208 $permissions['schedule mailings'] = [
de4bf197 209 ts('schedule mailings'),
be2fb01f
CW
210 ];
211 $permissions['approve mailings'] = [
de4bf197 212 ts('approve mailings'),
be2fb01f 213 ];
221b21b4
AH
214 }
215
216 if (!$descriptions) {
217 foreach ($permissions as $name => $attr) {
218 $permissions[$name] = array_shift($attr);
219 }
6a488035
TO
220 }
221
222 return $permissions;
223 }
224
e0ef6999 225 /**
e7c15cb6 226 * @inheritDoc
e0ef6999
EM
227 * @return null
228 */
6a488035
TO
229 public function getUserDashboardElement() {
230 // no dashboard element for this component
231 return NULL;
232 }
233
e0ef6999
EM
234 /**
235 * @return null
236 */
6a488035
TO
237 public function getUserDashboardObject() {
238 // no dashboard element for this component
239 return NULL;
240 }
241
e0ef6999 242 /**
e7c15cb6 243 * @inheritDoc
e0ef6999
EM
244 * @return array
245 */
6a488035 246 public function registerTab() {
be2fb01f 247 return [
2ede60ec
DL
248 'title' => ts('Mailings'),
249 'id' => 'mailing',
250 'url' => 'mailing',
251 'weight' => 45,
be2fb01f 252 ];
6a488035
TO
253 }
254
b04115b4
CW
255 /**
256 * @inheritDoc
257 * @return string
258 */
259 public function getIcon() {
260 return 'crm-i fa-envelope-o';
261 }
262
e0ef6999 263 /**
e7c15cb6 264 * @inheritDoc
e0ef6999
EM
265 * @return array
266 */
6a488035 267 public function registerAdvancedSearchPane() {
be2fb01f 268 return [
353ffa53 269 'title' => ts('Mailings'),
6a488035 270 'weight' => 20,
be2fb01f 271 ];
6a488035
TO
272 }
273
e0ef6999 274 /**
e7c15cb6 275 * @inheritDoc
e0ef6999
EM
276 * @return null
277 */
6a488035
TO
278 public function getActivityTypes() {
279 return NULL;
280 }
281
e0ef6999 282 /**
fe482240 283 * add shortcut to Create New.
e0ef6999
EM
284 * @param $shortCuts
285 */
35f7561f
TO
286 public function creatNewShortcut(&$shortCuts) {
287 }
96025800 288
6a488035 289}