3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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
79 private static $defaultComponent;
85 private static $mailingTypes;
90 public static function abStatus() {
91 if (!is_array(self
::$abStatus)) {
92 self
::$abStatus = array(
93 'Draft' => ts('Draft'),
94 'Testing' => ts('Testing'),
95 'Final' => ts('Final'),
98 return self
::$abStatus;
104 public static function abTestCriteria() {
105 if (!is_array(self
::$abTestCriteria)) {
106 self
::$abTestCriteria = array(
107 'subject' => ts('Test different "Subject" lines'),
108 'from' => ts('Test different "From" lines'),
109 'full_email' => ts('Test entirely different emails'),
112 return self
::$abTestCriteria;
118 public static function abWinnerCriteria() {
119 if (!is_array(self
::$abWinnerCriteria)) {
120 self
::$abWinnerCriteria = array(
121 'open' => ts('Open'),
122 'unique_click' => ts('Total Unique Clicks'),
123 'link_click' => ts('Total Clicks on a particular link'),
126 return self
::$abWinnerCriteria;
132 public static function mailingTypes() {
133 if (!is_array(self
::$mailingTypes)) {
134 self
::$mailingTypes = array(
135 'standalone' => ts('Standalone'),
136 'experiment' => ts('Experimental'),
137 'winner' => ts('Winner'),
140 return self
::$mailingTypes;
144 * Get all the mailing components of a particular type.
147 * The type of component needed.
150 * array reference of all mailing components
152 public static function &component($type = NULL) {
153 $name = $type ?
$type : 'ALL';
155 if (!self
::$component ||
!array_key_exists($name, self
::$component)) {
156 if (!self
::$component) {
157 self
::$component = array();
160 self
::$component[$name] = NULL;
161 CRM_Core_PseudoConstant
::populate(self
::$component[$name], 'CRM_Mailing_DAO_Component');
164 // we need to add an additional filter for $type
165 self
::$component[$name] = array();
167 $object = new CRM_Mailing_DAO_Component();
168 $object->component_type
= $type;
169 $object->selectAdd();
170 $object->selectAdd("id, name");
171 $object->orderBy('component_type, is_default, name');
172 $object->is_active
= 1;
174 while ($object->fetch()) {
175 self
::$component[$name][$object->id
] = $object->name
;
179 return self
::$component[$name];
183 * Determine the default mailing component of a given type.
186 * The type of component needed.
188 * The value to use if no default is defined.
191 * The ID of the default mailing component.
193 public static function &defaultComponent($type, $undefined = NULL) {
194 if (!self
::$defaultComponent) {
195 $queryDefaultComponents = "SELECT id, component_type
196 FROM civicrm_mailing_component
199 GROUP BY component_type, id";
201 $dao = CRM_Core_DAO
::executeQuery($queryDefaultComponents);
203 self
::$defaultComponent = array();
204 while ($dao->fetch()) {
205 self
::$defaultComponent[$dao->component_type
] = $dao->id
;
208 $value = CRM_Utils_Array
::value($type, self
::$defaultComponent, $undefined);
213 * Get all the mailing templates.
217 * array reference of all mailing templates if any
219 public static function &template() {
220 if (!self
::$template) {
221 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
223 return self
::$template;
227 * Get all the completed mailing.
233 * array reference of all mailing templates if any
235 public static function &completed($mode = NULL) {
236 if (!self
::$completed) {
237 $mailingACL = CRM_Mailing_BAO_Mailing
::mailingACL();
238 $mailingACL .= $mode == 'sms' ?
" AND sms_provider_id IS NOT NULL " : "";
240 CRM_Core_PseudoConstant
::populate(self
::$completed,
241 'CRM_Mailing_DAO_Mailing',
248 return self
::$completed;
252 * Labels for advanced search against mailing summary.
256 * @return unknown_type
258 public static function &yesNoOptions($field) {
263 'N' => ts('Successful '),
264 'Y' => ts('Bounced '),
266 'delivered' => array(
267 'Y' => ts('Successful '),
268 'N' => ts('Bounced '),
271 'Y' => ts('Opened '),
272 'N' => ts('Unopened/Hidden '),
275 'Y' => ts('Clicked '),
276 'N' => ts('Not Clicked '),
279 'Y' => ts('Replied '),
280 'N' => ts('No Reply '),
284 return $options[$field];
288 * Flush given pseudoconstant so it can be reread from db
289 * next time it's requested.
292 * @param bool|string $name pseudoconstant to be flushed
294 public static function flush($name = 'template') {
295 if (isset(self
::$
$name)) {