Merge pull request #22941 from sunilpawar/batch_copy_radio_clear_value
[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 * @return array
30 */
31 public static function createAngularSettings():array {
32 $reportIds = [];
33 $reportTypes = ['detail', 'opened', 'bounce', 'clicks'];
34 foreach ($reportTypes as $report) {
35 $rptResult = civicrm_api3('ReportInstance', 'get', [
36 'sequential' => 1,
37 'report_id' => 'mailing/' . $report,
38 ]);
39 if (!empty($rptResult['values'])) {
40 $reportIds[$report] = $rptResult['values'][0]['id'];
41 }
42 }
43
44 $session = CRM_Core_Session::singleton();
45 $contactID = $session->get('userID');
46
47 // Generic params.
48 $params = [
49 'options' => ['limit' => 0],
50 'sequential' => 1,
51 ];
52 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + [
53 'is_active' => 1,
54 'return' => [
55 'name',
56 'component_type',
57 'is_default',
58 'body_html',
59 'body_text',
60 ],
61 ]);
62
63 $emailAdd = civicrm_api3('Email', 'get', [
64 'sequential' => 1,
65 'return' => 'email',
66 'contact_id' => $contactID,
67 ]);
68
69 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + [
70 'sequential' => 1,
71 'is_active' => 1,
72 'return' => ['id', 'msg_title'],
73 'workflow_name' => ['IS NULL' => ''],
74 ]);
75 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
76 'entity' => ['contact', 'mailing'],
77 'sequential' => 1,
78 ]);
79 $fromAddress = civicrm_api3('OptionValue', 'get', $params + [
80 'option_group_id' => "from_email_address",
81 'domain_id' => CRM_Core_Config::domainID(),
82 ]);
83 $enabledLanguages = CRM_Core_I18n::languages(TRUE);
84 $isMultiLingual = (count($enabledLanguages) > 1);
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.
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' => [],
92 'campaignEnabled' => CRM_Core_Component::isEnabled('CiviCampaign'),
93 'groupNames' => [],
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 ];
114 return $crmMailingSettings;
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";
152
153 return $result;
154 }
155
156 /**
157 * @return bool
158 */
159 public static function workflowEnabled() {
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
173 $enableWorkflow = Civi::settings()->get('civimail_workflow');
174
175 return $enableWorkflow && $config->userSystem->is_drupal;
176 }
177
178 /**
179 * @inheritDoc
180 * @param bool $getAllUnconditionally
181 * @param bool $descriptions
182 * Whether to return permission descriptions
183 *
184 * @return array
185 */
186 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
187 $permissions = [
188 'access CiviMail' => [
189 ts('access CiviMail'),
190 ],
191 'access CiviMail subscribe/unsubscribe pages' => [
192 ts('access CiviMail subscribe/unsubscribe pages'),
193 ts('Subscribe/unsubscribe from mailing list group'),
194 ],
195 'delete in CiviMail' => [
196 ts('delete in CiviMail'),
197 ts('Delete Mailing'),
198 ],
199 'view public CiviMail content' => [
200 ts('view public CiviMail content'),
201 ],
202 ];
203
204 if (self::workflowEnabled() || $getAllUnconditionally) {
205 $permissions['create mailings'] = [
206 ts('create mailings'),
207 ];
208 $permissions['schedule mailings'] = [
209 ts('schedule mailings'),
210 ];
211 $permissions['approve mailings'] = [
212 ts('approve mailings'),
213 ];
214 }
215
216 if (!$descriptions) {
217 foreach ($permissions as $name => $attr) {
218 $permissions[$name] = array_shift($attr);
219 }
220 }
221
222 return $permissions;
223 }
224
225 /**
226 * @inheritDoc
227 * @return null
228 */
229 public function getUserDashboardElement() {
230 // no dashboard element for this component
231 return NULL;
232 }
233
234 /**
235 * @return null
236 */
237 public function getUserDashboardObject() {
238 // no dashboard element for this component
239 return NULL;
240 }
241
242 /**
243 * @inheritDoc
244 * @return array
245 */
246 public function registerTab() {
247 return [
248 'title' => ts('Mailings'),
249 'id' => 'mailing',
250 'url' => 'mailing',
251 'weight' => 45,
252 ];
253 }
254
255 /**
256 * @inheritDoc
257 * @return string
258 */
259 public function getIcon() {
260 return 'crm-i fa-envelope-o';
261 }
262
263 /**
264 * @inheritDoc
265 * @return array
266 */
267 public function registerAdvancedSearchPane() {
268 return [
269 'title' => ts('Mailings'),
270 'weight' => 20,
271 ];
272 }
273
274 /**
275 * @inheritDoc
276 * @return null
277 */
278 public function getActivityTypes() {
279 return NULL;
280 }
281
282 /**
283 * add shortcut to Create New.
284 * @param $shortCuts
285 */
286 public function creatNewShortcut(&$shortCuts) {
287 }
288
289 }