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