Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
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 | |
e7112fa7 | 34 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
35 | * $Id$ |
36 | * | |
37 | */ | |
38 | class CRM_Mailing_Info extends CRM_Core_Component_Info { | |
39 | ||
e7c15cb6 CW |
40 | /** |
41 | * @inheritDoc | |
42 | */ | |
6a488035 TO |
43 | protected $keyword = 'mailing'; |
44 | ||
45 | ||
e0ef6999 | 46 | /** |
e7c15cb6 | 47 | * @inheritDoc |
e0ef6999 EM |
48 | * @return array |
49 | */ | |
6a488035 TO |
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 | ||
ced9bfed | 60 | /** |
a0f40af4 | 61 | * Get AngularJS modules and their dependencies |
ced9bfed EM |
62 | * |
63 | * @return array | |
64 | * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules) | |
65 | * @see CRM_Utils_Hook::angularModules | |
66 | */ | |
4aef704e | 67 | public function getAngularModules() { |
68 | $result = array(); | |
88e9e883 | 69 | $result['crmMailing'] = array( |
030dce01 | 70 | 'ext' => 'civicrm', |
353ffa53 | 71 | 'js' => array( |
81bb7011 TO |
72 | 'ang/crmMailing.js', |
73 | 'ang/crmMailing/*.js', | |
353ffa53 | 74 | ), |
81bb7011 TO |
75 | 'css' => array('ang/crmMailing.css'), |
76 | 'partials' => array('ang/crmMailing'), | |
6bea4a47 | 77 | ); |
4aef704e | 78 | $result['crmMailingAB'] = array( |
79 | 'ext' => 'civicrm', | |
353ffa53 | 80 | 'js' => array( |
679996bb TO |
81 | 'ang/crmMailingAB.js', |
82 | 'ang/crmMailingAB/*.js', | |
83 | 'ang/crmMailingAB/*/*.js', | |
353ffa53 | 84 | ), |
e9f5761a | 85 | 'css' => array('ang/crmMailingAB.css'), |
6f54251a | 86 | 'partials' => array('ang/crmMailingAB'), |
4aef704e | 87 | ); |
d74bca86 TO |
88 | $result['crmD3'] = array( |
89 | 'ext' => 'civicrm', | |
edb34488 | 90 | 'js' => array( |
6f54251a | 91 | 'ang/crmD3.js', |
edb34488 TO |
92 | 'bower_components/d3/d3.min.js', |
93 | ), | |
d74bca86 | 94 | ); |
983052fe | 95 | |
8099bfee | 96 | $config = CRM_Core_Config::singleton(); |
6bea4a47 TO |
97 | $session = CRM_Core_Session::singleton(); |
98 | $contactID = $session->get('userID'); | |
d979898e | 99 | |
51527a6e CW |
100 | // Get past mailings |
101 | // CRM-16155 - Limit to a reasonable number | |
102 | $civiMails = civicrm_api3('Mailing', 'get', array( | |
72dd949e | 103 | 'is_completed' => 1, |
51527a6e | 104 | 'mailing_type' => array('IN' => array('standalone', 'winner')), |
72dd949e | 105 | 'return' => array('id', 'name', 'scheduled_date'), |
51527a6e CW |
106 | 'sequential' => 1, |
107 | 'options' => array( | |
108 | 'limit' => 500, | |
109 | 'sort' => 'is_archived asc, scheduled_date desc', | |
8099bfee | 110 | ), |
51527a6e CW |
111 | )); |
112 | // Generic params | |
a0f40af4 CW |
113 | $params = array( |
114 | 'options' => array('limit' => 0), | |
115 | 'sequential' => 1, | |
116 | ); | |
8099bfee | 117 | |
a0f40af4 CW |
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, | |
0499685e | 124 | 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'), |
72dd949e | 125 | )); |
6bea4a47 | 126 | |
44a7c67d TO |
127 | $emailAdd = civicrm_api3('Email', 'get', array( |
128 | 'sequential' => 1, | |
129 | 'return' => "email", | |
130 | 'contact_id' => $contactID, | |
131 | )); | |
a0f40af4 CW |
132 | |
133 | // FIXME: Loading the contents of every template into the dom does not scale well | |
d979898e | 134 | $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array( |
44a7c67d | 135 | 'sequential' => 1, |
a0f40af4 | 136 | 'is_active' => 1, |
44a7c67d | 137 | 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"), |
44a7c67d TO |
138 | 'workflow_id' => array('IS NULL' => ""), |
139 | )); | |
d979898e | 140 | $mailGrp = civicrm_api3('MailingGroup', 'get', $params); |
a0f40af4 CW |
141 | $mailTokens = civicrm_api3('Mailing', 'gettokens', array( |
142 | 'entity' => array('contact', 'mailing'), | |
8099bfee | 143 | 'sequential' => 1, |
a0f40af4 | 144 | )); |
d979898e CW |
145 | $fromAddress = civicrm_api3('OptionValue', 'get', $params + array( |
146 | 'option_group_id' => "from_email_address", | |
4aef704e | 147 | )); |
a0f40af4 CW |
148 | CRM_Core_Resources::singleton() |
149 | ->addSetting(array( | |
150 | 'crmMailing' => array( | |
151 | 'civiMails' => $civiMails['values'], | |
8099bfee | 152 | 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), |
a0f40af4 CW |
153 | 'groupNames' => $groupNames['values'], |
154 | 'headerfooterList' => $headerfooterList['values'], | |
155 | 'mesTemplate' => $mesTemplate['values'], | |
156 | 'emailAdd' => $emailAdd['values'], | |
157 | 'mailGrp' => $mailGrp['values'], | |
158 | 'mailTokens' => $mailTokens['values'], | |
159 | 'contactid' => $contactID, | |
160 | 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), | |
161 | 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'), | |
d124a91f | 162 | 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'), |
a0f40af4 CW |
163 | 'fromAddress' => $fromAddress['values'], |
164 | 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array( | |
165 | 'id' => 'user_contact_id', | |
166 | 'return' => 'email', | |
167 | )), | |
168 | 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()), | |
169 | 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(), | |
170 | ), | |
171 | )) | |
172 | ->addPermissions(array( | |
173 | 'view all contacts', | |
174 | 'access CiviMail', | |
175 | 'create mailings', | |
176 | 'schedule mailings', | |
177 | 'approve mailings', | |
178 | 'delete in CiviMail', | |
179 | )); | |
983052fe | 180 | |
4aef704e | 181 | return $result; |
182 | } | |
983052fe | 183 | |
4aef704e | 184 | /** |
e0ef6999 EM |
185 | * @return bool |
186 | */ | |
00be9182 | 187 | public static function workflowEnabled() { |
6a488035 TO |
188 | $config = CRM_Core_Config::singleton(); |
189 | ||
190 | // early exit, since not true for most | |
191 | if (!$config->userSystem->is_drupal || | |
192 | !function_exists('module_exists') | |
193 | ) { | |
194 | return FALSE; | |
195 | } | |
196 | ||
197 | if (!module_exists('rules')) { | |
198 | return FALSE; | |
199 | } | |
200 | ||
201 | $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, | |
202 | 'civimail_workflow', | |
203 | NULL, | |
204 | FALSE | |
205 | ); | |
206 | ||
207 | return ($enableWorkflow && | |
208 | $config->userSystem->is_drupal | |
209 | ) ? TRUE : FALSE; | |
210 | } | |
211 | ||
e0ef6999 | 212 | /** |
e7c15cb6 | 213 | * @inheritDoc |
e0ef6999 | 214 | * @param bool $getAllUnconditionally |
221b21b4 AH |
215 | * @param bool $descriptions |
216 | * Whether to return permission descriptions | |
e0ef6999 EM |
217 | * |
218 | * @return array | |
219 | */ | |
221b21b4 | 220 | public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { |
6a488035 | 221 | $permissions = array( |
221b21b4 AH |
222 | 'access CiviMail' => array( |
223 | ts('access CiviMail'), | |
224 | ), | |
225 | 'access CiviMail subscribe/unsubscribe pages' => array( | |
226 | ts('access CiviMail subscribe/unsubscribe pages'), | |
227 | ts('Subscribe/unsubscribe from mailing list group'), | |
228 | ), | |
229 | 'delete in CiviMail' => array( | |
230 | ts('delete in CiviMail'), | |
231 | ts('Delete Mailing'), | |
232 | ), | |
233 | 'view public CiviMail content' => array( | |
234 | ts('view public CiviMail content'), | |
235 | ), | |
6a488035 TO |
236 | ); |
237 | ||
33777e4a | 238 | if (self::workflowEnabled() || $getAllUnconditionally) { |
221b21b4 AH |
239 | $permissions[] = array( |
240 | 'create mailings' => array( | |
241 | ts('create mailings'), | |
242 | ), | |
243 | ); | |
244 | $permissions[] = array( | |
245 | 'schedule mailings' => array( | |
246 | ts('schedule mailings'), | |
247 | ), | |
248 | ); | |
249 | $permissions[] = array( | |
250 | 'approve mailings' => array( | |
251 | ts('approve mailings'), | |
252 | ), | |
253 | ); | |
254 | } | |
255 | ||
256 | if (!$descriptions) { | |
257 | foreach ($permissions as $name => $attr) { | |
258 | $permissions[$name] = array_shift($attr); | |
259 | } | |
6a488035 TO |
260 | } |
261 | ||
262 | return $permissions; | |
263 | } | |
264 | ||
265 | ||
e0ef6999 | 266 | /** |
e7c15cb6 | 267 | * @inheritDoc |
e0ef6999 EM |
268 | * @return null |
269 | */ | |
6a488035 TO |
270 | public function getUserDashboardElement() { |
271 | // no dashboard element for this component | |
272 | return NULL; | |
273 | } | |
274 | ||
e0ef6999 EM |
275 | /** |
276 | * @return null | |
277 | */ | |
6a488035 TO |
278 | public function getUserDashboardObject() { |
279 | // no dashboard element for this component | |
280 | return NULL; | |
281 | } | |
282 | ||
e0ef6999 | 283 | /** |
e7c15cb6 | 284 | * @inheritDoc |
e0ef6999 EM |
285 | * @return array |
286 | */ | |
6a488035 | 287 | public function registerTab() { |
2ede60ec DL |
288 | return array( |
289 | 'title' => ts('Mailings'), | |
290 | 'id' => 'mailing', | |
291 | 'url' => 'mailing', | |
292 | 'weight' => 45, | |
293 | ); | |
6a488035 TO |
294 | } |
295 | ||
e0ef6999 | 296 | /** |
e7c15cb6 | 297 | * @inheritDoc |
e0ef6999 EM |
298 | * @return array |
299 | */ | |
6a488035 | 300 | public function registerAdvancedSearchPane() { |
35f7561f | 301 | return array( |
353ffa53 | 302 | 'title' => ts('Mailings'), |
6a488035 TO |
303 | 'weight' => 20, |
304 | ); | |
305 | } | |
306 | ||
e0ef6999 | 307 | /** |
e7c15cb6 | 308 | * @inheritDoc |
e0ef6999 EM |
309 | * @return null |
310 | */ | |
6a488035 TO |
311 | public function getActivityTypes() { |
312 | return NULL; | |
313 | } | |
314 | ||
e0ef6999 | 315 | /** |
fe482240 | 316 | * add shortcut to Create New. |
e0ef6999 EM |
317 | * @param $shortCuts |
318 | */ | |
35f7561f TO |
319 | public function creatNewShortcut(&$shortCuts) { |
320 | } | |
96025800 | 321 | |
6a488035 | 322 | } |