Merge pull request #5485 from eileenmcnaughton/4.6
[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
ced9bfed
EM
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 */
4aef704e 67 public function getAngularModules() {
68 $result = array();
88e9e883 69 $result['crmMailing'] = array(
030dce01 70 'ext' => 'civicrm',
353ffa53
TO
71 'js' => array(
72 'js/angular-crmMailing.js',
edb34488 73 'js/angular-crmMailing/*.js',
353ffa53 74 ),
96ac27bd 75 'css' => array('css/angular-crmMailing.css'),
ad7abea2 76 'partials' => array('partials/crmMailing'),
6bea4a47 77 );
4aef704e 78 $result['crmMailingAB'] = array(
79 'ext' => 'civicrm',
353ffa53
TO
80 'js' => array(
81 'js/angular-crmMailingAB.js',
edb34488 82 'js/angular-crmMailingAB/*.js',
353ffa53 83 ),
4aef704e 84 'css' => array('css/angular-crmMailingAB.css'),
ad7abea2 85 'partials' => array('partials/crmMailingAB'),
4aef704e 86 );
d74bca86
TO
87 $result['crmD3'] = array(
88 'ext' => 'civicrm',
edb34488
TO
89 'js' => array(
90 'js/angular-crmD3.js',
91 'bower_components/d3/d3.min.js',
92 ),
d74bca86 93 );
983052fe 94
6bea4a47
TO
95 $session = CRM_Core_Session::singleton();
96 $contactID = $session->get('userID');
d979898e
CW
97
98 $params = array('options' => array('limit' => 0));
72dd949e
CW
99 $civiMails = civicrm_api3('Mailing', 'get', $params + array(
100 'is_completed' => 1,
101 'return' => array('id', 'name', 'scheduled_date'),
102 ));
d979898e 103 $campNames = civicrm_api3('Campaign', 'get', $params);
d979898e
CW
104 $groupNames = civicrm_api3('Group', 'get', $params);
105 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params);
6bea4a47 106
44a7c67d
TO
107 $emailAdd = civicrm_api3('Email', 'get', array(
108 'sequential' => 1,
109 'return' => "email",
110 'contact_id' => $contactID,
111 ));
d979898e 112 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
44a7c67d
TO
113 'sequential' => 1,
114 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"),
44a7c67d
TO
115 'workflow_id' => array('IS NULL' => ""),
116 ));
d979898e 117 $mailGrp = civicrm_api3('MailingGroup', 'get', $params);
1d280e03 118 $mailTokens = civicrm_api3('Mailing', 'gettokens', array('entity' => array('contact', 'mailing'), 'sequential' => 1));
d979898e
CW
119 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
120 'option_group_id' => "from_email_address",
4aef704e 121 ));
4aef704e 122 CRM_Core_Resources::singleton()->addSetting(array(
123 'crmMailing' => array(
124 'civiMails' => array_values($civiMails['values']),
125 'campNames' => array_values($campNames['values']),
4aef704e 126 'groupNames' => array_values($groupNames['values']),
127 'headerfooterList' => array_values($headerfooterList['values']),
128 'mesTemplate' => array_values($mesTemplate['values']),
129 'emailAdd' => array_values($emailAdd['values']),
6bea4a47 130 'mailGrp' => array_values($mailGrp['values']),
1d280e03 131 'mailTokens' => $mailTokens['values'],
6bea4a47 132 'contactid' => $contactID,
5f56e085 133 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
6098a966 134 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'),
d979898e 135 'fromAddress' => array_values($fromAddress['values']),
353ffa53
TO
136 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
137 'id' => 'user_contact_id',
317fceb4 138 'return' => 'email',
353ffa53 139 )),
92dd5fb3 140 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
9853619e 141 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
4aef704e 142 ),
143 ));
8f685a33
TO
144 CRM_Core_Resources::singleton()->addPermissions(array(
145 'view all contacts',
360d6097 146 'access CiviMail',
9853619e
TO
147 'create mailings',
148 'schedule mailings',
149 'approve mailings',
0fc156d9 150 'delete in CiviMail',
8f685a33 151 ));
983052fe 152
4aef704e 153 return $result;
154 }
983052fe 155
4aef704e 156 /**
e0ef6999
EM
157 * @return bool
158 */
00be9182 159 public static function workflowEnabled() {
6a488035
TO
160 $config = CRM_Core_Config::singleton();
161
162 // early exit, since not true for most
163 if (!$config->userSystem->is_drupal ||
164 !function_exists('module_exists')
165 ) {
166 return FALSE;
167 }
168
169 if (!module_exists('rules')) {
170 return FALSE;
171 }
172
173 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
174 'civimail_workflow',
175 NULL,
176 FALSE
177 );
178
179 return ($enableWorkflow &&
180 $config->userSystem->is_drupal
181 ) ? TRUE : FALSE;
182 }
183
e0ef6999 184 /**
e7c15cb6 185 * @inheritDoc
e0ef6999
EM
186 * @param bool $getAllUnconditionally
187 *
188 * @return array
189 */
33777e4a 190 public function getPermissions($getAllUnconditionally = FALSE) {
6a488035
TO
191 $permissions = array(
192 'access CiviMail',
193 'access CiviMail subscribe/unsubscribe pages',
194 'delete in CiviMail',
195 'view public CiviMail content',
196 );
197
33777e4a 198 if (self::workflowEnabled() || $getAllUnconditionally) {
6a488035
TO
199 $permissions[] = 'create mailings';
200 $permissions[] = 'schedule mailings';
201 $permissions[] = 'approve mailings';
202 }
203
204 return $permissions;
205 }
206
207
e0ef6999 208 /**
e7c15cb6 209 * @inheritDoc
e0ef6999
EM
210 * @return null
211 */
6a488035
TO
212 public function getUserDashboardElement() {
213 // no dashboard element for this component
214 return NULL;
215 }
216
e0ef6999
EM
217 /**
218 * @return null
219 */
6a488035
TO
220 public function getUserDashboardObject() {
221 // no dashboard element for this component
222 return NULL;
223 }
224
e0ef6999 225 /**
e7c15cb6 226 * @inheritDoc
e0ef6999
EM
227 * @return array
228 */
6a488035 229 public function registerTab() {
2ede60ec
DL
230 return array(
231 'title' => ts('Mailings'),
232 'id' => 'mailing',
233 'url' => 'mailing',
234 'weight' => 45,
235 );
6a488035
TO
236 }
237
e0ef6999 238 /**
e7c15cb6 239 * @inheritDoc
e0ef6999
EM
240 * @return array
241 */
6a488035 242 public function registerAdvancedSearchPane() {
35f7561f 243 return array(
353ffa53 244 'title' => ts('Mailings'),
6a488035
TO
245 'weight' => 20,
246 );
247 }
248
e0ef6999 249 /**
e7c15cb6 250 * @inheritDoc
e0ef6999
EM
251 * @return null
252 */
6a488035
TO
253 public function getActivityTypes() {
254 return NULL;
255 }
256
e0ef6999 257 /**
fe482240 258 * add shortcut to Create New.
e0ef6999
EM
259 * @param $shortCuts
260 */
35f7561f
TO
261 public function creatNewShortcut(&$shortCuts) {
262 }
96025800 263
6a488035 264}