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