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