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