3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
71 * @param $type 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();
93 $object = new CRM_Mailing_DAO_Component();
94 $object->component_type
= $type;
96 $object->selectAdd("id, name");
97 $object->orderBy('component_type, is_default, name');
98 $object->is_active
= 1;
100 while ($object->fetch()) {
101 self
::$component[$name][$object->id
] = $object->name
;
105 return self
::$component[$name];
109 * Determine the default mailing component of a given type
111 * @param $type the type of component needed
112 * @param $undefined 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
142 * @return array - array reference of all mailing templates if any
145 public static function &template() {
146 if (!self
::$template) {
147 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
149 return self
::$template;
153 * 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 '), 'Y' => ts('Bounced '),
190 'delivered' => array(
191 'Y' => ts('Successful '), 'N' => ts('Bounced '),
194 'Y' => ts('Opened '), 'N' => ts('Unopened/Hidden '),
197 'Y' => ts('Clicked '), 'N' => ts('Not Clicked '),
200 'Y' => ts('Replied '), 'N' => ts('No Reply '),
204 return $options[$field];
208 * Flush given pseudoconstant so it can be reread from db
209 * next time it's requested.
214 * @param boolean $name pseudoconstant to be flushed
217 public static function flush($name = 'template') {
218 if (isset(self
::$
$name)) {