Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
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 | ||
6a488035 TO |
42 | /** |
43 | * mailing templates | |
44 | * @var array | |
45 | * @static | |
46 | */ | |
47 | private static $template; | |
48 | ||
49 | /** | |
50 | * completed mailings | |
51 | * @var array | |
52 | * @static | |
53 | */ | |
54 | private static $completed; | |
55 | ||
56 | /** | |
57 | * mailing components | |
58 | * @var array | |
59 | * @static | |
60 | */ | |
61 | private static $component; | |
62 | ||
63 | /** | |
64 | * default component id's, indexed by component type | |
65 | */ | |
66 | private static $defaultComponent; | |
67 | ||
68 | /** | |
69 | * Get all the mailing components of a particular type | |
70 | * | |
71 | * @param $type the type of component needed | |
72 | * @access public | |
73 | * | |
74 | * @return array - array reference of all mailing components | |
75 | * @static | |
76 | */ | |
77 | public static function &component($type = NULL) { | |
78 | $name = $type ? $type : 'ALL'; | |
79 | ||
80 | if (!self::$component || !array_key_exists($name, self::$component)) { | |
81 | if (!self::$component) { | |
82 | self::$component = array(); | |
83 | } | |
84 | if (!$type) { | |
85 | self::$component[$name] = NULL; | |
86 | CRM_Core_PseudoConstant::populate(self::$component[$name], 'CRM_Mailing_DAO_Component'); | |
87 | } | |
88 | else { | |
89 | // we need to add an additional filter for $type | |
90 | self::$component[$name] = array(); | |
91 | ||
92 | ||
93 | $object = new CRM_Mailing_DAO_Component(); | |
94 | $object->component_type = $type; | |
95 | $object->selectAdd(); | |
96 | $object->selectAdd("id, name"); | |
97 | $object->orderBy('component_type, is_default, name'); | |
98 | $object->is_active = 1; | |
99 | $object->find(); | |
100 | while ($object->fetch()) { | |
101 | self::$component[$name][$object->id] = $object->name; | |
102 | } | |
103 | } | |
104 | } | |
105 | return self::$component[$name]; | |
106 | } | |
107 | ||
108 | /** | |
109 | * Determine the default mailing component of a given type | |
110 | * | |
111 | * @param $type the type of component needed | |
112 | * @param $undefined the value to use if no default is defined | |
113 | * @access public | |
114 | * | |
115 | * @return integer -The ID of the default mailing component. | |
116 | * @static | |
117 | */ | |
118 | public static function &defaultComponent($type, $undefined = NULL) { | |
119 | if (!self::$defaultComponent) { | |
120 | $queryDefaultComponents = "SELECT id, component_type | |
121 | FROM civicrm_mailing_component | |
122 | WHERE is_active = 1 | |
123 | AND is_default = 1 | |
124 | GROUP BY component_type"; | |
125 | ||
126 | $dao = CRM_Core_DAO::executeQuery($queryDefaultComponents); | |
127 | ||
128 | self::$defaultComponent = array(); | |
129 | while ($dao->fetch()) { | |
130 | self::$defaultComponent[$dao->component_type] = $dao->id; | |
131 | } | |
132 | } | |
133 | $value = CRM_Utils_Array::value($type, self::$defaultComponent, $undefined); | |
134 | return $value; | |
135 | } | |
136 | ||
137 | /** | |
138 | * Get all the mailing templates | |
139 | * | |
140 | * @access public | |
141 | * | |
142 | * @return array - array reference of all mailing templates if any | |
143 | * @static | |
144 | */ | |
145 | public static function &template() { | |
146 | if (!self::$template) { | |
147 | CRM_Core_PseudoConstant::populate(self::$template, 'CRM_Mailing_DAO_Mailing', TRUE, 'name', 'is_template'); | |
148 | } | |
149 | return self::$template; | |
150 | } | |
151 | ||
152 | /** | |
153 | * Get all the completed mailing | |
154 | * | |
155 | * @access public | |
156 | * | |
da6b46f4 EM |
157 | * @param null $mode |
158 | * | |
6a488035 TO |
159 | * @return array - array reference of all mailing templates if any |
160 | * @static | |
161 | */ | |
162 | public static function &completed($mode = NULL) { | |
163 | if (!self::$completed) { | |
164 | $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL(); | |
165 | $mailingACL .= $mode == 'sms' ? " AND sms_provider_id IS NOT NULL " : ""; | |
166 | ||
167 | CRM_Core_PseudoConstant::populate(self::$completed, | |
168 | 'CRM_Mailing_DAO_Mailing', | |
169 | FALSE, | |
170 | 'name', | |
171 | 'is_completed', | |
172 | $mailingACL | |
173 | ); | |
174 | } | |
175 | return self::$completed; | |
176 | } | |
177 | ||
6a488035 TO |
178 | /** |
179 | * Labels for advanced search against mailing summary. | |
180 | * | |
181 | * @param $field | |
182 | * | |
183 | * @return unknown_type | |
184 | */ | |
185 | public static function &yesNoOptions($field) { | |
186 | static $options; | |
187 | if (!$options) { | |
188 | $options = array( | |
189 | 'bounce' => array( | |
190 | 'N' => ts('Successful '), 'Y' => ts('Bounced '), | |
191 | ), | |
192 | 'delivered' => array( | |
193 | 'Y' => ts('Successful '), 'N' => ts('Bounced '), | |
194 | ), | |
195 | 'open' => array( | |
196 | 'Y' => ts('Opened '), 'N' => ts('Unopened/Hidden '), | |
197 | ), | |
198 | 'click' => array( | |
199 | 'Y' => ts('Clicked '), 'N' => ts('Not Clicked '), | |
200 | ), | |
201 | 'reply' => array( | |
202 | 'Y' => ts('Replied '), 'N' => ts('No Reply '), | |
203 | ), | |
204 | ); | |
205 | } | |
206 | return $options[$field]; | |
207 | } | |
208 | ||
209 | /** | |
210 | * Flush given pseudoconstant so it can be reread from db | |
6ce01b02 | 211 | * next time it's requested. |
6a488035 TO |
212 | * |
213 | * @access public | |
214 | * @static | |
215 | * | |
da6b46f4 | 216 | * @param bool|string $name pseudoconstant to be flushed |
6a488035 | 217 | */ |
6ce01b02 | 218 | public static function flush($name = 'template') { |
fa56270d CW |
219 | if (isset(self::$$name)) { |
220 | self::$$name = NULL; | |
221 | } | |
6a488035 TO |
222 | } |
223 | } | |
224 |