3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
40 class CRM_Mailing_PseudoConstant
extends CRM_Core_PseudoConstant
{
43 * Status options for A/B tests.
46 private static $abStatus;
49 * Test criteria for A/B tests.
52 private static $abTestCriteria;
55 * Winner criteria for A/B tests.
58 private static $abWinnerCriteria;
64 private static $template;
70 private static $completed;
76 private static $component;
79 * Default component id's, indexed by component type
81 private static $defaultComponent;
87 private static $mailingTypes;
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'),
100 return self
::$abStatus;
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'),
114 return self
::$abTestCriteria;
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'),
128 return self
::$abWinnerCriteria;
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'),
142 return self
::$mailingTypes;
146 * Get all the mailing components of a particular type.
149 * The type of component needed.
152 * array reference of all mailing components
154 public static function &component($type = NULL) {
155 $name = $type ?
$type : 'ALL';
157 if (!self
::$component ||
!array_key_exists($name, self
::$component)) {
158 if (!self
::$component) {
159 self
::$component = array();
162 self
::$component[$name] = NULL;
163 CRM_Core_PseudoConstant
::populate(self
::$component[$name], 'CRM_Mailing_DAO_Component');
166 // we need to add an additional filter for $type
167 self
::$component[$name] = array();
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;
176 while ($object->fetch()) {
177 self
::$component[$name][$object->id
] = $object->name
;
181 return self
::$component[$name];
185 * Determine the default mailing component of a given type.
188 * The type of component needed.
190 * The value to use if no default is defined.
193 * The ID of the default mailing component.
195 public static function &defaultComponent($type, $undefined = NULL) {
196 if (!self
::$defaultComponent) {
197 $queryDefaultComponents = "SELECT id, component_type
198 FROM civicrm_mailing_component
201 GROUP BY component_type";
203 $dao = CRM_Core_DAO
::executeQuery($queryDefaultComponents);
205 self
::$defaultComponent = array();
206 while ($dao->fetch()) {
207 self
::$defaultComponent[$dao->component_type
] = $dao->id
;
210 $value = CRM_Utils_Array
::value($type, self
::$defaultComponent, $undefined);
215 * Get all the mailing templates.
219 * array reference of all mailing templates if any
221 public static function &template() {
222 if (!self
::$template) {
223 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
225 return self
::$template;
229 * Get all the completed mailing.
235 * array reference of all mailing templates if any
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 " : "";
242 CRM_Core_PseudoConstant
::populate(self
::$completed,
243 'CRM_Mailing_DAO_Mailing',
250 return self
::$completed;
254 * Labels for advanced search against mailing summary.
258 * @return unknown_type
260 public static function &yesNoOptions($field) {
265 'N' => ts('Successful '),
266 'Y' => ts('Bounced '),
268 'delivered' => array(
269 'Y' => ts('Successful '),
270 'N' => ts('Bounced '),
273 'Y' => ts('Opened '),
274 'N' => ts('Unopened/Hidden '),
277 'Y' => ts('Clicked '),
278 'N' => ts('Not Clicked '),
281 'Y' => ts('Replied '),
282 'N' => ts('No Reply '),
286 return $options[$field];
290 * Flush given pseudoconstant so it can be reread from db
291 * next time it's requested.
294 * @param bool|string $name pseudoconstant to be flushed
296 public static function flush($name = 'template') {
297 if (isset(self
::$
$name)) {