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