510a8bbc27ec82d18a081052119772f25eba9fa5
[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 /**
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 * @return \CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
193 */
194 public function __construct()
195 {
196 $this->__table = 'civicrm_price_field';
197 parent::__construct();
198 }
199 /**
200 * return foreign links
201 *
202 * @return array
203 */
204 public function links()
205 {
206 if (!(self::$_links)) {
207 self::$_links = array(
208 'price_set_id' => 'civicrm_price_set:id',
209 );
210 }
211 return self::$_links;
212 }
213 /**
214 * returns all the column names of this table
215 *
216 * @return array
217 */
218 static function &fields()
219 {
220 if (!(self::$_fields)) {
221 self::$_fields = array(
222 'id' => array(
223 'name' => 'id',
224 'type' => CRM_Utils_Type::T_INT,
225 'required' => true,
226 ) ,
227 'price_set_id' => array(
228 'name' => 'price_set_id',
229 'type' => CRM_Utils_Type::T_INT,
230 'required' => true,
231 'FKClassName' => 'Snapshot_v4p2_Price_DAO_Set',
232 ) ,
233 'name' => array(
234 'name' => 'name',
235 'type' => CRM_Utils_Type::T_STRING,
236 'title' => ts('Name') ,
237 'required' => true,
238 'maxlength' => 255,
239 'size' => CRM_Utils_Type::HUGE,
240 ) ,
241 'label' => array(
242 'name' => 'label',
243 'type' => CRM_Utils_Type::T_STRING,
244 'title' => ts('Label') ,
245 'required' => true,
246 'maxlength' => 255,
247 'size' => CRM_Utils_Type::HUGE,
248 ) ,
249 'html_type' => array(
250 'name' => 'html_type',
251 'type' => CRM_Utils_Type::T_ENUM,
252 'title' => ts('Html Type') ,
253 'required' => true,
254 'enumValues' => 'Text, Select, Radio, CheckBox',
255 ) ,
256 'is_enter_qty' => array(
257 'name' => 'is_enter_qty',
258 'type' => CRM_Utils_Type::T_BOOLEAN,
259 ) ,
260 'help_pre' => array(
261 'name' => 'help_pre',
262 'type' => CRM_Utils_Type::T_TEXT,
263 'title' => ts('Help Pre') ,
264 'rows' => 4,
265 'cols' => 80,
266 ) ,
267 'help_post' => array(
268 'name' => 'help_post',
269 'type' => CRM_Utils_Type::T_TEXT,
270 'title' => ts('Help Post') ,
271 'rows' => 4,
272 'cols' => 80,
273 ) ,
274 'weight' => array(
275 'name' => 'weight',
276 'type' => CRM_Utils_Type::T_INT,
277 'title' => ts('Weight') ,
278 'default' => '',
279 ) ,
280 'is_display_amounts' => array(
281 'name' => 'is_display_amounts',
282 'type' => CRM_Utils_Type::T_BOOLEAN,
283 'default' => '',
284 ) ,
285 'options_per_line' => array(
286 'name' => 'options_per_line',
287 'type' => CRM_Utils_Type::T_INT,
288 'title' => ts('Options Per Line') ,
289 'default' => '',
290 ) ,
291 'is_active' => array(
292 'name' => 'is_active',
293 'type' => CRM_Utils_Type::T_BOOLEAN,
294 'default' => '',
295 ) ,
296 'is_required' => array(
297 'name' => 'is_required',
298 'type' => CRM_Utils_Type::T_BOOLEAN,
299 'default' => '',
300 ) ,
301 'active_on' => array(
302 'name' => 'active_on',
303 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
304 'title' => ts('Active On') ,
305 'default' => 'UL',
306 ) ,
307 'expire_on' => array(
308 'name' => 'expire_on',
309 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
310 'title' => ts('Expire On') ,
311 'default' => 'UL',
312 ) ,
313 'javascript' => array(
314 'name' => 'javascript',
315 'type' => CRM_Utils_Type::T_STRING,
316 'title' => ts('Javascript') ,
317 'maxlength' => 255,
318 'size' => CRM_Utils_Type::HUGE,
319 ) ,
320 'visibility_id' => array(
321 'name' => 'visibility_id',
322 'type' => CRM_Utils_Type::T_INT,
323 'default' => '',
324 ) ,
325 );
326 }
327 return self::$_fields;
328 }
329 /**
330 * returns the names of this table
331 *
332 * @static
333 * @return string
334 */
335 public static function getTableName()
336 {
337 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
338 }
339 /**
340 * returns if this table needs to be logged
341 *
342 * @return boolean
343 */
344 public function getLog()
345 {
346 return self::$_log;
347 }
348 /**
349 * returns the list of fields that can be imported
350 *
351 * return array
352 * @static
353 */
354 static function &import($prefix = false)
355 {
356 if (!(self::$_import)) {
357 self::$_import = array();
358 $fields = self::fields();
359 foreach($fields as $name => $field) {
360 if (!empty($field['import'])) {
361 if ($prefix) {
362 self::$_import['price_field'] = & $fields[$name];
363 } else {
364 self::$_import[$name] = & $fields[$name];
365 }
366 }
367 }
368 }
369 return self::$_import;
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 {
379 if (!(self::$_export)) {
380 self::$_export = array();
381 $fields = self::fields();
382 foreach($fields as $name => $field) {
383 if (!empty($field['export'])) {
384 if ($prefix) {
385 self::$_export['price_field'] = & $fields[$name];
386 } else {
387 self::$_export[$name] = & $fields[$name];
388 }
389 }
390 }
391 }
392 return self::$_export;
393 }
394 /**
395 * returns an array containing the enum fields of the civicrm_price_field table
396 *
397 * @return array (reference) the array of enum fields
398 */
399 static function &getEnums()
400 {
401 static $enums = array(
402 'html_type',
403 );
404 return $enums;
405 }
406 /**
407 * returns a ts()-translated enum value for display purposes
408 *
409 * @param string $field the enum field in question
410 * @param string $value the enum value up for translation
411 *
412 * @return string the display value of the enum
413 */
414 public static function tsEnum($field, $value)
415 {
416 static $translations = null;
417 if (!$translations) {
418 $translations = array(
419 'html_type' => array(
420 'Text' => ts('Text') ,
421 'Select' => ts('Select') ,
422 'Radio' => ts('Radio') ,
423 'CheckBox' => ts('CheckBox') ,
424 ) ,
425 );
426 }
427 return $translations[$field][$value];
428 }
429 /**
430 * adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field
431 *
432 * @param array $values (reference) the array up for enhancing
433 * @return void
434 */
435 public static function addDisplayEnums(&$values)
436 {
437 $enumFields = & Snapshot_v4p2_Price_DAO_Field::getEnums();
438 foreach($enumFields as $enum) {
439 if (isset($values[$enum])) {
440 $values[$enum . '_display'] = Snapshot_v4p2_Price_DAO_Field::tsEnum($enum, $values[$enum]);
441 }
442 }
443 }
444 }