3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class holds all the Pseudo constants that are specific to Mass mailing. This avoids
20 * polluting the core class and isolates the mass mailer class.
22 class CRM_Mailing_PseudoConstant
extends CRM_Core_PseudoConstant
{
25 * Status options for A/B tests.
28 private static $abStatus;
31 * Test criteria for A/B tests.
34 private static $abTestCriteria;
37 * Winner criteria for A/B tests.
40 private static $abWinnerCriteria;
46 private static $template;
52 private static $completed;
58 private static $component;
61 * Default component id's, indexed by component type
64 private static $defaultComponent;
70 private static $mailingTypes;
75 public static function abStatus() {
76 if (!is_array(self
::$abStatus)) {
78 'Draft' => ts('Draft'),
79 'Testing' => ts('Testing'),
80 'Final' => ts('Final'),
83 return self
::$abStatus;
89 public static function abTestCriteria() {
90 if (!is_array(self
::$abTestCriteria)) {
91 self
::$abTestCriteria = [
92 'subject' => ts('Test different "Subject" lines'),
93 'from' => ts('Test different "From" lines'),
94 'full_email' => ts('Test entirely different emails'),
97 return self
::$abTestCriteria;
103 public static function abWinnerCriteria() {
104 if (!is_array(self
::$abWinnerCriteria)) {
105 self
::$abWinnerCriteria = [
106 'open' => ts('Open'),
107 'unique_click' => ts('Total Unique Clicks'),
108 'link_click' => ts('Total Clicks on a particular link'),
111 return self
::$abWinnerCriteria;
117 public static function mailingTypes() {
118 if (!is_array(self
::$mailingTypes)) {
119 self
::$mailingTypes = [
120 'standalone' => ts('Standalone'),
121 'experiment' => ts('Experimental'),
122 'winner' => ts('Winner'),
125 return self
::$mailingTypes;
129 * Get all the mailing components of a particular type.
132 * The type of component needed.
135 * array reference of all mailing components
137 public static function &component($type = NULL) {
138 $name = $type ?
$type : 'ALL';
140 if (!self
::$component ||
!array_key_exists($name, self
::$component)) {
141 if (!self
::$component) {
142 self
::$component = [];
145 self
::$component[$name] = NULL;
146 CRM_Core_PseudoConstant
::populate(self
::$component[$name], 'CRM_Mailing_BAO_MailingComponent');
149 // we need to add an additional filter for $type
150 self
::$component[$name] = [];
152 $object = new CRM_Mailing_BAO_MailingComponent();
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;
159 while ($object->fetch()) {
160 self
::$component[$name][$object->id
] = $object->name
;
164 return self
::$component[$name];
168 * Determine the default mailing component of a given type.
171 * The type of component needed.
173 * The value to use if no default is defined.
176 * The ID of the default mailing component.
178 public static function &defaultComponent($type, $undefined = NULL) {
179 if (!self
::$defaultComponent) {
180 $queryDefaultComponents = "SELECT id, component_type
181 FROM civicrm_mailing_component
184 GROUP BY component_type, id";
186 $dao = CRM_Core_DAO
::executeQuery($queryDefaultComponents);
188 self
::$defaultComponent = [];
189 while ($dao->fetch()) {
190 self
::$defaultComponent[$dao->component_type
] = $dao->id
;
193 $value = CRM_Utils_Array
::value($type, self
::$defaultComponent, $undefined);
198 * Get all the mailing templates.
202 * array reference of all mailing templates if any
204 public static function &template() {
205 if (!self
::$template) {
206 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
208 return self
::$template;
212 * Get all the completed mailing.
218 * array reference of all mailing templates if any
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 " : "";
225 CRM_Core_PseudoConstant
::populate(self
::$completed,
226 'CRM_Mailing_DAO_Mailing',
233 return self
::$completed;
237 * Labels for advanced search against mailing summary.
241 * @return unknown_type
243 public static function &yesNoOptions($field) {
248 'N' => ts('Successful '),
249 'Y' => ts('Bounced '),
252 'Y' => ts('Successful '),
253 'N' => ts('Bounced '),
256 'Y' => ts('Opened '),
257 'N' => ts('Unopened/Hidden '),
260 'Y' => ts('Clicked '),
261 'N' => ts('Not Clicked '),
264 'Y' => ts('Replied '),
265 'N' => ts('No Reply '),
269 return $options[$field];
273 * Flush given pseudoconstant so it can be reread from db
274 * next time it's requested.
277 * @param bool|string $name pseudoconstant to be flushed
279 public static function flush($name = 'template') {
280 if (isset(self
::$
$name)) {