Merge pull request #10686 from totten/master-sql
[civicrm-core.git] / CRM / Mailing / Info.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
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
0f03f337 34 * @copyright CiviCRM LLC (c) 2004-2017
6a488035
TO
35 */
36class CRM_Mailing_Info extends CRM_Core_Component_Info {
37
e7c15cb6
CW
38 /**
39 * @inheritDoc
40 */
6a488035
TO
41 protected $keyword = 'mailing';
42
43
e0ef6999 44 /**
e7c15cb6 45 * @inheritDoc
e0ef6999
EM
46 * @return array
47 */
6a488035
TO
48 public function getInfo() {
49 return array(
50 'name' => 'CiviMail',
51 'translatedName' => ts('CiviMail'),
e300cf31 52 'title' => ts('CiviCRM Mailing Engine'),
6a488035
TO
53 'search' => 1,
54 'showActivitiesInCore' => 1,
55 );
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
KJ
71 ) {
72 return array();
73 }
8456e727 74 global $civicrm_root;
56621a6c 75
78414681
SL
76 $reportIds = array();
77 $reportTypes = array('detail', 'opened', 'bounce', 'clicks');
78 foreach ($reportTypes as $report) {
79 $result = civicrm_api3('ReportInstance', 'get', array(
80 'sequential' => 1,
81 'report_id' => 'mailing/' . $report));
82 $reportIds[$report] = $result['values'][0]['id'];
83 }
4aef704e 84 $result = array();
8456e727
TO
85 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
86 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
87 $result['crmD3'] = include "$civicrm_root/ang/crmD3.ang.php";
983052fe 88
8099bfee 89 $config = CRM_Core_Config::singleton();
6bea4a47
TO
90 $session = CRM_Core_Session::singleton();
91 $contactID = $session->get('userID');
d979898e 92
25606795
SB
93 // Get past mailings.
94 // CRM-16155 - Limit to a reasonable number.
51527a6e 95 $civiMails = civicrm_api3('Mailing', 'get', array(
72dd949e 96 'is_completed' => 1,
51527a6e 97 'mailing_type' => array('IN' => array('standalone', 'winner')),
b4a37a31 98 'domain_id' => CRM_Core_Config::domainID(),
72dd949e 99 'return' => array('id', 'name', 'scheduled_date'),
51527a6e
CW
100 'sequential' => 1,
101 'options' => array(
102 'limit' => 500,
103 'sort' => 'is_archived asc, scheduled_date desc',
8099bfee 104 ),
51527a6e 105 ));
25606795 106 // Generic params.
a0f40af4
CW
107 $params = array(
108 'options' => array('limit' => 0),
109 'sequential' => 1,
110 );
8099bfee 111
a0f40af4
CW
112 $groupNames = civicrm_api3('Group', 'get', $params + array(
113 'is_active' => 1,
e7d6f8f8 114 'check_permissions' => TRUE,
a0f40af4
CW
115 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
116 ));
117 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
118 'is_active' => 1,
0499685e 119 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
72dd949e 120 ));
6bea4a47 121
44a7c67d
TO
122 $emailAdd = civicrm_api3('Email', 'get', array(
123 'sequential' => 1,
124 'return' => "email",
125 'contact_id' => $contactID,
126 ));
a0f40af4 127
d979898e 128 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
44a7c67d 129 'sequential' => 1,
a0f40af4 130 'is_active' => 1,
3637550f 131 'return' => array("id", "msg_title"),
44a7c67d
TO
132 'workflow_id' => array('IS NULL' => ""),
133 ));
a0f40af4
CW
134 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
135 'entity' => array('contact', 'mailing'),
8099bfee 136 'sequential' => 1,
a0f40af4 137 ));
d979898e
CW
138 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
139 'option_group_id' => "from_email_address",
84deca8b 140 'domain_id' => CRM_Core_Config::domainID(),
4aef704e 141 ));
c00b95ef
ML
142 $enabledLanguages = CRM_Core_I18n::languages(TRUE);
143 $isMultiLingual = (count($enabledLanguages) > 1);
a0f40af4
CW
144 CRM_Core_Resources::singleton()
145 ->addSetting(array(
146 'crmMailing' => array(
703875d8 147 'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(),
a0f40af4 148 'civiMails' => $civiMails['values'],
8099bfee 149 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
a0f40af4
CW
150 'groupNames' => $groupNames['values'],
151 'headerfooterList' => $headerfooterList['values'],
152 'mesTemplate' => $mesTemplate['values'],
153 'emailAdd' => $emailAdd['values'],
a0f40af4
CW
154 'mailTokens' => $mailTokens['values'],
155 'contactid' => $contactID,
156 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
aaffa79f 157 'enableReplyTo' => (int) Civi::settings()->get('replyTo'),
158 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'),
a0f40af4
CW
159 'fromAddress' => $fromAddress['values'],
160 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
161 'id' => 'user_contact_id',
162 'return' => 'email',
163 )),
164 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
165 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
78414681 166 'reportIds' => $reportIds,
c00b95ef
ML
167 'enabledLanguages' => $enabledLanguages,
168 'isMultiLingual' => $isMultiLingual,
a0f40af4
CW
169 ),
170 ))
171 ->addPermissions(array(
172 'view all contacts',
84fd40f3 173 'edit all contacts',
a0f40af4
CW
174 'access CiviMail',
175 'create mailings',
176 'schedule mailings',
177 'approve mailings',
178 'delete in CiviMail',
867299da 179 'edit message templates',
a0f40af4 180 ));
983052fe 181
4aef704e 182 return $result;
183 }
983052fe 184
4aef704e 185 /**
e0ef6999
EM
186 * @return bool
187 */
00be9182 188 public static function workflowEnabled() {
6a488035
TO
189 $config = CRM_Core_Config::singleton();
190
191 // early exit, since not true for most
192 if (!$config->userSystem->is_drupal ||
193 !function_exists('module_exists')
194 ) {
195 return FALSE;
196 }
197
198 if (!module_exists('rules')) {
199 return FALSE;
200 }
201
aaffa79f 202 $enableWorkflow = Civi::settings()->get('civimail_workflow');
6a488035
TO
203
204 return ($enableWorkflow &&
205 $config->userSystem->is_drupal
206 ) ? TRUE : FALSE;
207 }
208
e0ef6999 209 /**
e7c15cb6 210 * @inheritDoc
e0ef6999 211 * @param bool $getAllUnconditionally
221b21b4
AH
212 * @param bool $descriptions
213 * Whether to return permission descriptions
e0ef6999
EM
214 *
215 * @return array
216 */
221b21b4 217 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
6a488035 218 $permissions = array(
221b21b4
AH
219 'access CiviMail' => array(
220 ts('access CiviMail'),
221 ),
222 'access CiviMail subscribe/unsubscribe pages' => array(
223 ts('access CiviMail subscribe/unsubscribe pages'),
224 ts('Subscribe/unsubscribe from mailing list group'),
225 ),
226 'delete in CiviMail' => array(
227 ts('delete in CiviMail'),
228 ts('Delete Mailing'),
229 ),
230 'view public CiviMail content' => array(
231 ts('view public CiviMail content'),
232 ),
6a488035
TO
233 );
234
33777e4a 235 if (self::workflowEnabled() || $getAllUnconditionally) {
de4bf197
TO
236 $permissions['create mailings'] = array(
237 ts('create mailings'),
221b21b4 238 );
de4bf197
TO
239 $permissions['schedule mailings'] = array(
240 ts('schedule mailings'),
221b21b4 241 );
de4bf197
TO
242 $permissions['approve mailings'] = array(
243 ts('approve mailings'),
221b21b4
AH
244 );
245 }
246
247 if (!$descriptions) {
248 foreach ($permissions as $name => $attr) {
249 $permissions[$name] = array_shift($attr);
250 }
6a488035
TO
251 }
252
253 return $permissions;
254 }
255
256
e0ef6999 257 /**
e7c15cb6 258 * @inheritDoc
e0ef6999
EM
259 * @return null
260 */
6a488035
TO
261 public function getUserDashboardElement() {
262 // no dashboard element for this component
263 return NULL;
264 }
265
e0ef6999
EM
266 /**
267 * @return null
268 */
6a488035
TO
269 public function getUserDashboardObject() {
270 // no dashboard element for this component
271 return NULL;
272 }
273
e0ef6999 274 /**
e7c15cb6 275 * @inheritDoc
e0ef6999
EM
276 * @return array
277 */
6a488035 278 public function registerTab() {
2ede60ec
DL
279 return array(
280 'title' => ts('Mailings'),
281 'id' => 'mailing',
282 'url' => 'mailing',
283 'weight' => 45,
284 );
6a488035
TO
285 }
286
e0ef6999 287 /**
e7c15cb6 288 * @inheritDoc
e0ef6999
EM
289 * @return array
290 */
6a488035 291 public function registerAdvancedSearchPane() {
35f7561f 292 return array(
353ffa53 293 'title' => ts('Mailings'),
6a488035
TO
294 'weight' => 20,
295 );
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}