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