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