ff3529b711f894f29960de8916ee8d3eeb76f05f
[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 $result = array();
69 $result['crmMailing'] = array(
70 'ext' => 'civicrm',
71 'js' => array(
72 'js/angular-crmMailing.js',
73 'js/angular-crmMailing/*.js',
74 ),
75 'css' => array('css/angular-crmMailing.css'),
76 'partials' => array('partials/crmMailing'),
77 );
78 $result['crmMailingAB'] = array(
79 'ext' => 'civicrm',
80 'js' => array(
81 'ang/crmMailingAB.js',
82 'ang/crmMailingAB/*.js',
83 'ang/crmMailingAB/*/*.js',
84 'js/angular-crmMailingAB/*.js',
85 ),
86 'css' => array('css/angular-crmMailingAB.css'),
87 'partials' => array('partials/crmMailingAB', 'ang/crmMailingAB'),
88 );
89 $result['crmD3'] = array(
90 'ext' => 'civicrm',
91 'js' => array(
92 'js/angular-crmD3.js',
93 'bower_components/d3/d3.min.js',
94 ),
95 );
96
97 $config = CRM_Core_Config::singleton();
98 $session = CRM_Core_Session::singleton();
99 $contactID = $session->get('userID');
100
101 // Get past mailings
102 // CRM-16155 - Limit to a reasonable number
103 $civiMails = civicrm_api3('Mailing', 'get', array(
104 'is_completed' => 1,
105 'mailing_type' => array('IN' => array('standalone', 'winner')),
106 'return' => array('id', 'name', 'scheduled_date'),
107 'sequential' => 1,
108 'options' => array(
109 'limit' => 500,
110 'sort' => 'is_archived asc, scheduled_date desc',
111 ),
112 ));
113 // Generic params
114 $params = array(
115 'options' => array('limit' => 0),
116 'sequential' => 1,
117 );
118
119 $groupNames = civicrm_api3('Group', 'get', $params + array(
120 'is_active' => 1,
121 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
122 ));
123 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
124 'is_active' => 1,
125 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
126 ));
127
128 $emailAdd = civicrm_api3('Email', 'get', array(
129 'sequential' => 1,
130 'return' => "email",
131 'contact_id' => $contactID,
132 ));
133
134 // FIXME: Loading the contents of every template into the dom does not scale well
135 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
136 'sequential' => 1,
137 'is_active' => 1,
138 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"),
139 'workflow_id' => array('IS NULL' => ""),
140 ));
141 $mailGrp = civicrm_api3('MailingGroup', 'get', $params);
142 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
143 'entity' => array('contact', 'mailing'),
144 'sequential' => 1,
145 ));
146 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
147 'option_group_id' => "from_email_address",
148 ));
149 CRM_Core_Resources::singleton()
150 ->addSetting(array(
151 'crmMailing' => array(
152 'civiMails' => $civiMails['values'],
153 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
154 'groupNames' => $groupNames['values'],
155 'headerfooterList' => $headerfooterList['values'],
156 'mesTemplate' => $mesTemplate['values'],
157 'emailAdd' => $emailAdd['values'],
158 'mailGrp' => $mailGrp['values'],
159 'mailTokens' => $mailTokens['values'],
160 'contactid' => $contactID,
161 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
162 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'),
163 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'),
164 'fromAddress' => $fromAddress['values'],
165 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
166 'id' => 'user_contact_id',
167 'return' => 'email',
168 )),
169 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
170 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
171 ),
172 ))
173 ->addPermissions(array(
174 'view all contacts',
175 'access CiviMail',
176 'create mailings',
177 'schedule mailings',
178 'approve mailings',
179 'delete in CiviMail',
180 ));
181
182 return $result;
183 }
184
185 /**
186 * @return bool
187 */
188 public static function workflowEnabled() {
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
202 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
203 'civimail_workflow',
204 NULL,
205 FALSE
206 );
207
208 return ($enableWorkflow &&
209 $config->userSystem->is_drupal
210 ) ? TRUE : FALSE;
211 }
212
213 /**
214 * @inheritDoc
215 * @param bool $getAllUnconditionally
216 * @param bool $descriptions
217 * Whether to return permission descriptions
218 *
219 * @return array
220 */
221 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
222 $permissions = array(
223 'access CiviMail' => array(
224 ts('access CiviMail'),
225 ),
226 'access CiviMail subscribe/unsubscribe pages' => array(
227 ts('access CiviMail subscribe/unsubscribe pages'),
228 ts('Subscribe/unsubscribe from mailing list group'),
229 ),
230 'delete in CiviMail' => array(
231 ts('delete in CiviMail'),
232 ts('Delete Mailing'),
233 ),
234 'view public CiviMail content' => array(
235 ts('view public CiviMail content'),
236 ),
237 );
238
239 if (self::workflowEnabled() || $getAllUnconditionally) {
240 $permissions[] = array(
241 'create mailings' => array(
242 ts('create mailings'),
243 ),
244 );
245 $permissions[] = array(
246 'schedule mailings' => array(
247 ts('schedule mailings'),
248 ),
249 );
250 $permissions[] = array(
251 'approve mailings' => array(
252 ts('approve mailings'),
253 ),
254 );
255 }
256
257 if (!$descriptions) {
258 foreach ($permissions as $name => $attr) {
259 $permissions[$name] = array_shift($attr);
260 }
261 }
262
263 return $permissions;
264 }
265
266
267 /**
268 * @inheritDoc
269 * @return null
270 */
271 public function getUserDashboardElement() {
272 // no dashboard element for this component
273 return NULL;
274 }
275
276 /**
277 * @return null
278 */
279 public function getUserDashboardObject() {
280 // no dashboard element for this component
281 return NULL;
282 }
283
284 /**
285 * @inheritDoc
286 * @return array
287 */
288 public function registerTab() {
289 return array(
290 'title' => ts('Mailings'),
291 'id' => 'mailing',
292 'url' => 'mailing',
293 'weight' => 45,
294 );
295 }
296
297 /**
298 * @inheritDoc
299 * @return array
300 */
301 public function registerAdvancedSearchPane() {
302 return array(
303 'title' => ts('Mailings'),
304 'weight' => 20,
305 );
306 }
307
308 /**
309 * @inheritDoc
310 * @return null
311 */
312 public function getActivityTypes() {
313 return NULL;
314 }
315
316 /**
317 * add shortcut to Create New.
318 * @param $shortCuts
319 */
320 public function creatNewShortcut(&$shortCuts) {
321 }
322
323 }