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
{
43 * mailing approval status
47 private static $approvalStatus;
54 private static $template;
61 private static $completed;
68 private static $component;
71 * default component id's, indexed by component type
73 private static $defaultComponent;
76 * Get all the mailing components of a particular type
78 * @param $type the type of component needed
81 * @return array - array reference of all mailing components
84 public static function &component($type = NULL) {
85 $name = $type ?
$type : 'ALL';
87 if (!self
::$component ||
!array_key_exists($name, self
::$component)) {
88 if (!self
::$component) {
89 self
::$component = array();
92 self
::$component[$name] = NULL;
93 CRM_Core_PseudoConstant
::populate(self
::$component[$name], 'CRM_Mailing_DAO_Component');
96 // we need to add an additional filter for $type
97 self
::$component[$name] = array();
100 $object = new CRM_Mailing_DAO_Component();
101 $object->component_type
= $type;
102 $object->selectAdd();
103 $object->selectAdd("id, name");
104 $object->orderBy('component_type, is_default, name');
105 $object->is_active
= 1;
107 while ($object->fetch()) {
108 self
::$component[$name][$object->id
] = $object->name
;
112 return self
::$component[$name];
116 * Determine the default mailing component of a given type
118 * @param $type the type of component needed
119 * @param $undefined the value to use if no default is defined
122 * @return integer -The ID of the default mailing component.
125 public static function &defaultComponent($type, $undefined = NULL) {
126 if (!self
::$defaultComponent) {
127 $queryDefaultComponents = "SELECT id, component_type
128 FROM civicrm_mailing_component
131 GROUP BY component_type";
133 $dao = CRM_Core_DAO
::executeQuery($queryDefaultComponents);
135 self
::$defaultComponent = array();
136 while ($dao->fetch()) {
137 self
::$defaultComponent[$dao->component_type
] = $dao->id
;
140 $value = CRM_Utils_Array
::value($type, self
::$defaultComponent, $undefined);
145 * Get all the mailing templates
149 * @return array - array reference of all mailing templates if any
152 public static function &template() {
153 if (!self
::$template) {
154 CRM_Core_PseudoConstant
::populate(self
::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template');
156 return self
::$template;
160 * Get all the completed mailing
164 * @return array - array reference of all mailing templates if any
167 public static function &completed($mode = NULL) {
168 if (!self
::$completed) {
169 $mailingACL = CRM_Mailing_BAO_Mailing
::mailingACL();
170 $mailingACL .= $mode == 'sms' ?
" AND sms_provider_id IS NOT NULL " : "";
172 CRM_Core_PseudoConstant
::populate(self
::$completed,
173 'CRM_Mailing_DAO_Mailing',
180 return self
::$completed;
184 * Get all mail approval status.
186 * The static array approvalStatus is returned
191 * @return array - array reference of all mail approval statuses
194 public static function &approvalStatus() {
195 if (!self
::$approvalStatus) {
196 self
::$approvalStatus = CRM_Core_OptionGroup
::values('mail_approval_status');
198 return self
::$approvalStatus;
202 * Labels for advanced search against mailing summary.
206 * @return unknown_type
208 public static function &yesNoOptions($field) {
213 'N' => ts('Successful '), 'Y' => ts('Bounced '),
215 'delivered' => array(
216 'Y' => ts('Successful '), 'N' => ts('Bounced '),
219 'Y' => ts('Opened '), 'N' => ts('Unopened/Hidden '),
222 'Y' => ts('Clicked '), 'N' => ts('Not Clicked '),
225 'Y' => ts('Replied '), 'N' => ts('No Reply '),
229 return $options[$field];
233 * Flush given pseudoconstant so it can be reread from db
234 * nex time it's requested.
239 * @param boolean $name pseudoconstant to be flushed
242 public static function flush($name) {
243 if (isset(self
::$
$name)) {