Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | +--------------------------------------------------------------------+ | |
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 | |
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 | ||
40 | // docs inherited from interface | |
41 | protected $keyword = 'mailing'; | |
42 | ||
43 | ||
44 | // docs inherited from interface | |
e0ef6999 EM |
45 | /** |
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 | ||
4aef704e | 58 | public function getAngularModules() { |
59 | $result = array(); | |
6bea4a47 TO |
60 | $result['crmMailing'] = array( |
61 | 'ext' => 'civicrm', | |
030dce01 TO |
62 | 'js' => array( |
63 | 'js/angular-Mailing.js' , | |
64 | 'js/angularsanitize.js' , | |
65 | 'packages/ckeditor/ckeditor.js' | |
66 | ), | |
67 | ); | |
68 | $result['crmMailing2'] = array( | |
69 | 'ext' => 'civicrm', | |
8dfd5110 | 70 | 'js' => array('js/angular-crmMailing2.js', 'js/angular-crmMailing2-services.js', 'js/angular-crmMailing2-directives.js'), |
f347d31d | 71 | 'css' => array('css/angular-crmMailing2.css'), |
6bea4a47 | 72 | ); |
4aef704e | 73 | $result['crmMailingAB'] = array( |
74 | 'ext' => 'civicrm', | |
1996b8b2 TO |
75 | 'js' => array( |
76 | 'js/angular-crmMailingAB.js', | |
77 | 'js/angular-crmMailingAB-ReportCtrl.js', | |
78 | 'js/d3.min.js', | |
79 | 'js/angular-sanitize.js', | |
80 | 'packages/ckeditor/ckeditor.js', | |
81 | ), | |
4aef704e | 82 | 'css' => array('css/angular-crmMailingAB.css'), |
83 | ); | |
983052fe | 84 | |
cd5dd333 | 85 | $config = CRM_Core_Config::singleton(); |
6bea4a47 TO |
86 | $session = CRM_Core_Session::singleton(); |
87 | $contactID = $session->get('userID'); | |
4aef704e | 88 | $civiMails = civicrm_api3('Mailing', 'get', array()); |
89 | $campNames = civicrm_api3('Campaign', 'get', array()); | |
493b91cf | 90 | $mailingabNames = civicrm_api3('MailingAB','get',array()); |
4aef704e | 91 | $mailStatus = civicrm_api3('MailingJob', 'get', array()); |
92 | $groupNames = civicrm_api3('Group', 'get', array()); | |
93 | $headerfooterList = civicrm_api3('MailingComponent', 'get', array()); | |
6bea4a47 TO |
94 | |
95 | // FIXME: The following two items differ between GSOC CiviMail and ABTest branches | |
96 | if (FALSE) { | |
97 | // AB Test | |
98 | $emailAdd = civicrm_api3('Email', 'get', array()); | |
99 | $mesTemplate = civicrm_api3('MessageTemplate', 'get', array( | |
100 | 'sequential' => 1, | |
101 | 'return' => array("msg_html", "id", "msg_title","msg_subject"), | |
102 | 'id' => array('>' => 58), | |
103 | )); | |
104 | } else { | |
105 | // CiviMail UI | |
106 | $emailAdd = civicrm_api3('Email', 'get', array( | |
107 | 'sequential' => 1, | |
108 | 'return' => "email", | |
109 | 'contact_id' => $contactID, | |
110 | )); | |
111 | $mesTemplate = civicrm_api3('MessageTemplate', 'get', array( 'sequential' => 1, | |
744bebee | 112 | 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"), |
6bea4a47 TO |
113 | 'workflow_id' => array('IS NULL' => ""), |
114 | )); | |
115 | } | |
116 | $mailGrp = civicrm_api3('MailingGroup','get', array()); | |
117 | $mailTokens = civicrm_api3('Mailing', 'get_token', array( 'usage' => 'Mailing')); | |
3d053687 | 118 | $fromAddress = civicrm_api3('OptionGroup', 'get', array( |
4aef704e | 119 | 'sequential' => 1, |
3d053687 SR |
120 | 'name' => "from_email_address", |
121 | 'api.OptionValue.get' => array(), | |
4aef704e | 122 | )); |
4aef704e | 123 | CRM_Core_Resources::singleton()->addSetting(array( |
124 | 'crmMailing' => array( | |
493b91cf | 125 | 'mailingabNames'=>array_values($mailingabNames['values']), |
4aef704e | 126 | 'civiMails' => array_values($civiMails['values']), |
127 | 'campNames' => array_values($campNames['values']), | |
128 | 'mailStatus' => array_values($mailStatus['values']), | |
129 | 'groupNames' => array_values($groupNames['values']), | |
130 | 'headerfooterList' => array_values($headerfooterList['values']), | |
131 | 'mesTemplate' => array_values($mesTemplate['values']), | |
132 | 'emailAdd' => array_values($emailAdd['values']), | |
6bea4a47 | 133 | 'mailGrp' => array_values($mailGrp['values']), |
467cd00c | 134 | 'mailTokens' => array_values($mailTokens), |
6bea4a47 | 135 | 'contactid' => $contactID, |
cd5dd333 | 136 | 'enableReplyTo' => $config->replyTo, |
6bea4a47 | 137 | 'fromAddress' => array_values($fromAddress['values'][0]['api.OptionValue.get']['values']), |
13cb08ff | 138 | 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array('id' => 'user_contact_id', 'return' => 'email')), |
30a3791a TO |
139 | 'visibility' => array( |
140 | array('value' => 'Public Pages', 'label' => ts('Public Pages')), | |
141 | array('value' => 'User and User Admin Only', 'label' => ts('User and User Admin Only')), | |
142 | ), | |
4aef704e | 143 | ), |
144 | )); | |
983052fe | 145 | |
4aef704e | 146 | return $result; |
147 | } | |
983052fe | 148 | |
4aef704e | 149 | /** |
e0ef6999 EM |
150 | * @return bool |
151 | */ | |
6a488035 TO |
152 | static function workflowEnabled() { |
153 | $config = CRM_Core_Config::singleton(); | |
154 | ||
155 | // early exit, since not true for most | |
156 | if (!$config->userSystem->is_drupal || | |
157 | !function_exists('module_exists') | |
158 | ) { | |
159 | return FALSE; | |
160 | } | |
161 | ||
162 | if (!module_exists('rules')) { | |
163 | return FALSE; | |
164 | } | |
165 | ||
166 | $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, | |
167 | 'civimail_workflow', | |
168 | NULL, | |
169 | FALSE | |
170 | ); | |
171 | ||
172 | return ($enableWorkflow && | |
173 | $config->userSystem->is_drupal | |
174 | ) ? TRUE : FALSE; | |
175 | } | |
176 | ||
177 | // docs inherited from interface | |
e0ef6999 EM |
178 | /** |
179 | * @param bool $getAllUnconditionally | |
180 | * | |
181 | * @return array | |
182 | */ | |
33777e4a | 183 | public function getPermissions($getAllUnconditionally = FALSE) { |
6a488035 TO |
184 | $permissions = array( |
185 | 'access CiviMail', | |
186 | 'access CiviMail subscribe/unsubscribe pages', | |
187 | 'delete in CiviMail', | |
188 | 'view public CiviMail content', | |
189 | ); | |
190 | ||
33777e4a | 191 | if (self::workflowEnabled() || $getAllUnconditionally) { |
6a488035 TO |
192 | $permissions[] = 'create mailings'; |
193 | $permissions[] = 'schedule mailings'; | |
194 | $permissions[] = 'approve mailings'; | |
195 | } | |
196 | ||
197 | return $permissions; | |
198 | } | |
199 | ||
200 | ||
201 | // docs inherited from interface | |
e0ef6999 EM |
202 | /** |
203 | * @return null | |
204 | */ | |
6a488035 TO |
205 | public function getUserDashboardElement() { |
206 | // no dashboard element for this component | |
207 | return NULL; | |
208 | } | |
209 | ||
e0ef6999 EM |
210 | /** |
211 | * @return null | |
212 | */ | |
6a488035 TO |
213 | public function getUserDashboardObject() { |
214 | // no dashboard element for this component | |
215 | return NULL; | |
216 | } | |
217 | ||
218 | // docs inherited from interface | |
e0ef6999 EM |
219 | /** |
220 | * @return array | |
221 | */ | |
6a488035 | 222 | public function registerTab() { |
2ede60ec DL |
223 | return array( |
224 | 'title' => ts('Mailings'), | |
225 | 'id' => 'mailing', | |
226 | 'url' => 'mailing', | |
227 | 'weight' => 45, | |
228 | ); | |
6a488035 TO |
229 | } |
230 | ||
231 | // docs inherited from interface | |
e0ef6999 EM |
232 | /** |
233 | * @return array | |
234 | */ | |
6a488035 TO |
235 | public function registerAdvancedSearchPane() { |
236 | return array('title' => ts('Mailings'), | |
237 | 'weight' => 20, | |
238 | ); | |
239 | } | |
240 | ||
241 | // docs inherited from interface | |
e0ef6999 EM |
242 | /** |
243 | * @return null | |
244 | */ | |
6a488035 TO |
245 | public function getActivityTypes() { |
246 | return NULL; | |
247 | } | |
248 | ||
249 | // add shortcut to Create New | |
e0ef6999 EM |
250 | /** |
251 | * @param $shortCuts | |
252 | */ | |
6a488035 TO |
253 | public function creatNewShortcut(&$shortCuts) {} |
254 | } | |
255 |