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