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