Merge pull request #10225 from civicrm/4.7.19-rc
[civicrm-core.git] / CRM / Mailing / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 +--------------------------------------------------------------------+
26 */
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
34 * @copyright CiviCRM LLC (c) 2004-2017
35 */
36 class CRM_Mailing_Info extends CRM_Core_Component_Info {
37
38 /**
39 * @inheritDoc
40 */
41 protected $keyword = 'mailing';
42
43
44 /**
45 * @inheritDoc
46 * @return array
47 */
48 public function getInfo() {
49 return array(
50 'name' => 'CiviMail',
51 'translatedName' => ts('CiviMail'),
52 'title' => ts('CiviCRM Mailing Engine'),
53 'search' => 1,
54 'showActivitiesInCore' => 1,
55 );
56 }
57
58 /**
59 * Get AngularJS modules and their dependencies.
60 *
61 * @return array
62 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
63 * @see CRM_Utils_Hook::angularModules
64 */
65 public function getAngularModules() {
66 // load angular files only if valid permissions are granted to the user
67 if (!CRM_Core_Permission::check('access CiviMail')
68 && !CRM_Core_Permission::check('create mailings')
69 && !CRM_Core_Permission::check('schedule mailings')
70 && !CRM_Core_Permission::check('approve mailings')
71 ) {
72 return array();
73 }
74
75 $reportIds = array();
76 $reportTypes = array('detail', 'opened', 'bounce', 'clicks');
77 foreach ($reportTypes as $report) {
78 $result = civicrm_api3('ReportInstance', 'get', array(
79 'sequential' => 1,
80 'report_id' => 'mailing/' . $report));
81 $reportIds[$report] = $result['values'][0]['id'];
82 }
83 $result = array();
84 $result['crmMailing'] = array(
85 'ext' => 'civicrm',
86 'js' => array(
87 'ang/crmMailing.js',
88 'ang/crmMailing/*.js',
89 ),
90 'css' => array('ang/crmMailing.css'),
91 'partials' => array('ang/crmMailing'),
92 );
93 $result['crmMailingAB'] = array(
94 'ext' => 'civicrm',
95 'js' => array(
96 'ang/crmMailingAB.js',
97 'ang/crmMailingAB/*.js',
98 'ang/crmMailingAB/*/*.js',
99 ),
100 'css' => array('ang/crmMailingAB.css'),
101 'partials' => array('ang/crmMailingAB'),
102 );
103 $result['crmD3'] = array(
104 'ext' => 'civicrm',
105 'js' => array(
106 'ang/crmD3.js',
107 'bower_components/d3/d3.min.js',
108 ),
109 );
110
111 $config = CRM_Core_Config::singleton();
112 $session = CRM_Core_Session::singleton();
113 $contactID = $session->get('userID');
114
115 // Get past mailings.
116 // CRM-16155 - Limit to a reasonable number.
117 $civiMails = civicrm_api3('Mailing', 'get', array(
118 'is_completed' => 1,
119 'mailing_type' => array('IN' => array('standalone', 'winner')),
120 'domain_id' => CRM_Core_Config::domainID(),
121 'return' => array('id', 'name', 'scheduled_date'),
122 'sequential' => 1,
123 'options' => array(
124 'limit' => 500,
125 'sort' => 'is_archived asc, scheduled_date desc',
126 ),
127 ));
128 // Generic params.
129 $params = array(
130 'options' => array('limit' => 0),
131 'sequential' => 1,
132 );
133
134 $groupNames = civicrm_api3('Group', 'get', $params + array(
135 'is_active' => 1,
136 'check_permissions' => TRUE,
137 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
138 ));
139 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
140 'is_active' => 1,
141 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
142 ));
143
144 $emailAdd = civicrm_api3('Email', 'get', array(
145 'sequential' => 1,
146 'return' => "email",
147 'contact_id' => $contactID,
148 ));
149
150 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
151 'sequential' => 1,
152 'is_active' => 1,
153 'return' => array("id", "msg_title"),
154 'workflow_id' => array('IS NULL' => ""),
155 ));
156 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
157 'entity' => array('contact', 'mailing'),
158 'sequential' => 1,
159 ));
160 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
161 'option_group_id' => "from_email_address",
162 'domain_id' => CRM_Core_Config::domainID(),
163 ));
164 $enabledLanguages = CRM_Core_I18n::languages(TRUE);
165 $isMultiLingual = (count($enabledLanguages) > 1);
166 CRM_Core_Resources::singleton()
167 ->addSetting(array(
168 'crmMailing' => array(
169 'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(),
170 'civiMails' => $civiMails['values'],
171 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
172 'groupNames' => $groupNames['values'],
173 'headerfooterList' => $headerfooterList['values'],
174 'mesTemplate' => $mesTemplate['values'],
175 'emailAdd' => $emailAdd['values'],
176 'mailTokens' => $mailTokens['values'],
177 'contactid' => $contactID,
178 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
179 'enableReplyTo' => (int) Civi::settings()->get('replyTo'),
180 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'),
181 'fromAddress' => $fromAddress['values'],
182 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
183 'id' => 'user_contact_id',
184 'return' => 'email',
185 )),
186 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
187 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
188 'reportIds' => $reportIds,
189 'enabledLanguages' => $enabledLanguages,
190 'isMultiLingual' => $isMultiLingual,
191 ),
192 ))
193 ->addPermissions(array(
194 'view all contacts',
195 'edit all contacts',
196 'access CiviMail',
197 'create mailings',
198 'schedule mailings',
199 'approve mailings',
200 'delete in CiviMail',
201 'edit message templates',
202 ));
203
204 return $result;
205 }
206
207 /**
208 * @return bool
209 */
210 public static function workflowEnabled() {
211 $config = CRM_Core_Config::singleton();
212
213 // early exit, since not true for most
214 if (!$config->userSystem->is_drupal ||
215 !function_exists('module_exists')
216 ) {
217 return FALSE;
218 }
219
220 if (!module_exists('rules')) {
221 return FALSE;
222 }
223
224 $enableWorkflow = Civi::settings()->get('civimail_workflow');
225
226 return ($enableWorkflow &&
227 $config->userSystem->is_drupal
228 ) ? TRUE : FALSE;
229 }
230
231 /**
232 * @inheritDoc
233 * @param bool $getAllUnconditionally
234 * @param bool $descriptions
235 * Whether to return permission descriptions
236 *
237 * @return array
238 */
239 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
240 $permissions = array(
241 'access CiviMail' => array(
242 ts('access CiviMail'),
243 ),
244 'access CiviMail subscribe/unsubscribe pages' => array(
245 ts('access CiviMail subscribe/unsubscribe pages'),
246 ts('Subscribe/unsubscribe from mailing list group'),
247 ),
248 'delete in CiviMail' => array(
249 ts('delete in CiviMail'),
250 ts('Delete Mailing'),
251 ),
252 'view public CiviMail content' => array(
253 ts('view public CiviMail content'),
254 ),
255 );
256
257 if (self::workflowEnabled() || $getAllUnconditionally) {
258 $permissions['create mailings'] = array(
259 ts('create mailings'),
260 );
261 $permissions['schedule mailings'] = array(
262 ts('schedule mailings'),
263 );
264 $permissions['approve mailings'] = array(
265 ts('approve mailings'),
266 );
267 }
268
269 if (!$descriptions) {
270 foreach ($permissions as $name => $attr) {
271 $permissions[$name] = array_shift($attr);
272 }
273 }
274
275 return $permissions;
276 }
277
278
279 /**
280 * @inheritDoc
281 * @return null
282 */
283 public function getUserDashboardElement() {
284 // no dashboard element for this component
285 return NULL;
286 }
287
288 /**
289 * @return null
290 */
291 public function getUserDashboardObject() {
292 // no dashboard element for this component
293 return NULL;
294 }
295
296 /**
297 * @inheritDoc
298 * @return array
299 */
300 public function registerTab() {
301 return array(
302 'title' => ts('Mailings'),
303 'id' => 'mailing',
304 'url' => 'mailing',
305 'weight' => 45,
306 );
307 }
308
309 /**
310 * @inheritDoc
311 * @return array
312 */
313 public function registerAdvancedSearchPane() {
314 return array(
315 'title' => ts('Mailings'),
316 'weight' => 20,
317 );
318 }
319
320 /**
321 * @inheritDoc
322 * @return null
323 */
324 public function getActivityTypes() {
325 return NULL;
326 }
327
328 /**
329 * add shortcut to Create New.
330 * @param $shortCuts
331 */
332 public function creatNewShortcut(&$shortCuts) {
333 }
334
335 }