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