Merge pull request #7076 from totten/4.6-weight-sgn
[civicrm-core.git] / CRM / Mailing / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 * $Id$
36 *
37 */
38 class CRM_Mailing_Info extends CRM_Core_Component_Info {
39
40 /**
41 * @inheritDoc
42 */
43 protected $keyword = 'mailing';
44
45
46 /**
47 * @inheritDoc
48 * @return array
49 */
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
60 /**
61 * Get AngularJS modules and their dependencies
62 *
63 * @return array
64 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
65 * @see CRM_Utils_Hook::angularModules
66 */
67 public function getAngularModules() {
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
77 $result = array();
78 $result['crmMailing'] = array(
79 'ext' => 'civicrm',
80 'js' => array(
81 'ang/crmMailing.js',
82 'ang/crmMailing/*.js',
83 ),
84 'css' => array('ang/crmMailing.css'),
85 'partials' => array('ang/crmMailing'),
86 );
87 $result['crmMailingAB'] = array(
88 'ext' => 'civicrm',
89 'js' => array(
90 'ang/crmMailingAB.js',
91 'ang/crmMailingAB/*.js',
92 'ang/crmMailingAB/*/*.js',
93 ),
94 'css' => array('ang/crmMailingAB.css'),
95 'partials' => array('ang/crmMailingAB'),
96 );
97 $result['crmD3'] = array(
98 'ext' => 'civicrm',
99 'js' => array(
100 'ang/crmD3.js',
101 'bower_components/d3/d3.min.js',
102 ),
103 );
104
105 $config = CRM_Core_Config::singleton();
106 $session = CRM_Core_Session::singleton();
107 $contactID = $session->get('userID');
108
109 // Get past mailings
110 // CRM-16155 - Limit to a reasonable number
111 $civiMails = civicrm_api3('Mailing', 'get', array(
112 'is_completed' => 1,
113 'mailing_type' => array('IN' => array('standalone', 'winner')),
114 'return' => array('id', 'name', 'scheduled_date'),
115 'sequential' => 1,
116 'options' => array(
117 'limit' => 500,
118 'sort' => 'is_archived asc, scheduled_date desc',
119 ),
120 ));
121 // Generic params
122 $params = array(
123 'options' => array('limit' => 0),
124 'sequential' => 1,
125 );
126
127 $groupNames = civicrm_api3('Group', 'get', $params + array(
128 'is_active' => 1,
129 'check_permissions' => TRUE,
130 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
131 ));
132 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
133 'is_active' => 1,
134 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
135 ));
136
137 $emailAdd = civicrm_api3('Email', 'get', array(
138 'sequential' => 1,
139 'return' => "email",
140 'contact_id' => $contactID,
141 ));
142
143 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
144 'sequential' => 1,
145 'is_active' => 1,
146 'return' => array("id", "msg_title"),
147 'workflow_id' => array('IS NULL' => ""),
148 ));
149 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
150 'entity' => array('contact', 'mailing'),
151 'sequential' => 1,
152 ));
153 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
154 'option_group_id' => "from_email_address",
155 'domain_id' => CRM_Core_Config::domainID(),
156 ));
157 CRM_Core_Resources::singleton()
158 ->addSetting(array(
159 'crmMailing' => array(
160 'civiMails' => $civiMails['values'],
161 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
162 'groupNames' => $groupNames['values'],
163 'headerfooterList' => $headerfooterList['values'],
164 'mesTemplate' => $mesTemplate['values'],
165 'emailAdd' => $emailAdd['values'],
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'),
170 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'),
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',
187 'edit message templates',
188 ));
189
190 return $result;
191 }
192
193 /**
194 * @return bool
195 */
196 public static function workflowEnabled() {
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
221 /**
222 * @inheritDoc
223 * @param bool $getAllUnconditionally
224 * @param bool $descriptions
225 * Whether to return permission descriptions
226 *
227 * @return array
228 */
229 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
230 $permissions = array(
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 ),
245 );
246
247 if (self::workflowEnabled() || $getAllUnconditionally) {
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 }
269 }
270
271 return $permissions;
272 }
273
274
275 /**
276 * @inheritDoc
277 * @return null
278 */
279 public function getUserDashboardElement() {
280 // no dashboard element for this component
281 return NULL;
282 }
283
284 /**
285 * @return null
286 */
287 public function getUserDashboardObject() {
288 // no dashboard element for this component
289 return NULL;
290 }
291
292 /**
293 * @inheritDoc
294 * @return array
295 */
296 public function registerTab() {
297 return array(
298 'title' => ts('Mailings'),
299 'id' => 'mailing',
300 'url' => 'mailing',
301 'weight' => 45,
302 );
303 }
304
305 /**
306 * @inheritDoc
307 * @return array
308 */
309 public function registerAdvancedSearchPane() {
310 return array(
311 'title' => ts('Mailings'),
312 'weight' => 20,
313 );
314 }
315
316 /**
317 * @inheritDoc
318 * @return null
319 */
320 public function getActivityTypes() {
321 return NULL;
322 }
323
324 /**
325 * add shortcut to Create New.
326 * @param $shortCuts
327 */
328 public function creatNewShortcut(&$shortCuts) {
329 }
330
331 }