3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class holds all the Pseudo constants that are specific to Mass mailing. This avoids
36 * polluting the core class and isolates the mass mailer class.
38 class CRM_Mailing_PseudoConstant
extends CRM_Core_PseudoConstant
{
41 * Status options for A/B tests.
44 private static $abStatus;
47 * Test criteria for A/B tests.
50 private static $abTestCriteria;
53 * Winner criteria for A/B tests.
56 private static $abWinnerCriteria;
62 private static $template;
68 private static $completed;
74 private static $component;
77 * Default component id's, indexed by component type
80 private static $defaultComponent;
86 private static $mailingTypes;
91 public static function abStatus() {
92 if (!is_array(self
::$abStatus)) {
94 'Draft' => ts('Draft'),
95 'Testing' => ts('Testing'),
96 'Final' => ts('Final'),
99 return self
::$abStatus;
105 public static function abTestCriteria() {
106 if (!is_array(self
::$abTestCriteria)) {
107 self
::$abTestCriteria = [
108 'subject' => ts('Test different "Subject" lines'),
109 'from' => ts('Test different "From" lines'),
110 'full_email' => ts('Test entirely different emails'),
113 return self
::$abTestCriteria;
119 public static function abWinnerCriteria() {
120 if (!is_array(self
::$abWinnerCriteria)) {
121 self
::$abWinnerCriteria = [
122 'open' => ts('Open'),
123 'unique_click' => ts('Total Unique Clicks'),
124 'link_click' => ts('Total Clicks on a particular link'),
127 return self
::$abWinnerCriteria;
133 public static function mailingTypes() {
134 if (!is_array(self
::$mailingTypes)) {
135 self
::$mailingTypes = [
136 'standalone' => ts('Standalone'),
137 'experiment' => ts('Experimental'),
138 'winner' => ts('Winner'),
141 return self
::$mailingTypes;
145 * Get all the mailing components of a particular type.
148 * The type of component needed.
151 * array reference of all mailing components
153 public static function &component($type = NULL) {
154 $name = $type ?
$type : 'ALL';
156 if (!self
::$component ||
!array_key_exists($name, self
::$component)) {
157 if (!self
::$component) {
158 self
::$component = [];
161 self
::$component[$name] = NULL;
162 CRM_Core_PseudoConstant
::populate(self
::$component[$name], 'CRM_Mailing_BAO_MailingComponent');
165 // we need to add an additional filter for $type
166 self
::$component[$name] = [];
168 $object = new CRM_Mailing_BAO_MailingComponent();
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;
175 while ($object->fetch()) {
176 self
::$component[$name][$object->id
] = $object->name
;
180 return self
::$component[$name];
184 * Determine the default mailing component of a given type.
187 * The type of component needed.
189 * The value to use if no default is defined.
192 * The ID of the default mailing component.
194 public static function &defaultComponent($type, $undefined = NULL) {
195 if (!self
::$defaultComponent) {
196 $queryDefaultComponents = "SELECT id, component_type
197 FROM civicrm_mailing_component
200 GROUP BY component_type, id";
202 $dao = CRM_Core_DAO
::executeQuery($queryDefaultComponents);
204 self
::$defaultComponent = [];
205 while ($dao->fetch()) {
206 self
::$defaultComponent[$dao->component_type
] = $dao->id
;
209 $value = CRM_Utils_Array
::value($type, self
::$defaultComponent, $undefined);
214 * Get all the mailing templates.
218 * array reference of all mailing templates if any
220 public static function &template() {
221 if (!self
::$template) {
222 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
224 return self
::$template;
228 * Get all the completed mailing.
234 * array reference of all mailing templates if any
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 " : "";
241 CRM_Core_PseudoConstant
::populate(self
::$completed,
242 'CRM_Mailing_DAO_Mailing',
249 return self
::$completed;
253 * Labels for advanced search against mailing summary.
257 * @return unknown_type
259 public static function &yesNoOptions($field) {
264 'N' => ts('Successful '),
265 'Y' => ts('Bounced '),
268 'Y' => ts('Successful '),
269 'N' => ts('Bounced '),
272 'Y' => ts('Opened '),
273 'N' => ts('Unopened/Hidden '),
276 'Y' => ts('Clicked '),
277 'N' => ts('Not Clicked '),
280 'Y' => ts('Replied '),
281 'N' => ts('No Reply '),
285 return $options[$field];
289 * Flush given pseudoconstant so it can be reread from db
290 * next time it's requested.
293 * @param bool|string $name pseudoconstant to be flushed
295 public static function flush($name = 'template') {
296 if (isset(self
::$
$name)) {