Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | * @package CRM | |
e7112fa7 | 30 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
31 | * $Id$ |
32 | * | |
33 | */ | |
34 | require_once 'CRM/Core/DAO.php'; | |
35 | require_once 'CRM/Utils/Type.php'; | |
624e56fa EM |
36 | |
37 | /** | |
38 | * Class CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field | |
39 | */ | |
353ffa53 TO |
40 | class CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field extends CRM_Core_DAO { |
41 | /** | |
42 | * static instance to hold the table name | |
43 | * | |
44 | * @var string | |
353ffa53 TO |
45 | */ |
46 | static $_tableName = 'civicrm_price_field'; | |
47 | /** | |
48 | * static instance to hold the field values | |
49 | * | |
50 | * @var array | |
353ffa53 TO |
51 | */ |
52 | static $_fields = NULL; | |
53 | /** | |
54 | * static instance to hold the FK relationships | |
55 | * | |
56 | * @var string | |
353ffa53 TO |
57 | */ |
58 | static $_links = NULL; | |
59 | /** | |
60 | * static instance to hold the values that can | |
61 | * be imported | |
62 | * | |
63 | * @var array | |
353ffa53 TO |
64 | */ |
65 | static $_import = NULL; | |
66 | /** | |
67 | * static instance to hold the values that can | |
68 | * be exported | |
69 | * | |
70 | * @var array | |
353ffa53 TO |
71 | */ |
72 | static $_export = NULL; | |
73 | /** | |
74 | * static value to see if we should log any modifications to | |
75 | * this table in the civicrm_log table | |
76 | * | |
77 | * @var boolean | |
353ffa53 TO |
78 | */ |
79 | static $_log = TRUE; | |
80 | /** | |
81 | * Price Field | |
82 | * | |
83 | * @var int unsigned | |
84 | */ | |
85 | public $id; | |
86 | /** | |
87 | * FK to civicrm_price_set | |
88 | * | |
89 | * @var int unsigned | |
90 | */ | |
91 | public $price_set_id; | |
92 | /** | |
93 | * Variable name/programmatic handle for this field. | |
94 | * | |
95 | * @var string | |
96 | */ | |
97 | public $name; | |
98 | /** | |
99 | * Text for form field label (also friendly name for administering this field). | |
100 | * | |
101 | * @var string | |
102 | */ | |
103 | public $label; | |
104 | /** | |
105 | * | |
106 | * @var enum('Text', 'Select', 'Radio', 'CheckBox') | |
107 | */ | |
108 | public $html_type; | |
109 | /** | |
110 | * Enter a quantity for this field? | |
111 | * | |
112 | * @var boolean | |
113 | */ | |
114 | public $is_enter_qty; | |
115 | /** | |
116 | * Description and/or help text to display before this field. | |
117 | * | |
118 | * @var text | |
119 | */ | |
120 | public $help_pre; | |
121 | /** | |
122 | * Description and/or help text to display after this field. | |
123 | * | |
124 | * @var text | |
125 | */ | |
126 | public $help_post; | |
127 | /** | |
128 | * Order in which the fields should appear | |
129 | * | |
130 | * @var int | |
131 | */ | |
132 | public $weight; | |
133 | /** | |
134 | * Should the price be displayed next to the label for each option? | |
135 | * | |
136 | * @var boolean | |
137 | */ | |
138 | public $is_display_amounts; | |
139 | /** | |
140 | * number of options per line for checkbox and radio | |
141 | * | |
142 | * @var int unsigned | |
143 | */ | |
144 | public $options_per_line; | |
145 | /** | |
146 | * Is this price field active | |
147 | * | |
148 | * @var boolean | |
149 | */ | |
150 | public $is_active; | |
151 | /** | |
152 | * Is this price field required (value must be > 1) | |
153 | * | |
154 | * @var boolean | |
155 | */ | |
156 | public $is_required; | |
157 | /** | |
158 | * If non-zero, do not show this field before the date specified | |
159 | * | |
160 | * @var datetime | |
161 | */ | |
162 | public $active_on; | |
163 | /** | |
164 | * If non-zero, do not show this field after the date specified | |
165 | * | |
166 | * @var datetime | |
167 | */ | |
168 | public $expire_on; | |
169 | /** | |
170 | * Optional scripting attributes for field | |
171 | * | |
172 | * @var string | |
173 | */ | |
174 | public $javascript; | |
175 | /** | |
176 | * Implicit FK to civicrm_option_group with name = \'visibility\' | |
177 | * | |
178 | * @var int unsigned | |
179 | */ | |
180 | public $visibility_id; | |
77b97be7 EM |
181 | |
182 | /** | |
fe482240 | 183 | * Class constructor. |
77b97be7 | 184 | * |
77b97be7 EM |
185 | * @return \CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field |
186 | */ | |
353ffa53 TO |
187 | public function __construct() { |
188 | $this->__table = 'civicrm_price_field'; | |
189 | parent::__construct(); | |
190 | } | |
191 | ||
192 | /** | |
fe482240 | 193 | * Return foreign links. |
353ffa53 TO |
194 | * |
195 | * @return array | |
196 | */ | |
197 | public function links() { | |
198 | if (!(self::$_links)) { | |
199 | self::$_links = array( | |
200 | 'price_set_id' => 'civicrm_price_set:id', | |
201 | ); | |
6a488035 | 202 | } |
353ffa53 TO |
203 | return self::$_links; |
204 | } | |
205 | ||
206 | /** | |
fe482240 | 207 | * Returns all the column names of this table. |
353ffa53 TO |
208 | * |
209 | * @return array | |
210 | */ | |
211 | static function &fields() { | |
212 | if (!(self::$_fields)) { | |
213 | self::$_fields = array( | |
214 | 'id' => array( | |
215 | 'name' => 'id', | |
216 | 'type' => CRM_Utils_Type::T_INT, | |
217 | 'required' => TRUE, | |
218 | ), | |
219 | 'price_set_id' => array( | |
220 | 'name' => 'price_set_id', | |
221 | 'type' => CRM_Utils_Type::T_INT, | |
222 | 'required' => TRUE, | |
223 | 'FKClassName' => 'Snapshot_v4p2_Price_DAO_Set', | |
224 | ), | |
225 | 'name' => array( | |
226 | 'name' => 'name', | |
227 | 'type' => CRM_Utils_Type::T_STRING, | |
228 | 'title' => ts('Name'), | |
229 | 'required' => TRUE, | |
230 | 'maxlength' => 255, | |
231 | 'size' => CRM_Utils_Type::HUGE, | |
232 | ), | |
233 | 'label' => array( | |
234 | 'name' => 'label', | |
235 | 'type' => CRM_Utils_Type::T_STRING, | |
236 | 'title' => ts('Label'), | |
237 | 'required' => TRUE, | |
238 | 'maxlength' => 255, | |
239 | 'size' => CRM_Utils_Type::HUGE, | |
240 | ), | |
241 | 'html_type' => array( | |
242 | 'name' => 'html_type', | |
243 | 'type' => CRM_Utils_Type::T_ENUM, | |
244 | 'title' => ts('Html Type'), | |
245 | 'required' => TRUE, | |
246 | 'enumValues' => 'Text, Select, Radio, CheckBox', | |
247 | ), | |
248 | 'is_enter_qty' => array( | |
249 | 'name' => 'is_enter_qty', | |
250 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
251 | ), | |
252 | 'help_pre' => array( | |
253 | 'name' => 'help_pre', | |
254 | 'type' => CRM_Utils_Type::T_TEXT, | |
255 | 'title' => ts('Help Pre'), | |
256 | 'rows' => 4, | |
257 | 'cols' => 80, | |
258 | ), | |
259 | 'help_post' => array( | |
260 | 'name' => 'help_post', | |
261 | 'type' => CRM_Utils_Type::T_TEXT, | |
262 | 'title' => ts('Help Post'), | |
263 | 'rows' => 4, | |
264 | 'cols' => 80, | |
265 | ), | |
266 | 'weight' => array( | |
267 | 'name' => 'weight', | |
268 | 'type' => CRM_Utils_Type::T_INT, | |
269 | 'title' => ts('Weight'), | |
270 | 'default' => '', | |
271 | ), | |
272 | 'is_display_amounts' => array( | |
273 | 'name' => 'is_display_amounts', | |
274 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
275 | 'default' => '', | |
276 | ), | |
277 | 'options_per_line' => array( | |
278 | 'name' => 'options_per_line', | |
279 | 'type' => CRM_Utils_Type::T_INT, | |
280 | 'title' => ts('Options Per Line'), | |
281 | 'default' => '', | |
282 | ), | |
283 | 'is_active' => array( | |
284 | 'name' => 'is_active', | |
285 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
286 | 'default' => '', | |
287 | ), | |
288 | 'is_required' => array( | |
289 | 'name' => 'is_required', | |
290 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
291 | 'default' => '', | |
292 | ), | |
293 | 'active_on' => array( | |
294 | 'name' => 'active_on', | |
295 | 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, | |
296 | 'title' => ts('Active On'), | |
297 | 'default' => 'UL', | |
298 | ), | |
299 | 'expire_on' => array( | |
300 | 'name' => 'expire_on', | |
301 | 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, | |
302 | 'title' => ts('Expire On'), | |
303 | 'default' => 'UL', | |
304 | ), | |
305 | 'javascript' => array( | |
306 | 'name' => 'javascript', | |
307 | 'type' => CRM_Utils_Type::T_STRING, | |
308 | 'title' => ts('Javascript'), | |
309 | 'maxlength' => 255, | |
310 | 'size' => CRM_Utils_Type::HUGE, | |
311 | ), | |
312 | 'visibility_id' => array( | |
313 | 'name' => 'visibility_id', | |
314 | 'type' => CRM_Utils_Type::T_INT, | |
315 | 'default' => '', | |
316 | ), | |
317 | ); | |
6a488035 | 318 | } |
353ffa53 TO |
319 | return self::$_fields; |
320 | } | |
321 | ||
322 | /** | |
fe482240 | 323 | * returns the names of this table. |
353ffa53 | 324 | * |
353ffa53 TO |
325 | * @return string |
326 | */ | |
327 | public static function getTableName() { | |
328 | return CRM_Core_DAO::getLocaleTableName(self::$_tableName); | |
329 | } | |
330 | ||
331 | /** | |
fe482240 | 332 | * returns if this table needs to be logged. |
353ffa53 TO |
333 | * |
334 | * @return boolean | |
335 | */ | |
336 | public function getLog() { | |
337 | return self::$_log; | |
338 | } | |
339 | ||
340 | /** | |
fe482240 | 341 | * returns the list of fields that can be imported. |
353ffa53 | 342 | * |
76e7a76c | 343 | * @return array |
353ffa53 TO |
344 | */ |
345 | static function &import($prefix = FALSE) { | |
346 | if (!(self::$_import)) { | |
347 | self::$_import = array(); | |
348 | $fields = self::fields(); | |
349 | foreach ($fields as $name => $field) { | |
350 | if (!empty($field['import'])) { | |
351 | if ($prefix) { | |
352 | self::$_import['price_field'] = &$fields[$name]; | |
353 | } | |
354 | else { | |
355 | self::$_import[$name] = &$fields[$name]; | |
356 | } | |
6a488035 | 357 | } |
353ffa53 | 358 | } |
6a488035 | 359 | } |
353ffa53 TO |
360 | return self::$_import; |
361 | } | |
362 | ||
363 | /** | |
fe482240 | 364 | * returns the list of fields that can be exported. |
353ffa53 | 365 | * |
76e7a76c | 366 | * @return array |
353ffa53 TO |
367 | */ |
368 | static function &export($prefix = FALSE) { | |
369 | if (!(self::$_export)) { | |
370 | self::$_export = array(); | |
371 | $fields = self::fields(); | |
372 | foreach ($fields as $name => $field) { | |
373 | if (!empty($field['export'])) { | |
374 | if ($prefix) { | |
375 | self::$_export['price_field'] = &$fields[$name]; | |
376 | } | |
377 | else { | |
378 | self::$_export[$name] = &$fields[$name]; | |
379 | } | |
6a488035 | 380 | } |
353ffa53 | 381 | } |
6a488035 | 382 | } |
353ffa53 TO |
383 | return self::$_export; |
384 | } | |
385 | ||
386 | /** | |
fe482240 | 387 | * returns an array containing the enum fields of the civicrm_price_field table. |
353ffa53 TO |
388 | * |
389 | * @return array | |
a6c01b45 | 390 | * (reference) the array of enum fields |
353ffa53 TO |
391 | */ |
392 | static function &getEnums() { | |
393 | static $enums = array( | |
394 | 'html_type', | |
395 | ); | |
396 | return $enums; | |
397 | } | |
398 | ||
399 | /** | |
400 | * returns a ts()-translated enum value for display purposes | |
401 | * | |
402 | * @param string $field | |
403 | * The enum field in question. | |
404 | * @param string $value | |
405 | * The enum value up for translation. | |
406 | * | |
407 | * @return string | |
a6c01b45 | 408 | * the display value of the enum |
353ffa53 TO |
409 | */ |
410 | public static function tsEnum($field, $value) { | |
411 | static $translations = NULL; | |
412 | if (!$translations) { | |
413 | $translations = array( | |
414 | 'html_type' => array( | |
415 | 'Text' => ts('Text'), | |
416 | 'Select' => ts('Select'), | |
417 | 'Radio' => ts('Radio'), | |
418 | 'CheckBox' => ts('CheckBox'), | |
419 | ), | |
420 | ); | |
6a488035 | 421 | } |
353ffa53 TO |
422 | return $translations[$field][$value]; |
423 | } | |
424 | ||
425 | /** | |
426 | * adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field | |
427 | * | |
428 | * @param array $values | |
429 | * (reference) the array up for enhancing. | |
430 | * @return void | |
431 | */ | |
432 | public static function addDisplayEnums(&$values) { | |
433 | $enumFields = &Snapshot_v4p2_Price_DAO_Field::getEnums(); | |
434 | foreach ($enumFields as $enum) { | |
435 | if (isset($values[$enum])) { | |
436 | $values[$enum . '_display'] = Snapshot_v4p2_Price_DAO_Field::tsEnum($enum, $values[$enum]); | |
437 | } | |
6a488035 | 438 | } |
353ffa53 | 439 | } |
6a488035 | 440 | } |