Merge pull request #4983 from colemanw/CRM-15842
[civicrm-core.git] / CRM / Mailing / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 /**
41 * @inheritDoc
42 */
43 protected $keyword = 'mailing';
44
45
46 /**
47 * @inheritDoc
48 * @return array
49 */
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
60 public function getAngularModules() {
61 $result = array();
62 $result['crmMailing'] = array(
63 'ext' => 'civicrm',
64 'js' => array(
65 'js/angular-crmMailing.js',
66 'js/angular-crmMailing/services.js',
67 'js/angular-crmMailing/directives.js',
68 ),
69 'css' => array('css/angular-crmMailing.css'),
70 );
71 $result['crmMailingAB'] = array(
72 'ext' => 'civicrm',
73 'js' => array(
74 'js/angular-crmMailingAB.js',
75 'js/angular-crmMailingAB/services.js',
76 'js/angular-crmMailingAB/directives.js',
77 ),
78 'css' => array('css/angular-crmMailingAB.css'),
79 );
80 $result['crmD3'] = array(
81 'ext' => 'civicrm',
82 'js' => array('js/angular-crmD3.js', 'bower_components/d3/d3.min.js'),
83 );
84
85 $config = CRM_Core_Config::singleton();
86 $session = CRM_Core_Session::singleton();
87 $contactID = $session->get('userID');
88 $civiMails = civicrm_api3('Mailing', 'get', array());
89 $campNames = civicrm_api3('Campaign', 'get', array());
90 $mailingabNames = civicrm_api3('MailingAB', 'get', array());
91 $mailStatus = civicrm_api3('MailingJob', 'get', array());
92 $groupNames = civicrm_api3('Group', 'get', array());
93 $headerfooterList = civicrm_api3('MailingComponent', 'get', array());
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 }
105 else {
106 // CiviMail UI
107 $emailAdd = civicrm_api3('Email', 'get', array(
108 'sequential' => 1,
109 'return' => "email",
110 'contact_id' => $contactID,
111 ));
112 $mesTemplate = civicrm_api3('MessageTemplate', 'get', array(
113 'sequential' => 1,
114 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"),
115 'workflow_id' => array('IS NULL' => ""),
116 ));
117 }
118 $mailGrp = civicrm_api3('MailingGroup', 'get', array());
119 $mailTokens = civicrm_api3('Mailing', 'get_token', array('usage' => 'Mailing'));
120 $fromAddress = civicrm_api3('OptionGroup', 'get', array(
121 'sequential' => 1,
122 'name' => "from_email_address",
123 'api.OptionValue.get' => array(),
124 ));
125 CRM_Core_Resources::singleton()->addSetting(array(
126 'crmMailing' => array(
127 'mailingabNames' => array_values($mailingabNames['values']),
128 'civiMails' => array_values($civiMails['values']),
129 'campNames' => array_values($campNames['values']),
130 'mailStatus' => array_values($mailStatus['values']),
131 'groupNames' => array_values($groupNames['values']),
132 'headerfooterList' => array_values($headerfooterList['values']),
133 'mesTemplate' => array_values($mesTemplate['values']),
134 'emailAdd' => array_values($emailAdd['values']),
135 'mailGrp' => array_values($mailGrp['values']),
136 'mailTokens' => array_values($mailTokens),
137 'contactid' => $contactID,
138 'enableReplyTo' => isset($config->replyTo) ? $config->replyTo : 0,
139 'fromAddress' => array_values($fromAddress['values'][0]['api.OptionValue.get']['values']),
140 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
141 'id' => 'user_contact_id',
142 'return' => 'email',
143 )),
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 public 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 /**
183 * @inheritDoc
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 /**
207 * @inheritDoc
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 /**
224 * @inheritDoc
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 /**
237 * @inheritDoc
238 * @return array
239 */
240 public function registerAdvancedSearchPane() {
241 return array(
242 'title' => ts('Mailings'),
243 'weight' => 20,
244 );
245 }
246
247 /**
248 * @inheritDoc
249 * @return null
250 */
251 public function getActivityTypes() {
252 return NULL;
253 }
254
255 /**
256 * add shortcut to Create New
257 * @param $shortCuts
258 */
259 public function creatNewShortcut(&$shortCuts) {
260 }
261
262 }