Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
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 | |
39 | */ | |
40 | class CRM_Mailing_PseudoConstant extends CRM_Core_PseudoConstant { | |
41 | ||
42 | /** | |
43 | * mailing approval status | |
44 | * @var array | |
45 | * @static | |
46 | */ | |
47 | private static $approvalStatus; | |
48 | ||
49 | /** | |
50 | * mailing templates | |
51 | * @var array | |
52 | * @static | |
53 | */ | |
54 | private static $template; | |
55 | ||
56 | /** | |
57 | * completed mailings | |
58 | * @var array | |
59 | * @static | |
60 | */ | |
61 | private static $completed; | |
62 | ||
63 | /** | |
64 | * mailing components | |
65 | * @var array | |
66 | * @static | |
67 | */ | |
68 | private static $component; | |
69 | ||
70 | /** | |
71 | * default component id's, indexed by component type | |
72 | */ | |
73 | private static $defaultComponent; | |
74 | ||
75 | /** | |
76 | * Get all the mailing components of a particular type | |
77 | * | |
78 | * @param $type the type of component needed | |
79 | * @access public | |
80 | * | |
81 | * @return array - array reference of all mailing components | |
82 | * @static | |
83 | */ | |
84 | public static function &component($type = NULL) { | |
85 | $name = $type ? $type : 'ALL'; | |
86 | ||
87 | if (!self::$component || !array_key_exists($name, self::$component)) { | |
88 | if (!self::$component) { | |
89 | self::$component = array(); | |
90 | } | |
91 | if (!$type) { | |
92 | self::$component[$name] = NULL; | |
93 | CRM_Core_PseudoConstant::populate(self::$component[$name], 'CRM_Mailing_DAO_Component'); | |
94 | } | |
95 | else { | |
96 | // we need to add an additional filter for $type | |
97 | self::$component[$name] = array(); | |
98 | ||
99 | ||
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; | |
106 | $object->find(); | |
107 | while ($object->fetch()) { | |
108 | self::$component[$name][$object->id] = $object->name; | |
109 | } | |
110 | } | |
111 | } | |
112 | return self::$component[$name]; | |
113 | } | |
114 | ||
115 | /** | |
116 | * Determine the default mailing component of a given type | |
117 | * | |
118 | * @param $type the type of component needed | |
119 | * @param $undefined the value to use if no default is defined | |
120 | * @access public | |
121 | * | |
122 | * @return integer -The ID of the default mailing component. | |
123 | * @static | |
124 | */ | |
125 | public static function &defaultComponent($type, $undefined = NULL) { | |
126 | if (!self::$defaultComponent) { | |
127 | $queryDefaultComponents = "SELECT id, component_type | |
128 | FROM civicrm_mailing_component | |
129 | WHERE is_active = 1 | |
130 | AND is_default = 1 | |
131 | GROUP BY component_type"; | |
132 | ||
133 | $dao = CRM_Core_DAO::executeQuery($queryDefaultComponents); | |
134 | ||
135 | self::$defaultComponent = array(); | |
136 | while ($dao->fetch()) { | |
137 | self::$defaultComponent[$dao->component_type] = $dao->id; | |
138 | } | |
139 | } | |
140 | $value = CRM_Utils_Array::value($type, self::$defaultComponent, $undefined); | |
141 | return $value; | |
142 | } | |
143 | ||
144 | /** | |
145 | * Get all the mailing templates | |
146 | * | |
147 | * @access public | |
148 | * | |
149 | * @return array - array reference of all mailing templates if any | |
150 | * @static | |
151 | */ | |
152 | public static function &template() { | |
153 | if (!self::$template) { | |
154 | CRM_Core_PseudoConstant::populate(self::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template'); | |
155 | } | |
156 | return self::$template; | |
157 | } | |
158 | ||
159 | /** | |
160 | * Get all the completed mailing | |
161 | * | |
162 | * @access public | |
163 | * | |
164 | * @return array - array reference of all mailing templates if any | |
165 | * @static | |
166 | */ | |
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 " : ""; | |
171 | ||
172 | CRM_Core_PseudoConstant::populate(self::$completed, | |
173 | 'CRM_Mailing_DAO_Mailing', | |
174 | FALSE, | |
175 | 'name', | |
176 | 'is_completed', | |
177 | $mailingACL | |
178 | ); | |
179 | } | |
180 | return self::$completed; | |
181 | } | |
182 | ||
183 | /** | |
184 | * Get all mail approval status. | |
185 | * | |
186 | * The static array approvalStatus is returned | |
187 | * | |
188 | * @access public | |
189 | * @static | |
190 | * | |
191 | * @return array - array reference of all mail approval statuses | |
192 | * | |
193 | */ | |
194 | public static function &approvalStatus() { | |
195 | if (!self::$approvalStatus) { | |
196 | self::$approvalStatus = CRM_Core_OptionGroup::values('mail_approval_status'); | |
197 | } | |
198 | return self::$approvalStatus; | |
199 | } | |
200 | ||
201 | /** | |
202 | * Labels for advanced search against mailing summary. | |
203 | * | |
204 | * @param $field | |
205 | * | |
206 | * @return unknown_type | |
207 | */ | |
208 | public static function &yesNoOptions($field) { | |
209 | static $options; | |
210 | if (!$options) { | |
211 | $options = array( | |
212 | 'bounce' => array( | |
213 | 'N' => ts('Successful '), 'Y' => ts('Bounced '), | |
214 | ), | |
215 | 'delivered' => array( | |
216 | 'Y' => ts('Successful '), 'N' => ts('Bounced '), | |
217 | ), | |
218 | 'open' => array( | |
219 | 'Y' => ts('Opened '), 'N' => ts('Unopened/Hidden '), | |
220 | ), | |
221 | 'click' => array( | |
222 | 'Y' => ts('Clicked '), 'N' => ts('Not Clicked '), | |
223 | ), | |
224 | 'reply' => array( | |
225 | 'Y' => ts('Replied '), 'N' => ts('No Reply '), | |
226 | ), | |
227 | ); | |
228 | } | |
229 | return $options[$field]; | |
230 | } | |
231 | ||
232 | /** | |
233 | * Flush given pseudoconstant so it can be reread from db | |
234 | * nex time it's requested. | |
235 | * | |
236 | * @access public | |
237 | * @static | |
238 | * | |
239 | * @param boolean $name pseudoconstant to be flushed | |
240 | * | |
241 | */ | |
242 | public static function flush($name) { | |
fa56270d CW |
243 | if (isset(self::$$name)) { |
244 | self::$$name = NULL; | |
245 | } | |
6a488035 TO |
246 | } |
247 | } | |
248 |