Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class holds all the Pseudo constants that are specific to Mass mailing. This avoids | |
25606795 | 36 | * polluting the core class and isolates the mass mailer class. |
6a488035 TO |
37 | */ |
38 | class CRM_Mailing_PseudoConstant extends CRM_Core_PseudoConstant { | |
39 | ||
321121a1 TO |
40 | /** |
41 | * Status options for A/B tests. | |
42 | * @var array | |
43 | */ | |
44 | private static $abStatus; | |
45 | ||
46 | /** | |
47 | * Test criteria for A/B tests. | |
48 | * @var array | |
49 | */ | |
50 | private static $abTestCriteria; | |
51 | ||
52 | /** | |
53 | * Winner criteria for A/B tests. | |
54 | * @var array | |
55 | */ | |
56 | private static $abWinnerCriteria; | |
57 | ||
6a488035 | 58 | /** |
100fef9d | 59 | * Mailing templates |
6a488035 | 60 | * @var array |
6a488035 TO |
61 | */ |
62 | private static $template; | |
63 | ||
64 | /** | |
100fef9d | 65 | * Completed mailings |
6a488035 | 66 | * @var array |
6a488035 TO |
67 | */ |
68 | private static $completed; | |
69 | ||
70 | /** | |
100fef9d | 71 | * Mailing components |
6a488035 | 72 | * @var array |
6a488035 TO |
73 | */ |
74 | private static $component; | |
75 | ||
76 | /** | |
100fef9d | 77 | * Default component id's, indexed by component type |
6a488035 TO |
78 | */ |
79 | private static $defaultComponent; | |
80 | ||
e81bac46 | 81 | /** |
82 | * Mailing Types | |
83 | * @var array | |
84 | */ | |
85 | private static $mailingTypes; | |
86 | ||
321121a1 TO |
87 | /** |
88 | * @return array | |
89 | */ | |
90 | public static function abStatus() { | |
91 | if (!is_array(self::$abStatus)) { | |
92 | self::$abStatus = array( | |
93 | 'Draft' => ts('Draft'), | |
94 | 'Testing' => ts('Testing'), | |
95 | 'Final' => ts('Final'), | |
96 | ); | |
97 | } | |
98 | return self::$abStatus; | |
99 | } | |
100 | ||
101 | /** | |
102 | * @return array | |
103 | */ | |
104 | public static function abTestCriteria() { | |
105 | if (!is_array(self::$abTestCriteria)) { | |
106 | self::$abTestCriteria = array( | |
107 | 'subject' => ts('Test different "Subject" lines'), | |
108 | 'from' => ts('Test different "From" lines'), | |
109 | 'full_email' => ts('Test entirely different emails'), | |
110 | ); | |
111 | } | |
112 | return self::$abTestCriteria; | |
113 | } | |
114 | ||
115 | /** | |
116 | * @return array | |
117 | */ | |
118 | public static function abWinnerCriteria() { | |
119 | if (!is_array(self::$abWinnerCriteria)) { | |
120 | self::$abWinnerCriteria = array( | |
121 | 'open' => ts('Open'), | |
122 | 'unique_click' => ts('Total Unique Clicks'), | |
123 | 'link_click' => ts('Total Clicks on a particular link'), | |
124 | ); | |
125 | } | |
126 | return self::$abWinnerCriteria; | |
127 | } | |
128 | ||
e81bac46 | 129 | /** |
130 | * @return array | |
131 | */ | |
132 | public static function mailingTypes() { | |
133 | if (!is_array(self::$mailingTypes)) { | |
134 | self::$mailingTypes = array( | |
135 | 'standalone' => ts('Standalone'), | |
136 | 'experiment' => ts('Experimental'), | |
137 | 'winner' => ts('Winner'), | |
138 | ); | |
139 | } | |
140 | return self::$mailingTypes; | |
141 | } | |
142 | ||
6a488035 | 143 | /** |
fe482240 | 144 | * Get all the mailing components of a particular type. |
6a488035 | 145 | * |
90c8230e TO |
146 | * @param $type |
147 | * The type of component needed. | |
6a488035 | 148 | * |
a6c01b45 CW |
149 | * @return array |
150 | * array reference of all mailing components | |
6a488035 TO |
151 | */ |
152 | public static function &component($type = NULL) { | |
153 | $name = $type ? $type : 'ALL'; | |
154 | ||
155 | if (!self::$component || !array_key_exists($name, self::$component)) { | |
156 | if (!self::$component) { | |
157 | self::$component = array(); | |
158 | } | |
159 | if (!$type) { | |
160 | self::$component[$name] = NULL; | |
161 | CRM_Core_PseudoConstant::populate(self::$component[$name], 'CRM_Mailing_DAO_Component'); | |
162 | } | |
163 | else { | |
164 | // we need to add an additional filter for $type | |
165 | self::$component[$name] = array(); | |
166 | ||
6a488035 TO |
167 | $object = new CRM_Mailing_DAO_Component(); |
168 | $object->component_type = $type; | |
169 | $object->selectAdd(); | |
170 | $object->selectAdd("id, name"); | |
171 | $object->orderBy('component_type, is_default, name'); | |
172 | $object->is_active = 1; | |
173 | $object->find(); | |
174 | while ($object->fetch()) { | |
175 | self::$component[$name][$object->id] = $object->name; | |
176 | } | |
177 | } | |
178 | } | |
179 | return self::$component[$name]; | |
180 | } | |
181 | ||
182 | /** | |
fe482240 | 183 | * Determine the default mailing component of a given type. |
6a488035 | 184 | * |
90c8230e TO |
185 | * @param $type |
186 | * The type of component needed. | |
187 | * @param $undefined | |
188 | * The value to use if no default is defined. | |
6a488035 | 189 | * |
df8d3074 | 190 | * @return int |
a6c01b45 | 191 | * The ID of the default mailing component. |
6a488035 TO |
192 | */ |
193 | public static function &defaultComponent($type, $undefined = NULL) { | |
194 | if (!self::$defaultComponent) { | |
195 | $queryDefaultComponents = "SELECT id, component_type | |
196 | FROM civicrm_mailing_component | |
197 | WHERE is_active = 1 | |
198 | AND is_default = 1 | |
199 | GROUP BY component_type"; | |
200 | ||
201 | $dao = CRM_Core_DAO::executeQuery($queryDefaultComponents); | |
202 | ||
203 | self::$defaultComponent = array(); | |
204 | while ($dao->fetch()) { | |
205 | self::$defaultComponent[$dao->component_type] = $dao->id; | |
206 | } | |
207 | } | |
208 | $value = CRM_Utils_Array::value($type, self::$defaultComponent, $undefined); | |
209 | return $value; | |
210 | } | |
211 | ||
212 | /** | |
fe482240 | 213 | * Get all the mailing templates. |
6a488035 | 214 | * |
6a488035 | 215 | * |
a6c01b45 CW |
216 | * @return array |
217 | * array reference of all mailing templates if any | |
6a488035 TO |
218 | */ |
219 | public static function &template() { | |
220 | if (!self::$template) { | |
221 | CRM_Core_PseudoConstant::populate(self::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template'); | |
222 | } | |
223 | return self::$template; | |
224 | } | |
225 | ||
226 | /** | |
fe482240 | 227 | * Get all the completed mailing. |
6a488035 | 228 | * |
6a488035 | 229 | * |
da6b46f4 EM |
230 | * @param null $mode |
231 | * | |
a6c01b45 CW |
232 | * @return array |
233 | * array reference of all mailing templates if any | |
6a488035 TO |
234 | */ |
235 | public static function &completed($mode = NULL) { | |
236 | if (!self::$completed) { | |
237 | $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL(); | |
238 | $mailingACL .= $mode == 'sms' ? " AND sms_provider_id IS NOT NULL " : ""; | |
239 | ||
240 | CRM_Core_PseudoConstant::populate(self::$completed, | |
241 | 'CRM_Mailing_DAO_Mailing', | |
242 | FALSE, | |
243 | 'name', | |
244 | 'is_completed', | |
245 | $mailingACL | |
246 | ); | |
247 | } | |
248 | return self::$completed; | |
249 | } | |
250 | ||
6a488035 TO |
251 | /** |
252 | * Labels for advanced search against mailing summary. | |
253 | * | |
254 | * @param $field | |
255 | * | |
256 | * @return unknown_type | |
257 | */ | |
258 | public static function &yesNoOptions($field) { | |
259 | static $options; | |
260 | if (!$options) { | |
261 | $options = array( | |
262 | 'bounce' => array( | |
35f7561f | 263 | 'N' => ts('Successful '), |
353ffa53 | 264 | 'Y' => ts('Bounced '), |
6a488035 TO |
265 | ), |
266 | 'delivered' => array( | |
35f7561f | 267 | 'Y' => ts('Successful '), |
353ffa53 | 268 | 'N' => ts('Bounced '), |
6a488035 TO |
269 | ), |
270 | 'open' => array( | |
35f7561f | 271 | 'Y' => ts('Opened '), |
353ffa53 | 272 | 'N' => ts('Unopened/Hidden '), |
6a488035 TO |
273 | ), |
274 | 'click' => array( | |
35f7561f | 275 | 'Y' => ts('Clicked '), |
353ffa53 | 276 | 'N' => ts('Not Clicked '), |
6a488035 TO |
277 | ), |
278 | 'reply' => array( | |
35f7561f | 279 | 'Y' => ts('Replied '), |
353ffa53 | 280 | 'N' => ts('No Reply '), |
6a488035 TO |
281 | ), |
282 | ); | |
283 | } | |
284 | return $options[$field]; | |
285 | } | |
286 | ||
287 | /** | |
288 | * Flush given pseudoconstant so it can be reread from db | |
6ce01b02 | 289 | * next time it's requested. |
6a488035 | 290 | * |
6a488035 | 291 | * |
da6b46f4 | 292 | * @param bool|string $name pseudoconstant to be flushed |
6a488035 | 293 | */ |
6ce01b02 | 294 | public static function flush($name = 'template') { |
35f7561f | 295 | if (isset(self::$$name)) { |
fa56270d CW |
296 | self::$$name = NULL; |
297 | } | |
6a488035 | 298 | } |
96025800 | 299 | |
6a488035 | 300 | } |