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