Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-10-14-11-04-09
[civicrm-core.git] / CRM / Mailing / Info.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 34 * @copyright CiviCRM LLC (c) 2004-2015
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'),
52 'title' => 'CiviCRM Mailing Engine',
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')
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
4aef704e 75 $result = array();
88e9e883 76 $result['crmMailing'] = array(
030dce01 77 'ext' => 'civicrm',
353ffa53 78 'js' => array(
81bb7011
TO
79 'ang/crmMailing.js',
80 'ang/crmMailing/*.js',
353ffa53 81 ),
81bb7011
TO
82 'css' => array('ang/crmMailing.css'),
83 'partials' => array('ang/crmMailing'),
6bea4a47 84 );
4aef704e 85 $result['crmMailingAB'] = array(
86 'ext' => 'civicrm',
353ffa53 87 'js' => array(
679996bb
TO
88 'ang/crmMailingAB.js',
89 'ang/crmMailingAB/*.js',
90 'ang/crmMailingAB/*/*.js',
353ffa53 91 ),
e9f5761a 92 'css' => array('ang/crmMailingAB.css'),
6f54251a 93 'partials' => array('ang/crmMailingAB'),
4aef704e 94 );
d74bca86
TO
95 $result['crmD3'] = array(
96 'ext' => 'civicrm',
edb34488 97 'js' => array(
6f54251a 98 'ang/crmD3.js',
edb34488
TO
99 'bower_components/d3/d3.min.js',
100 ),
d74bca86 101 );
983052fe 102
8099bfee 103 $config = CRM_Core_Config::singleton();
6bea4a47
TO
104 $session = CRM_Core_Session::singleton();
105 $contactID = $session->get('userID');
d979898e 106
25606795
SB
107 // Get past mailings.
108 // CRM-16155 - Limit to a reasonable number.
51527a6e 109 $civiMails = civicrm_api3('Mailing', 'get', array(
72dd949e 110 'is_completed' => 1,
51527a6e 111 'mailing_type' => array('IN' => array('standalone', 'winner')),
b4a37a31 112 'domain_id' => CRM_Core_Config::domainID(),
72dd949e 113 'return' => array('id', 'name', 'scheduled_date'),
51527a6e
CW
114 'sequential' => 1,
115 'options' => array(
116 'limit' => 500,
117 'sort' => 'is_archived asc, scheduled_date desc',
8099bfee 118 ),
51527a6e 119 ));
25606795 120 // Generic params.
a0f40af4
CW
121 $params = array(
122 'options' => array('limit' => 0),
123 'sequential' => 1,
124 );
8099bfee 125
a0f40af4
CW
126 $groupNames = civicrm_api3('Group', 'get', $params + array(
127 'is_active' => 1,
e7d6f8f8 128 'check_permissions' => TRUE,
a0f40af4
CW
129 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
130 ));
131 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
132 'is_active' => 1,
0499685e 133 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
72dd949e 134 ));
6bea4a47 135
44a7c67d
TO
136 $emailAdd = civicrm_api3('Email', 'get', array(
137 'sequential' => 1,
138 'return' => "email",
139 'contact_id' => $contactID,
140 ));
a0f40af4 141
d979898e 142 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
44a7c67d 143 'sequential' => 1,
a0f40af4 144 'is_active' => 1,
3637550f 145 'return' => array("id", "msg_title"),
44a7c67d
TO
146 'workflow_id' => array('IS NULL' => ""),
147 ));
a0f40af4
CW
148 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
149 'entity' => array('contact', 'mailing'),
8099bfee 150 'sequential' => 1,
a0f40af4 151 ));
d979898e
CW
152 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
153 'option_group_id' => "from_email_address",
84deca8b 154 'domain_id' => CRM_Core_Config::domainID(),
4aef704e 155 ));
a0f40af4
CW
156 CRM_Core_Resources::singleton()
157 ->addSetting(array(
158 'crmMailing' => array(
159 'civiMails' => $civiMails['values'],
8099bfee 160 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
a0f40af4
CW
161 'groupNames' => $groupNames['values'],
162 'headerfooterList' => $headerfooterList['values'],
163 'mesTemplate' => $mesTemplate['values'],
164 'emailAdd' => $emailAdd['values'],
a0f40af4
CW
165 'mailTokens' => $mailTokens['values'],
166 'contactid' => $contactID,
167 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
168 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'),
d124a91f 169 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'),
a0f40af4
CW
170 'fromAddress' => $fromAddress['values'],
171 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
172 'id' => 'user_contact_id',
173 'return' => 'email',
174 )),
175 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
176 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
177 ),
178 ))
179 ->addPermissions(array(
180 'view all contacts',
181 'access CiviMail',
182 'create mailings',
183 'schedule mailings',
184 'approve mailings',
185 'delete in CiviMail',
867299da 186 'edit message templates',
a0f40af4 187 ));
983052fe 188
4aef704e 189 return $result;
190 }
983052fe 191
4aef704e 192 /**
e0ef6999
EM
193 * @return bool
194 */
00be9182 195 public static function workflowEnabled() {
6a488035
TO
196 $config = CRM_Core_Config::singleton();
197
198 // early exit, since not true for most
199 if (!$config->userSystem->is_drupal ||
200 !function_exists('module_exists')
201 ) {
202 return FALSE;
203 }
204
205 if (!module_exists('rules')) {
206 return FALSE;
207 }
208
209 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
210 'civimail_workflow',
211 NULL,
212 FALSE
213 );
214
215 return ($enableWorkflow &&
216 $config->userSystem->is_drupal
217 ) ? TRUE : FALSE;
218 }
219
e0ef6999 220 /**
e7c15cb6 221 * @inheritDoc
e0ef6999 222 * @param bool $getAllUnconditionally
221b21b4
AH
223 * @param bool $descriptions
224 * Whether to return permission descriptions
e0ef6999
EM
225 *
226 * @return array
227 */
221b21b4 228 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
6a488035 229 $permissions = array(
221b21b4
AH
230 'access CiviMail' => array(
231 ts('access CiviMail'),
232 ),
233 'access CiviMail subscribe/unsubscribe pages' => array(
234 ts('access CiviMail subscribe/unsubscribe pages'),
235 ts('Subscribe/unsubscribe from mailing list group'),
236 ),
237 'delete in CiviMail' => array(
238 ts('delete in CiviMail'),
239 ts('Delete Mailing'),
240 ),
241 'view public CiviMail content' => array(
242 ts('view public CiviMail content'),
243 ),
6a488035
TO
244 );
245
33777e4a 246 if (self::workflowEnabled() || $getAllUnconditionally) {
221b21b4
AH
247 $permissions[] = array(
248 'create mailings' => array(
249 ts('create mailings'),
250 ),
251 );
252 $permissions[] = array(
253 'schedule mailings' => array(
254 ts('schedule mailings'),
255 ),
256 );
257 $permissions[] = array(
258 'approve mailings' => array(
259 ts('approve mailings'),
260 ),
261 );
262 }
263
264 if (!$descriptions) {
265 foreach ($permissions as $name => $attr) {
266 $permissions[$name] = array_shift($attr);
267 }
6a488035
TO
268 }
269
270 return $permissions;
271 }
272
273
e0ef6999 274 /**
e7c15cb6 275 * @inheritDoc
e0ef6999
EM
276 * @return null
277 */
6a488035
TO
278 public function getUserDashboardElement() {
279 // no dashboard element for this component
280 return NULL;
281 }
282
e0ef6999
EM
283 /**
284 * @return null
285 */
6a488035
TO
286 public function getUserDashboardObject() {
287 // no dashboard element for this component
288 return NULL;
289 }
290
e0ef6999 291 /**
e7c15cb6 292 * @inheritDoc
e0ef6999
EM
293 * @return array
294 */
6a488035 295 public function registerTab() {
2ede60ec
DL
296 return array(
297 'title' => ts('Mailings'),
298 'id' => 'mailing',
299 'url' => 'mailing',
300 'weight' => 45,
301 );
6a488035
TO
302 }
303
e0ef6999 304 /**
e7c15cb6 305 * @inheritDoc
e0ef6999
EM
306 * @return array
307 */
6a488035 308 public function registerAdvancedSearchPane() {
35f7561f 309 return array(
353ffa53 310 'title' => ts('Mailings'),
6a488035
TO
311 'weight' => 20,
312 );
313 }
314
e0ef6999 315 /**
e7c15cb6 316 * @inheritDoc
e0ef6999
EM
317 * @return null
318 */
6a488035
TO
319 public function getActivityTypes() {
320 return NULL;
321 }
322
e0ef6999 323 /**
fe482240 324 * add shortcut to Create New.
e0ef6999
EM
325 * @param $shortCuts
326 */
35f7561f
TO
327 public function creatNewShortcut(&$shortCuts) {
328 }
96025800 329
6a488035 330}