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