Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
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 | */ |
36 | class CRM_Mailing_Info extends CRM_Core_Component_Info { | |
37 | ||
e7c15cb6 CW |
38 | /** |
39 | * @inheritDoc | |
40 | */ | |
6a488035 TO |
41 | protected $keyword = 'mailing'; |
42 | ||
43 | ||
e0ef6999 | 44 | /** |
e7c15cb6 | 45 | * @inheritDoc |
e0ef6999 EM |
46 | * @return array |
47 | */ | |
6a488035 TO |
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 | ||
ced9bfed | 58 | /** |
25606795 | 59 | * Get AngularJS modules and their dependencies. |
ced9bfed EM |
60 | * |
61 | * @return array | |
62 | * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules) | |
63 | * @see CRM_Utils_Hook::angularModules | |
64 | */ | |
4aef704e | 65 | public function getAngularModules() { |
56621a6c KJ |
66 | // load angular files only if valid permissions are granted to the user |
67 | if (!CRM_Core_Permission::check('access CiviMail') | |
011c7136 KJ |
68 | && !CRM_Core_Permission::check('create mailings') |
69 | && !CRM_Core_Permission::check('schedule mailings') | |
70 | && !CRM_Core_Permission::check('approve mailings') | |
56621a6c KJ |
71 | ) { |
72 | return array(); | |
73 | } | |
74 | ||
4aef704e | 75 | $result = array(); |
88e9e883 | 76 | $result['crmMailing'] = array( |
030dce01 | 77 | 'ext' => 'civicrm', |
353ffa53 | 78 | 'js' => array( |
81bb7011 TO |
79 | 'ang/crmMailing.js', |
80 | 'ang/crmMailing/*.js', | |
353ffa53 | 81 | ), |
81bb7011 TO |
82 | 'css' => array('ang/crmMailing.css'), |
83 | 'partials' => array('ang/crmMailing'), | |
6bea4a47 | 84 | ); |
4aef704e | 85 | $result['crmMailingAB'] = array( |
86 | 'ext' => 'civicrm', | |
353ffa53 | 87 | 'js' => array( |
679996bb TO |
88 | 'ang/crmMailingAB.js', |
89 | 'ang/crmMailingAB/*.js', | |
90 | 'ang/crmMailingAB/*/*.js', | |
353ffa53 | 91 | ), |
e9f5761a | 92 | 'css' => array('ang/crmMailingAB.css'), |
6f54251a | 93 | 'partials' => array('ang/crmMailingAB'), |
4aef704e | 94 | ); |
d74bca86 TO |
95 | $result['crmD3'] = array( |
96 | 'ext' => 'civicrm', | |
edb34488 | 97 | 'js' => array( |
6f54251a | 98 | 'ang/crmD3.js', |
edb34488 TO |
99 | 'bower_components/d3/d3.min.js', |
100 | ), | |
d74bca86 | 101 | ); |
983052fe | 102 | |
8099bfee | 103 | $config = CRM_Core_Config::singleton(); |
6bea4a47 TO |
104 | $session = CRM_Core_Session::singleton(); |
105 | $contactID = $session->get('userID'); | |
d979898e | 106 | |
25606795 SB |
107 | // Get past mailings. |
108 | // CRM-16155 - Limit to a reasonable number. | |
51527a6e | 109 | $civiMails = civicrm_api3('Mailing', 'get', array( |
72dd949e | 110 | 'is_completed' => 1, |
51527a6e | 111 | 'mailing_type' => array('IN' => array('standalone', 'winner')), |
b4a37a31 | 112 | 'domain_id' => CRM_Core_Config::domainID(), |
72dd949e | 113 | 'return' => array('id', 'name', 'scheduled_date'), |
51527a6e CW |
114 | 'sequential' => 1, |
115 | 'options' => array( | |
116 | 'limit' => 500, | |
117 | 'sort' => 'is_archived asc, scheduled_date desc', | |
8099bfee | 118 | ), |
51527a6e | 119 | )); |
25606795 | 120 | // Generic params. |
a0f40af4 CW |
121 | $params = array( |
122 | 'options' => array('limit' => 0), | |
123 | 'sequential' => 1, | |
124 | ); | |
8099bfee | 125 | |
a0f40af4 CW |
126 | $groupNames = civicrm_api3('Group', 'get', $params + array( |
127 | 'is_active' => 1, | |
e7d6f8f8 | 128 | 'check_permissions' => TRUE, |
a0f40af4 CW |
129 | 'return' => array('title', 'visibility', 'group_type', 'is_hidden'), |
130 | )); | |
131 | $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array( | |
132 | 'is_active' => 1, | |
0499685e | 133 | 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'), |
72dd949e | 134 | )); |
6bea4a47 | 135 | |
44a7c67d TO |
136 | $emailAdd = civicrm_api3('Email', 'get', array( |
137 | 'sequential' => 1, | |
138 | 'return' => "email", | |
139 | 'contact_id' => $contactID, | |
140 | )); | |
a0f40af4 | 141 | |
d979898e | 142 | $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array( |
44a7c67d | 143 | 'sequential' => 1, |
a0f40af4 | 144 | 'is_active' => 1, |
3637550f | 145 | 'return' => array("id", "msg_title"), |
44a7c67d TO |
146 | 'workflow_id' => array('IS NULL' => ""), |
147 | )); | |
a0f40af4 CW |
148 | $mailTokens = civicrm_api3('Mailing', 'gettokens', array( |
149 | 'entity' => array('contact', 'mailing'), | |
8099bfee | 150 | 'sequential' => 1, |
a0f40af4 | 151 | )); |
d979898e CW |
152 | $fromAddress = civicrm_api3('OptionValue', 'get', $params + array( |
153 | 'option_group_id' => "from_email_address", | |
84deca8b | 154 | 'domain_id' => CRM_Core_Config::domainID(), |
4aef704e | 155 | )); |
a0f40af4 CW |
156 | CRM_Core_Resources::singleton() |
157 | ->addSetting(array( | |
158 | 'crmMailing' => array( | |
159 | 'civiMails' => $civiMails['values'], | |
8099bfee | 160 | 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), |
a0f40af4 CW |
161 | 'groupNames' => $groupNames['values'], |
162 | 'headerfooterList' => $headerfooterList['values'], | |
163 | 'mesTemplate' => $mesTemplate['values'], | |
164 | 'emailAdd' => $emailAdd['values'], | |
a0f40af4 CW |
165 | 'mailTokens' => $mailTokens['values'], |
166 | 'contactid' => $contactID, | |
167 | 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), | |
aaffa79f | 168 | 'enableReplyTo' => (int) Civi::settings()->get('replyTo'), |
169 | 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'), | |
a0f40af4 CW |
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', | |
867299da | 186 | 'edit message templates', |
a0f40af4 | 187 | )); |
983052fe | 188 | |
4aef704e | 189 | return $result; |
190 | } | |
983052fe | 191 | |
4aef704e | 192 | /** |
e0ef6999 EM |
193 | * @return bool |
194 | */ | |
00be9182 | 195 | public static function workflowEnabled() { |
6a488035 TO |
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 | ||
aaffa79f | 209 | $enableWorkflow = Civi::settings()->get('civimail_workflow'); |
6a488035 TO |
210 | |
211 | return ($enableWorkflow && | |
212 | $config->userSystem->is_drupal | |
213 | ) ? TRUE : FALSE; | |
214 | } | |
215 | ||
e0ef6999 | 216 | /** |
e7c15cb6 | 217 | * @inheritDoc |
e0ef6999 | 218 | * @param bool $getAllUnconditionally |
221b21b4 AH |
219 | * @param bool $descriptions |
220 | * Whether to return permission descriptions | |
e0ef6999 EM |
221 | * |
222 | * @return array | |
223 | */ | |
221b21b4 | 224 | public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { |
6a488035 | 225 | $permissions = array( |
221b21b4 AH |
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 | ), | |
6a488035 TO |
240 | ); |
241 | ||
33777e4a | 242 | if (self::workflowEnabled() || $getAllUnconditionally) { |
221b21b4 AH |
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 | } | |
6a488035 TO |
264 | } |
265 | ||
266 | return $permissions; | |
267 | } | |
268 | ||
269 | ||
e0ef6999 | 270 | /** |
e7c15cb6 | 271 | * @inheritDoc |
e0ef6999 EM |
272 | * @return null |
273 | */ | |
6a488035 TO |
274 | public function getUserDashboardElement() { |
275 | // no dashboard element for this component | |
276 | return NULL; | |
277 | } | |
278 | ||
e0ef6999 EM |
279 | /** |
280 | * @return null | |
281 | */ | |
6a488035 TO |
282 | public function getUserDashboardObject() { |
283 | // no dashboard element for this component | |
284 | return NULL; | |
285 | } | |
286 | ||
e0ef6999 | 287 | /** |
e7c15cb6 | 288 | * @inheritDoc |
e0ef6999 EM |
289 | * @return array |
290 | */ | |
6a488035 | 291 | public function registerTab() { |
2ede60ec DL |
292 | return array( |
293 | 'title' => ts('Mailings'), | |
294 | 'id' => 'mailing', | |
295 | 'url' => 'mailing', | |
296 | 'weight' => 45, | |
297 | ); | |
6a488035 TO |
298 | } |
299 | ||
e0ef6999 | 300 | /** |
e7c15cb6 | 301 | * @inheritDoc |
e0ef6999 EM |
302 | * @return array |
303 | */ | |
6a488035 | 304 | public function registerAdvancedSearchPane() { |
35f7561f | 305 | return array( |
353ffa53 | 306 | 'title' => ts('Mailings'), |
6a488035 TO |
307 | 'weight' => 20, |
308 | ); | |
309 | } | |
310 | ||
e0ef6999 | 311 | /** |
e7c15cb6 | 312 | * @inheritDoc |
e0ef6999 EM |
313 | * @return null |
314 | */ | |
6a488035 TO |
315 | public function getActivityTypes() { |
316 | return NULL; | |
317 | } | |
318 | ||
e0ef6999 | 319 | /** |
fe482240 | 320 | * add shortcut to Create New. |
e0ef6999 EM |
321 | * @param $shortCuts |
322 | */ | |
35f7561f TO |
323 | public function creatNewShortcut(&$shortCuts) { |
324 | } | |
96025800 | 325 | |
6a488035 | 326 | } |