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