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
{
47 private static $template;
54 private static $completed;
61 private static $component;
64 * Default component id's, indexed by component type
66 private static $defaultComponent;
69 * Get all the mailing components of a particular type
72 * The type of component needed.
74 * @return array - array reference of all mailing components
77 public static function &component($type = NULL) {
78 $name = $type ?
$type : 'ALL';
80 if (!self
::$component ||
!array_key_exists($name, self
::$component)) {
81 if (!self
::$component) {
82 self
::$component = array();
85 self
::$component[$name] = NULL;
86 CRM_Core_PseudoConstant
::populate(self
::$component[$name], 'CRM_Mailing_DAO_Component');
89 // we need to add an additional filter for $type
90 self
::$component[$name] = array();
92 $object = new CRM_Mailing_DAO_Component();
93 $object->component_type
= $type;
95 $object->selectAdd("id, name");
96 $object->orderBy('component_type, is_default, name');
97 $object->is_active
= 1;
99 while ($object->fetch()) {
100 self
::$component[$name][$object->id
] = $object->name
;
104 return self
::$component[$name];
108 * Determine the default mailing component of a given type
111 * The type of component needed.
113 * The value to use if no default is defined.
115 * @return integer -The ID of the default mailing component.
118 public static function &defaultComponent($type, $undefined = NULL) {
119 if (!self
::$defaultComponent) {
120 $queryDefaultComponents = "SELECT id, component_type
121 FROM civicrm_mailing_component
124 GROUP BY component_type";
126 $dao = CRM_Core_DAO
::executeQuery($queryDefaultComponents);
128 self
::$defaultComponent = array();
129 while ($dao->fetch()) {
130 self
::$defaultComponent[$dao->component_type
] = $dao->id
;
133 $value = CRM_Utils_Array
::value($type, self
::$defaultComponent, $undefined);
138 * Get all the mailing templates
141 * @return array - array reference of all mailing templates if any
144 public static function &template() {
145 if (!self
::$template) {
146 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
148 return self
::$template;
152 * Get all the completed mailing
157 * @return array - array reference of all mailing templates if any
160 public static function &completed($mode = NULL) {
161 if (!self
::$completed) {
162 $mailingACL = CRM_Mailing_BAO_Mailing
::mailingACL();
163 $mailingACL .= $mode == 'sms' ?
" AND sms_provider_id IS NOT NULL " : "";
165 CRM_Core_PseudoConstant
::populate(self
::$completed,
166 'CRM_Mailing_DAO_Mailing',
173 return self
::$completed;
177 * Labels for advanced search against mailing summary.
181 * @return unknown_type
183 public static function &yesNoOptions($field) {
188 'N' => ts('Successful '),
189 'Y' => ts('Bounced '),
191 'delivered' => array(
192 'Y' => ts('Successful '),
193 'N' => ts('Bounced '),
196 'Y' => ts('Opened '),
197 'N' => ts('Unopened/Hidden '),
200 'Y' => ts('Clicked '),
201 'N' => ts('Not Clicked '),
204 'Y' => ts('Replied '),
205 'N' => ts('No Reply '),
209 return $options[$field];
213 * Flush given pseudoconstant so it can be reread from db
214 * next time it's requested.
218 * @param bool|string $name pseudoconstant to be flushed
220 public static function flush($name = 'template') {
221 if (isset(self
::$
$name)) {