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