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
{
46 private static $template;
52 private static $completed;
58 private static $component;
61 * Default component id's, indexed by component type
63 private static $defaultComponent;
66 * Get all the mailing components of a particular type.
69 * The type of component needed.
72 * array reference of all mailing components
74 public static function &component($type = NULL) {
75 $name = $type ?
$type : 'ALL';
77 if (!self
::$component ||
!array_key_exists($name, self
::$component)) {
78 if (!self
::$component) {
79 self
::$component = array();
82 self
::$component[$name] = NULL;
83 CRM_Core_PseudoConstant
::populate(self
::$component[$name], 'CRM_Mailing_DAO_Component');
86 // we need to add an additional filter for $type
87 self
::$component[$name] = array();
89 $object = new CRM_Mailing_DAO_Component();
90 $object->component_type
= $type;
92 $object->selectAdd("id, name");
93 $object->orderBy('component_type, is_default, name');
94 $object->is_active
= 1;
96 while ($object->fetch()) {
97 self
::$component[$name][$object->id
] = $object->name
;
101 return self
::$component[$name];
105 * Determine the default mailing component of a given type.
108 * The type of component needed.
110 * The value to use if no default is defined.
113 * The ID of the default mailing component.
115 public static function &defaultComponent($type, $undefined = NULL) {
116 if (!self
::$defaultComponent) {
117 $queryDefaultComponents = "SELECT id, component_type
118 FROM civicrm_mailing_component
121 GROUP BY component_type";
123 $dao = CRM_Core_DAO
::executeQuery($queryDefaultComponents);
125 self
::$defaultComponent = array();
126 while ($dao->fetch()) {
127 self
::$defaultComponent[$dao->component_type
] = $dao->id
;
130 $value = CRM_Utils_Array
::value($type, self
::$defaultComponent, $undefined);
135 * Get all the mailing templates.
139 * array reference of all mailing templates if any
141 public static function &template() {
142 if (!self
::$template) {
143 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
145 return self
::$template;
149 * Get all the completed mailing.
155 * array reference of all mailing templates if any
157 public static function &completed($mode = NULL) {
158 if (!self
::$completed) {
159 $mailingACL = CRM_Mailing_BAO_Mailing
::mailingACL();
160 $mailingACL .= $mode == 'sms' ?
" AND sms_provider_id IS NOT NULL " : "";
162 CRM_Core_PseudoConstant
::populate(self
::$completed,
163 'CRM_Mailing_DAO_Mailing',
170 return self
::$completed;
174 * Labels for advanced search against mailing summary.
178 * @return unknown_type
180 public static function &yesNoOptions($field) {
185 'N' => ts('Successful '),
186 'Y' => ts('Bounced '),
188 'delivered' => array(
189 'Y' => ts('Successful '),
190 'N' => ts('Bounced '),
193 'Y' => ts('Opened '),
194 'N' => ts('Unopened/Hidden '),
197 'Y' => ts('Clicked '),
198 'N' => ts('Not Clicked '),
201 'Y' => ts('Replied '),
202 'N' => ts('No Reply '),
206 return $options[$field];
210 * Flush given pseudoconstant so it can be reread from db
211 * next time it's requested.
214 * @param bool|string $name pseudoconstant to be flushed
216 public static function flush($name = 'template') {
217 if (isset(self
::$
$name)) {