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