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