Merge pull request #7791 from jitendrapurohit/CRM-18020
[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) Civi::settings()->get('replyTo'),
169 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('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 = Civi::settings()->get('civimail_workflow');
210
211 return ($enableWorkflow &&
212 $config->userSystem->is_drupal
213 ) ? TRUE : FALSE;
214 }
215
216 /**
217 * @inheritDoc
218 * @param bool $getAllUnconditionally
219 * @param bool $descriptions
220 * Whether to return permission descriptions
221 *
222 * @return array
223 */
224 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
225 $permissions = array(
226 'access CiviMail' => array(
227 ts('access CiviMail'),
228 ),
229 'access CiviMail subscribe/unsubscribe pages' => array(
230 ts('access CiviMail subscribe/unsubscribe pages'),
231 ts('Subscribe/unsubscribe from mailing list group'),
232 ),
233 'delete in CiviMail' => array(
234 ts('delete in CiviMail'),
235 ts('Delete Mailing'),
236 ),
237 'view public CiviMail content' => array(
238 ts('view public CiviMail content'),
239 ),
240 );
241
242 if (self::workflowEnabled() || $getAllUnconditionally) {
243 $permissions[] = array(
244 'create mailings' => array(
245 ts('create mailings'),
246 ),
247 );
248 $permissions[] = array(
249 'schedule mailings' => array(
250 ts('schedule mailings'),
251 ),
252 );
253 $permissions[] = array(
254 'approve mailings' => array(
255 ts('approve mailings'),
256 ),
257 );
258 }
259
260 if (!$descriptions) {
261 foreach ($permissions as $name => $attr) {
262 $permissions[$name] = array_shift($attr);
263 }
264 }
265
266 return $permissions;
267 }
268
269
270 /**
271 * @inheritDoc
272 * @return null
273 */
274 public function getUserDashboardElement() {
275 // no dashboard element for this component
276 return NULL;
277 }
278
279 /**
280 * @return null
281 */
282 public function getUserDashboardObject() {
283 // no dashboard element for this component
284 return NULL;
285 }
286
287 /**
288 * @inheritDoc
289 * @return array
290 */
291 public function registerTab() {
292 return array(
293 'title' => ts('Mailings'),
294 'id' => 'mailing',
295 'url' => 'mailing',
296 'weight' => 45,
297 );
298 }
299
300 /**
301 * @inheritDoc
302 * @return array
303 */
304 public function registerAdvancedSearchPane() {
305 return array(
306 'title' => ts('Mailings'),
307 'weight' => 20,
308 );
309 }
310
311 /**
312 * @inheritDoc
313 * @return null
314 */
315 public function getActivityTypes() {
316 return NULL;
317 }
318
319 /**
320 * add shortcut to Create New.
321 * @param $shortCuts
322 */
323 public function creatNewShortcut(&$shortCuts) {
324 }
325
326 }