gorups working final
[civicrm-core.git] / CRM / Mailing / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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-newMailing.js' , 'js/angularsanitize.js'),
63 );
64 $session = CRM_Core_Session::singleton();
65 $contactID = $session->get('userID');
66 $civiMails = civicrm_api3('Mailing', 'get', array());
67 $campNames = civicrm_api3('Campaign', 'get', array());
68 $mailStatus = civicrm_api3('MailingJob', 'get', array());
69 $groupNames = civicrm_api3('Group', 'get', array());
70 $headerfooterList = civicrm_api3('MailingComponent', 'get', array());
71 $emailAdd = civicrm_api3('Email', 'get', array(
72 'sequential' => 1,
73 'return' => "email",
74 'contact_id' => $contactID,
75 ));
76 $mesTemplate = civicrm_api3('MessageTemplate', 'get', array( 'sequential' => 1,
77 'return' => array("msg_html", "id", "msg_title", "msg_subject"),
78 'workflow_id' => array('IS NULL' => ""),
79 ));
80 $mailGrp = civicrm_api3('MailingGroup','get', array());
81 $mailTokens = civicrm_api3('Mailing', 'get_token', array( 'usage' => 'Mailing'));
82
83
84
85 CRM_Core_Resources::singleton()->addSetting(array(
86 'crmMailing' => array(
87 'civiMails' => array_values($civiMails['values']),
88 'campNames' => array_values($campNames['values']),
89 'mailStatus' => array_values($mailStatus['values']),
90 'groupNames' => array_values($groupNames['values']),
91 'headerfooterList' => array_values($headerfooterList['values']),
92 'mesTemplate' => array_values($mesTemplate['values']),
93 'emailAdd' => array_values($emailAdd['values']),
94 'mailGrp' => array_values($mailGrp['values']),
95 'mailTokens' => array_values($mailTokens),
96 'contactid' => $contactID
97 ),
98 ));
99 return $result;
100 }
101
102 /**
103 * @return bool
104 */
105 static function workflowEnabled() {
106 $config = CRM_Core_Config::singleton();
107
108 // early exit, since not true for most
109 if (!$config->userSystem->is_drupal ||
110 !function_exists('module_exists')
111 ) {
112 return FALSE;
113 }
114
115 if (!module_exists('rules')) {
116 return FALSE;
117 }
118
119 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
120 'civimail_workflow',
121 NULL,
122 FALSE
123 );
124
125 return ($enableWorkflow &&
126 $config->userSystem->is_drupal
127 ) ? TRUE : FALSE;
128 }
129
130 // docs inherited from interface
131 /**
132 * @param bool $getAllUnconditionally
133 *
134 * @return array
135 */
136 public function getPermissions($getAllUnconditionally = FALSE) {
137 $permissions = array(
138 'access CiviMail',
139 'access CiviMail subscribe/unsubscribe pages',
140 'delete in CiviMail',
141 'view public CiviMail content',
142 );
143
144 if (self::workflowEnabled() || $getAllUnconditionally) {
145 $permissions[] = 'create mailings';
146 $permissions[] = 'schedule mailings';
147 $permissions[] = 'approve mailings';
148 }
149
150 return $permissions;
151 }
152
153
154 // docs inherited from interface
155 /**
156 * @return null
157 */
158 public function getUserDashboardElement() {
159 // no dashboard element for this component
160 return NULL;
161 }
162
163 /**
164 * @return null
165 */
166 public function getUserDashboardObject() {
167 // no dashboard element for this component
168 return NULL;
169 }
170
171 // docs inherited from interface
172 /**
173 * @return array
174 */
175 public function registerTab() {
176 return array(
177 'title' => ts('Mailings'),
178 'id' => 'mailing',
179 'url' => 'mailing',
180 'weight' => 45,
181 );
182 }
183
184 // docs inherited from interface
185 /**
186 * @return array
187 */
188 public function registerAdvancedSearchPane() {
189 return array('title' => ts('Mailings'),
190 'weight' => 20,
191 );
192 }
193
194 // docs inherited from interface
195 /**
196 * @return null
197 */
198 public function getActivityTypes() {
199 return NULL;
200 }
201
202 // add shortcut to Create New
203 /**
204 * @param $shortCuts
205 */
206 public function creatNewShortcut(&$shortCuts) {}
207 }
208