CRM-16063 - CiviMail - Get full list of active mailin components.
[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 'is_active' => 1,
105 'options' => array(
106 'limit' => 0,
107 ),
108 ));
109
110 $emailAdd = civicrm_api3('Email', 'get', array(
111 'sequential' => 1,
112 'return' => "email",
113 'contact_id' => $contactID,
114 ));
115 $mesTemplate = civicrm_api3('MessageTemplate', 'get', array(
116 'sequential' => 1,
117 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"),
118 'is_active' => 1,
119 'workflow_id' => array('IS NULL' => ""),
120 ));
121 $mailGrp = civicrm_api3('MailingGroup', 'get', array());
122 $mailTokens = civicrm_api3('Mailing', 'gettokens', array('entity' => array('contact', 'mailing'), 'sequential' => 1));
123 $fromAddress = civicrm_api3('OptionGroup', 'get', array(
124 'sequential' => 1,
125 'name' => "from_email_address",
126 'api.OptionValue.get' => array(),
127 ));
128 CRM_Core_Resources::singleton()->addSetting(array(
129 'crmMailing' => array(
130 'mailingabNames' => array_values($mailingabNames['values']),
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']),
138 'mailGrp' => array_values($mailGrp['values']),
139 'mailTokens' => $mailTokens['values'],
140 'contactid' => $contactID,
141 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
142 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'),
143 'fromAddress' => array_values($fromAddress['values'][0]['api.OptionValue.get']['values']),
144 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
145 'id' => 'user_contact_id',
146 'return' => 'email',
147 )),
148 'visibility' => array(
149 array('value' => 'Public Pages', 'label' => ts('Public Pages')),
150 array('value' => 'User and User Admin Only', 'label' => ts('User and User Admin Only')),
151 ),
152 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
153 ),
154 ));
155 CRM_Core_Resources::singleton()->addPermissions(array(
156 'view all contacts',
157 'access CiviMail',
158 'create mailings',
159 'schedule mailings',
160 'approve mailings',
161 'delete in CiviMail',
162 ));
163
164 return $result;
165 }
166
167 /**
168 * @return bool
169 */
170 public static function workflowEnabled() {
171 $config = CRM_Core_Config::singleton();
172
173 // early exit, since not true for most
174 if (!$config->userSystem->is_drupal ||
175 !function_exists('module_exists')
176 ) {
177 return FALSE;
178 }
179
180 if (!module_exists('rules')) {
181 return FALSE;
182 }
183
184 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
185 'civimail_workflow',
186 NULL,
187 FALSE
188 );
189
190 return ($enableWorkflow &&
191 $config->userSystem->is_drupal
192 ) ? TRUE : FALSE;
193 }
194
195 /**
196 * @inheritDoc
197 * @param bool $getAllUnconditionally
198 *
199 * @return array
200 */
201 public function getPermissions($getAllUnconditionally = FALSE) {
202 $permissions = array(
203 'access CiviMail',
204 'access CiviMail subscribe/unsubscribe pages',
205 'delete in CiviMail',
206 'view public CiviMail content',
207 );
208
209 if (self::workflowEnabled() || $getAllUnconditionally) {
210 $permissions[] = 'create mailings';
211 $permissions[] = 'schedule mailings';
212 $permissions[] = 'approve mailings';
213 }
214
215 return $permissions;
216 }
217
218
219 /**
220 * @inheritDoc
221 * @return null
222 */
223 public function getUserDashboardElement() {
224 // no dashboard element for this component
225 return NULL;
226 }
227
228 /**
229 * @return null
230 */
231 public function getUserDashboardObject() {
232 // no dashboard element for this component
233 return NULL;
234 }
235
236 /**
237 * @inheritDoc
238 * @return array
239 */
240 public function registerTab() {
241 return array(
242 'title' => ts('Mailings'),
243 'id' => 'mailing',
244 'url' => 'mailing',
245 'weight' => 45,
246 );
247 }
248
249 /**
250 * @inheritDoc
251 * @return array
252 */
253 public function registerAdvancedSearchPane() {
254 return array(
255 'title' => ts('Mailings'),
256 'weight' => 20,
257 );
258 }
259
260 /**
261 * @inheritDoc
262 * @return null
263 */
264 public function getActivityTypes() {
265 return NULL;
266 }
267
268 /**
269 * add shortcut to Create New.
270 * @param $shortCuts
271 */
272 public function creatNewShortcut(&$shortCuts) {
273 }
274
275 }