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