Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | |
06b69b18 | 34 | * @copyright CiviCRM LLC (c) 2004-2014 |
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 TO |
71 | 'js' => array( |
72 | 'js/angular-crmMailing.js', | |
edb34488 | 73 | 'js/angular-crmMailing/*.js', |
353ffa53 | 74 | ), |
96ac27bd | 75 | 'css' => array('css/angular-crmMailing.css'), |
ad7abea2 | 76 | 'partials' => array('partials/crmMailing'), |
6bea4a47 | 77 | ); |
4aef704e | 78 | $result['crmMailingAB'] = array( |
79 | 'ext' => 'civicrm', | |
353ffa53 TO |
80 | 'js' => array( |
81 | 'js/angular-crmMailingAB.js', | |
edb34488 | 82 | 'js/angular-crmMailingAB/*.js', |
353ffa53 | 83 | ), |
4aef704e | 84 | 'css' => array('css/angular-crmMailingAB.css'), |
ad7abea2 | 85 | 'partials' => array('partials/crmMailingAB'), |
4aef704e | 86 | ); |
d74bca86 TO |
87 | $result['crmD3'] = array( |
88 | 'ext' => 'civicrm', | |
edb34488 TO |
89 | 'js' => array( |
90 | 'js/angular-crmD3.js', | |
91 | 'bower_components/d3/d3.min.js', | |
92 | ), | |
d74bca86 | 93 | ); |
983052fe | 94 | |
8099bfee | 95 | $config = CRM_Core_Config::singleton(); |
6bea4a47 TO |
96 | $session = CRM_Core_Session::singleton(); |
97 | $contactID = $session->get('userID'); | |
d979898e | 98 | |
51527a6e CW |
99 | // Get past mailings |
100 | // CRM-16155 - Limit to a reasonable number | |
101 | $civiMails = civicrm_api3('Mailing', 'get', array( | |
102 | 'is_completed' => 1, | |
103 | 'mailing_type' => array('IN' => array('standalone', 'winner')), | |
104 | 'return' => array('id', 'name', 'scheduled_date'), | |
105 | 'sequential' => 1, | |
106 | 'options' => array( | |
107 | 'limit' => 500, | |
108 | 'sort' => 'is_archived asc, scheduled_date desc', | |
8099bfee | 109 | ), |
51527a6e CW |
110 | )); |
111 | // Generic params | |
a0f40af4 CW |
112 | $params = array( |
113 | 'options' => array('limit' => 0), | |
114 | 'sequential' => 1, | |
115 | ); | |
8099bfee | 116 | |
a0f40af4 CW |
117 | $groupNames = civicrm_api3('Group', 'get', $params + array( |
118 | 'is_active' => 1, | |
119 | 'return' => array('title', 'visibility', 'group_type', 'is_hidden'), | |
120 | )); | |
121 | $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array( | |
122 | 'is_active' => 1, | |
123 | 'return' => array('name', 'component_type', 'is_default'), | |
124 | )); | |
6bea4a47 | 125 | |
44a7c67d TO |
126 | $emailAdd = civicrm_api3('Email', 'get', array( |
127 | 'sequential' => 1, | |
128 | 'return' => "email", | |
129 | 'contact_id' => $contactID, | |
130 | )); | |
a0f40af4 CW |
131 | |
132 | // FIXME: Loading the contents of every template into the dom does not scale well | |
d979898e | 133 | $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array( |
44a7c67d | 134 | 'sequential' => 1, |
a0f40af4 | 135 | 'is_active' => 1, |
44a7c67d | 136 | 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"), |
44a7c67d TO |
137 | 'workflow_id' => array('IS NULL' => ""), |
138 | )); | |
d979898e | 139 | $mailGrp = civicrm_api3('MailingGroup', 'get', $params); |
a0f40af4 CW |
140 | $mailTokens = civicrm_api3('Mailing', 'gettokens', array( |
141 | 'entity' => array('contact', 'mailing'), | |
8099bfee | 142 | 'sequential' => 1, |
a0f40af4 | 143 | )); |
d979898e CW |
144 | $fromAddress = civicrm_api3('OptionValue', 'get', $params + array( |
145 | 'option_group_id' => "from_email_address", | |
4aef704e | 146 | )); |
a0f40af4 CW |
147 | CRM_Core_Resources::singleton() |
148 | ->addSetting(array( | |
149 | 'crmMailing' => array( | |
150 | 'civiMails' => $civiMails['values'], | |
8099bfee | 151 | 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), |
a0f40af4 CW |
152 | 'groupNames' => $groupNames['values'], |
153 | 'headerfooterList' => $headerfooterList['values'], | |
154 | 'mesTemplate' => $mesTemplate['values'], | |
155 | 'emailAdd' => $emailAdd['values'], | |
156 | 'mailGrp' => $mailGrp['values'], | |
157 | 'mailTokens' => $mailTokens['values'], | |
158 | 'contactid' => $contactID, | |
159 | 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), | |
160 | 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'), | |
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 | )); | |
983052fe | 178 | |
4aef704e | 179 | return $result; |
180 | } | |
983052fe | 181 | |
4aef704e | 182 | /** |
e0ef6999 EM |
183 | * @return bool |
184 | */ | |
00be9182 | 185 | public static function workflowEnabled() { |
6a488035 TO |
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 | ||
e0ef6999 | 210 | /** |
e7c15cb6 | 211 | * @inheritDoc |
e0ef6999 EM |
212 | * @param bool $getAllUnconditionally |
213 | * | |
214 | * @return array | |
215 | */ | |
33777e4a | 216 | public function getPermissions($getAllUnconditionally = FALSE) { |
6a488035 TO |
217 | $permissions = array( |
218 | 'access CiviMail', | |
219 | 'access CiviMail subscribe/unsubscribe pages', | |
220 | 'delete in CiviMail', | |
221 | 'view public CiviMail content', | |
222 | ); | |
223 | ||
33777e4a | 224 | if (self::workflowEnabled() || $getAllUnconditionally) { |
6a488035 TO |
225 | $permissions[] = 'create mailings'; |
226 | $permissions[] = 'schedule mailings'; | |
227 | $permissions[] = 'approve mailings'; | |
228 | } | |
229 | ||
230 | return $permissions; | |
231 | } | |
232 | ||
233 | ||
e0ef6999 | 234 | /** |
e7c15cb6 | 235 | * @inheritDoc |
e0ef6999 EM |
236 | * @return null |
237 | */ | |
6a488035 TO |
238 | public function getUserDashboardElement() { |
239 | // no dashboard element for this component | |
240 | return NULL; | |
241 | } | |
242 | ||
e0ef6999 EM |
243 | /** |
244 | * @return null | |
245 | */ | |
6a488035 TO |
246 | public function getUserDashboardObject() { |
247 | // no dashboard element for this component | |
248 | return NULL; | |
249 | } | |
250 | ||
e0ef6999 | 251 | /** |
e7c15cb6 | 252 | * @inheritDoc |
e0ef6999 EM |
253 | * @return array |
254 | */ | |
6a488035 | 255 | public function registerTab() { |
2ede60ec DL |
256 | return array( |
257 | 'title' => ts('Mailings'), | |
258 | 'id' => 'mailing', | |
259 | 'url' => 'mailing', | |
260 | 'weight' => 45, | |
261 | ); | |
6a488035 TO |
262 | } |
263 | ||
e0ef6999 | 264 | /** |
e7c15cb6 | 265 | * @inheritDoc |
e0ef6999 EM |
266 | * @return array |
267 | */ | |
6a488035 | 268 | public function registerAdvancedSearchPane() { |
35f7561f | 269 | return array( |
353ffa53 | 270 | 'title' => ts('Mailings'), |
6a488035 TO |
271 | 'weight' => 20, |
272 | ); | |
273 | } | |
274 | ||
e0ef6999 | 275 | /** |
e7c15cb6 | 276 | * @inheritDoc |
e0ef6999 EM |
277 | * @return null |
278 | */ | |
6a488035 TO |
279 | public function getActivityTypes() { |
280 | return NULL; | |
281 | } | |
282 | ||
e0ef6999 | 283 | /** |
fe482240 | 284 | * add shortcut to Create New. |
e0ef6999 EM |
285 | * @param $shortCuts |
286 | */ | |
35f7561f TO |
287 | public function creatNewShortcut(&$shortCuts) { |
288 | } | |
96025800 | 289 | |
6a488035 | 290 | } |