Merge pull request #10116 from colemanw/CRM-20390
[civicrm-core.git] / CRM / Core / DAO / CustomField.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 * @package CRM
29 * @copyright CiviCRM LLC (c) 2004-2017
30 *
31 * Generated from xml/schema/CRM/Core/CustomField.xml
32 * DO NOT EDIT. Generated by CRM_Core_CodeGen
33 * (GenCodeChecksum:6c4ced0a0ac204cde5c048d37aee6057)
34 */
35 require_once 'CRM/Core/DAO.php';
36 require_once 'CRM/Utils/Type.php';
37 /**
38 * CRM_Core_DAO_CustomField constructor.
39 */
40 class CRM_Core_DAO_CustomField extends CRM_Core_DAO {
41 /**
42 * Static instance to hold the table name.
43 *
44 * @var string
45 */
46 static $_tableName = 'civicrm_custom_field';
47 /**
48 * Should CiviCRM log any modifications to this table in the civicrm_log table.
49 *
50 * @var boolean
51 */
52 static $_log = true;
53 /**
54 * Unique Custom Field ID
55 *
56 * @var int unsigned
57 */
58 public $id;
59 /**
60 * FK to civicrm_custom_group.
61 *
62 * @var int unsigned
63 */
64 public $custom_group_id;
65 /**
66 * Variable name/programmatic handle for this group.
67 *
68 * @var string
69 */
70 public $name;
71 /**
72 * Text for form field label (also friendly name for administering this custom property).
73 *
74 * @var string
75 */
76 public $label;
77 /**
78 * Controls location of data storage in extended_data table.
79 *
80 * @var string
81 */
82 public $data_type;
83 /**
84 * HTML types plus several built-in extended types.
85 *
86 * @var string
87 */
88 public $html_type;
89 /**
90 * Use form_options.is_default for field_types which use options.
91 *
92 * @var string
93 */
94 public $default_value;
95 /**
96 * Is a value required for this property.
97 *
98 * @var boolean
99 */
100 public $is_required;
101 /**
102 * Is this property searchable.
103 *
104 * @var boolean
105 */
106 public $is_searchable;
107 /**
108 * Is this property range searchable.
109 *
110 * @var boolean
111 */
112 public $is_search_range;
113 /**
114 * Controls field display order within an extended property group.
115 *
116 * @var int
117 */
118 public $weight;
119 /**
120 * Description and/or help text to display before this field.
121 *
122 * @var text
123 */
124 public $help_pre;
125 /**
126 * Description and/or help text to display after this field.
127 *
128 * @var text
129 */
130 public $help_post;
131 /**
132 * Optional format instructions for specific field types, like date types.
133 *
134 * @var string
135 */
136 public $mask;
137 /**
138 * Store collection of type-appropriate attributes, e.g. textarea needs rows/cols attributes
139 *
140 * @var string
141 */
142 public $attributes;
143 /**
144 * Optional scripting attributes for field.
145 *
146 * @var string
147 */
148 public $javascript;
149 /**
150 * Is this property active?
151 *
152 * @var boolean
153 */
154 public $is_active;
155 /**
156 * Is this property set by PHP Code? A code field is viewable but not editable
157 *
158 * @var boolean
159 */
160 public $is_view;
161 /**
162 * number of options per line for checkbox and radio
163 *
164 * @var int unsigned
165 */
166 public $options_per_line;
167 /**
168 * field length if alphanumeric
169 *
170 * @var int unsigned
171 */
172 public $text_length;
173 /**
174 * Date may be up to start_date_years years prior to the current date.
175 *
176 * @var int
177 */
178 public $start_date_years;
179 /**
180 * Date may be up to end_date_years years after the current date.
181 *
182 * @var int
183 */
184 public $end_date_years;
185 /**
186 * date format for custom date
187 *
188 * @var string
189 */
190 public $date_format;
191 /**
192 * time format for custom date
193 *
194 * @var int unsigned
195 */
196 public $time_format;
197 /**
198 * Number of columns in Note Field
199 *
200 * @var int unsigned
201 */
202 public $note_columns;
203 /**
204 * Number of rows in Note Field
205 *
206 * @var int unsigned
207 */
208 public $note_rows;
209 /**
210 * Name of the column that holds the values for this field.
211 *
212 * @var string
213 */
214 public $column_name;
215 /**
216 * For elements with options, the option group id that is used
217 *
218 * @var int unsigned
219 */
220 public $option_group_id;
221 /**
222 * Stores Contact Get API params contact reference custom fields. May be used for other filters in the future.
223 *
224 * @var string
225 */
226 public $filter;
227 /**
228 * Should the multi-record custom field values be displayed in tab table listing
229 *
230 * @var boolean
231 */
232 public $in_selector;
233 /**
234 * Class constructor.
235 */
236 function __construct() {
237 $this->__table = 'civicrm_custom_field';
238 parent::__construct();
239 }
240 /**
241 * Returns foreign keys and entity references.
242 *
243 * @return array
244 * [CRM_Core_Reference_Interface]
245 */
246 static function getReferenceColumns() {
247 if (!isset(Civi::$statics[__CLASS__]['links'])) {
248 Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
249 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'custom_group_id', 'civicrm_custom_group', 'id');
250 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
251 }
252 return Civi::$statics[__CLASS__]['links'];
253 }
254 /**
255 * Returns all the column names of this table
256 *
257 * @return array
258 */
259 static function &fields() {
260 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
261 Civi::$statics[__CLASS__]['fields'] = array(
262 'id' => array(
263 'name' => 'id',
264 'type' => CRM_Utils_Type::T_INT,
265 'title' => ts('Custom Field ID') ,
266 'description' => 'Unique Custom Field ID',
267 'required' => true,
268 'table_name' => 'civicrm_custom_field',
269 'entity' => 'CustomField',
270 'bao' => 'CRM_Core_BAO_CustomField',
271 'localizable' => 0,
272 ) ,
273 'custom_group_id' => array(
274 'name' => 'custom_group_id',
275 'type' => CRM_Utils_Type::T_INT,
276 'title' => ts('Custom Group') ,
277 'description' => 'FK to civicrm_custom_group.',
278 'required' => true,
279 'table_name' => 'civicrm_custom_field',
280 'entity' => 'CustomField',
281 'bao' => 'CRM_Core_BAO_CustomField',
282 'localizable' => 0,
283 'FKClassName' => 'CRM_Core_DAO_CustomGroup',
284 'html' => array(
285 'type' => 'Select',
286 ) ,
287 'pseudoconstant' => array(
288 'table' => 'civicrm_custom_group',
289 'keyColumn' => 'id',
290 'labelColumn' => 'title',
291 )
292 ) ,
293 'name' => array(
294 'name' => 'name',
295 'type' => CRM_Utils_Type::T_STRING,
296 'title' => ts('Custom Field Name') ,
297 'description' => 'Variable name/programmatic handle for this group.',
298 'maxlength' => 64,
299 'size' => CRM_Utils_Type::BIG,
300 'table_name' => 'civicrm_custom_field',
301 'entity' => 'CustomField',
302 'bao' => 'CRM_Core_BAO_CustomField',
303 'localizable' => 0,
304 ) ,
305 'label' => array(
306 'name' => 'label',
307 'type' => CRM_Utils_Type::T_STRING,
308 'title' => ts('Custom Field Label') ,
309 'description' => 'Text for form field label (also friendly name for administering this custom property).',
310 'required' => true,
311 'maxlength' => 255,
312 'size' => CRM_Utils_Type::HUGE,
313 'table_name' => 'civicrm_custom_field',
314 'entity' => 'CustomField',
315 'bao' => 'CRM_Core_BAO_CustomField',
316 'localizable' => 1,
317 ) ,
318 'data_type' => array(
319 'name' => 'data_type',
320 'type' => CRM_Utils_Type::T_STRING,
321 'title' => ts('Custom Field Data Type') ,
322 'description' => 'Controls location of data storage in extended_data table.',
323 'required' => true,
324 'maxlength' => 16,
325 'size' => CRM_Utils_Type::TWELVE,
326 'table_name' => 'civicrm_custom_field',
327 'entity' => 'CustomField',
328 'bao' => 'CRM_Core_BAO_CustomField',
329 'localizable' => 0,
330 'html' => array(
331 'type' => 'Select',
332 ) ,
333 'pseudoconstant' => array(
334 'callback' => 'CRM_Core_BAO_CustomField::dataType',
335 )
336 ) ,
337 'html_type' => array(
338 'name' => 'html_type',
339 'type' => CRM_Utils_Type::T_STRING,
340 'title' => ts('Custom Field HTML Type') ,
341 'description' => 'HTML types plus several built-in extended types.',
342 'required' => true,
343 'maxlength' => 32,
344 'size' => CRM_Utils_Type::MEDIUM,
345 'table_name' => 'civicrm_custom_field',
346 'entity' => 'CustomField',
347 'bao' => 'CRM_Core_BAO_CustomField',
348 'localizable' => 0,
349 'pseudoconstant' => array(
350 'callback' => 'CRM_Core_SelectValues::customHtmlType',
351 )
352 ) ,
353 'default_value' => array(
354 'name' => 'default_value',
355 'type' => CRM_Utils_Type::T_STRING,
356 'title' => ts('Custom Field Default') ,
357 'description' => 'Use form_options.is_default for field_types which use options.',
358 'maxlength' => 255,
359 'size' => CRM_Utils_Type::HUGE,
360 'table_name' => 'civicrm_custom_field',
361 'entity' => 'CustomField',
362 'bao' => 'CRM_Core_BAO_CustomField',
363 'localizable' => 0,
364 ) ,
365 'is_required' => array(
366 'name' => 'is_required',
367 'type' => CRM_Utils_Type::T_BOOLEAN,
368 'title' => ts('Custom Field Is Required?') ,
369 'description' => 'Is a value required for this property.',
370 'table_name' => 'civicrm_custom_field',
371 'entity' => 'CustomField',
372 'bao' => 'CRM_Core_BAO_CustomField',
373 'localizable' => 0,
374 ) ,
375 'is_searchable' => array(
376 'name' => 'is_searchable',
377 'type' => CRM_Utils_Type::T_BOOLEAN,
378 'title' => ts('Allow Searching on Field?') ,
379 'description' => 'Is this property searchable.',
380 'table_name' => 'civicrm_custom_field',
381 'entity' => 'CustomField',
382 'bao' => 'CRM_Core_BAO_CustomField',
383 'localizable' => 0,
384 ) ,
385 'is_search_range' => array(
386 'name' => 'is_search_range',
387 'type' => CRM_Utils_Type::T_BOOLEAN,
388 'title' => ts('Search as a Range') ,
389 'description' => 'Is this property range searchable.',
390 'table_name' => 'civicrm_custom_field',
391 'entity' => 'CustomField',
392 'bao' => 'CRM_Core_BAO_CustomField',
393 'localizable' => 0,
394 ) ,
395 'weight' => array(
396 'name' => 'weight',
397 'type' => CRM_Utils_Type::T_INT,
398 'title' => ts('Order') ,
399 'description' => 'Controls field display order within an extended property group.',
400 'required' => true,
401 'default' => '1',
402 'table_name' => 'civicrm_custom_field',
403 'entity' => 'CustomField',
404 'bao' => 'CRM_Core_BAO_CustomField',
405 'localizable' => 0,
406 ) ,
407 'help_pre' => array(
408 'name' => 'help_pre',
409 'type' => CRM_Utils_Type::T_TEXT,
410 'title' => ts('Custom Field Pre Text') ,
411 'description' => 'Description and/or help text to display before this field.',
412 'table_name' => 'civicrm_custom_field',
413 'entity' => 'CustomField',
414 'bao' => 'CRM_Core_BAO_CustomField',
415 'localizable' => 1,
416 ) ,
417 'help_post' => array(
418 'name' => 'help_post',
419 'type' => CRM_Utils_Type::T_TEXT,
420 'title' => ts('Custom Field Post Text') ,
421 'description' => 'Description and/or help text to display after this field.',
422 'table_name' => 'civicrm_custom_field',
423 'entity' => 'CustomField',
424 'bao' => 'CRM_Core_BAO_CustomField',
425 'localizable' => 1,
426 ) ,
427 'mask' => array(
428 'name' => 'mask',
429 'type' => CRM_Utils_Type::T_STRING,
430 'title' => ts('Custom Field Formatting') ,
431 'description' => 'Optional format instructions for specific field types, like date types.',
432 'maxlength' => 64,
433 'size' => CRM_Utils_Type::BIG,
434 'table_name' => 'civicrm_custom_field',
435 'entity' => 'CustomField',
436 'bao' => 'CRM_Core_BAO_CustomField',
437 'localizable' => 0,
438 ) ,
439 'attributes' => array(
440 'name' => 'attributes',
441 'type' => CRM_Utils_Type::T_STRING,
442 'title' => ts('Custom Field Attributes') ,
443 'description' => 'Store collection of type-appropriate attributes, e.g. textarea needs rows/cols attributes',
444 'maxlength' => 255,
445 'size' => CRM_Utils_Type::HUGE,
446 'table_name' => 'civicrm_custom_field',
447 'entity' => 'CustomField',
448 'bao' => 'CRM_Core_BAO_CustomField',
449 'localizable' => 0,
450 ) ,
451 'javascript' => array(
452 'name' => 'javascript',
453 'type' => CRM_Utils_Type::T_STRING,
454 'title' => ts('Custom Field Javascript') ,
455 'description' => 'Optional scripting attributes for field.',
456 'maxlength' => 255,
457 'size' => CRM_Utils_Type::HUGE,
458 'table_name' => 'civicrm_custom_field',
459 'entity' => 'CustomField',
460 'bao' => 'CRM_Core_BAO_CustomField',
461 'localizable' => 0,
462 ) ,
463 'is_active' => array(
464 'name' => 'is_active',
465 'type' => CRM_Utils_Type::T_BOOLEAN,
466 'title' => ts('Custom Field Is Active?') ,
467 'description' => 'Is this property active?',
468 'table_name' => 'civicrm_custom_field',
469 'entity' => 'CustomField',
470 'bao' => 'CRM_Core_BAO_CustomField',
471 'localizable' => 0,
472 ) ,
473 'is_view' => array(
474 'name' => 'is_view',
475 'type' => CRM_Utils_Type::T_BOOLEAN,
476 'title' => ts('Field is Viewable') ,
477 'description' => 'Is this property set by PHP Code? A code field is viewable but not editable',
478 'table_name' => 'civicrm_custom_field',
479 'entity' => 'CustomField',
480 'bao' => 'CRM_Core_BAO_CustomField',
481 'localizable' => 0,
482 ) ,
483 'options_per_line' => array(
484 'name' => 'options_per_line',
485 'type' => CRM_Utils_Type::T_INT,
486 'title' => ts('Field Options Per Line') ,
487 'description' => 'number of options per line for checkbox and radio',
488 'table_name' => 'civicrm_custom_field',
489 'entity' => 'CustomField',
490 'bao' => 'CRM_Core_BAO_CustomField',
491 'localizable' => 0,
492 ) ,
493 'text_length' => array(
494 'name' => 'text_length',
495 'type' => CRM_Utils_Type::T_INT,
496 'title' => ts('Field Length') ,
497 'description' => 'field length if alphanumeric',
498 'table_name' => 'civicrm_custom_field',
499 'entity' => 'CustomField',
500 'bao' => 'CRM_Core_BAO_CustomField',
501 'localizable' => 0,
502 ) ,
503 'start_date_years' => array(
504 'name' => 'start_date_years',
505 'type' => CRM_Utils_Type::T_INT,
506 'title' => ts('Field Start Date') ,
507 'description' => 'Date may be up to start_date_years years prior to the current date.',
508 'table_name' => 'civicrm_custom_field',
509 'entity' => 'CustomField',
510 'bao' => 'CRM_Core_BAO_CustomField',
511 'localizable' => 0,
512 ) ,
513 'end_date_years' => array(
514 'name' => 'end_date_years',
515 'type' => CRM_Utils_Type::T_INT,
516 'title' => ts('Field End Date') ,
517 'description' => 'Date may be up to end_date_years years after the current date.',
518 'table_name' => 'civicrm_custom_field',
519 'entity' => 'CustomField',
520 'bao' => 'CRM_Core_BAO_CustomField',
521 'localizable' => 0,
522 ) ,
523 'date_format' => array(
524 'name' => 'date_format',
525 'type' => CRM_Utils_Type::T_STRING,
526 'title' => ts('Field Data Format') ,
527 'description' => 'date format for custom date',
528 'maxlength' => 64,
529 'size' => CRM_Utils_Type::BIG,
530 'table_name' => 'civicrm_custom_field',
531 'entity' => 'CustomField',
532 'bao' => 'CRM_Core_BAO_CustomField',
533 'localizable' => 0,
534 ) ,
535 'time_format' => array(
536 'name' => 'time_format',
537 'type' => CRM_Utils_Type::T_INT,
538 'title' => ts('Field Time Format') ,
539 'description' => 'time format for custom date',
540 'table_name' => 'civicrm_custom_field',
541 'entity' => 'CustomField',
542 'bao' => 'CRM_Core_BAO_CustomField',
543 'localizable' => 0,
544 ) ,
545 'note_columns' => array(
546 'name' => 'note_columns',
547 'type' => CRM_Utils_Type::T_INT,
548 'title' => ts('Field Note Columns') ,
549 'description' => ' Number of columns in Note Field ',
550 'table_name' => 'civicrm_custom_field',
551 'entity' => 'CustomField',
552 'bao' => 'CRM_Core_BAO_CustomField',
553 'localizable' => 0,
554 ) ,
555 'note_rows' => array(
556 'name' => 'note_rows',
557 'type' => CRM_Utils_Type::T_INT,
558 'title' => ts('Field Note Rows') ,
559 'description' => ' Number of rows in Note Field ',
560 'table_name' => 'civicrm_custom_field',
561 'entity' => 'CustomField',
562 'bao' => 'CRM_Core_BAO_CustomField',
563 'localizable' => 0,
564 ) ,
565 'column_name' => array(
566 'name' => 'column_name',
567 'type' => CRM_Utils_Type::T_STRING,
568 'title' => ts('Field Column Name') ,
569 'description' => 'Name of the column that holds the values for this field.',
570 'maxlength' => 255,
571 'size' => CRM_Utils_Type::HUGE,
572 'table_name' => 'civicrm_custom_field',
573 'entity' => 'CustomField',
574 'bao' => 'CRM_Core_BAO_CustomField',
575 'localizable' => 0,
576 ) ,
577 'option_group_id' => array(
578 'name' => 'option_group_id',
579 'type' => CRM_Utils_Type::T_INT,
580 'title' => ts('Field Option Group') ,
581 'description' => 'For elements with options, the option group id that is used',
582 'table_name' => 'civicrm_custom_field',
583 'entity' => 'CustomField',
584 'bao' => 'CRM_Core_BAO_CustomField',
585 'localizable' => 0,
586 ) ,
587 'filter' => array(
588 'name' => 'filter',
589 'type' => CRM_Utils_Type::T_STRING,
590 'title' => ts('Field Filter') ,
591 'description' => 'Stores Contact Get API params contact reference custom fields. May be used for other filters in the future.',
592 'maxlength' => 255,
593 'size' => CRM_Utils_Type::HUGE,
594 'table_name' => 'civicrm_custom_field',
595 'entity' => 'CustomField',
596 'bao' => 'CRM_Core_BAO_CustomField',
597 'localizable' => 0,
598 ) ,
599 'in_selector' => array(
600 'name' => 'in_selector',
601 'type' => CRM_Utils_Type::T_BOOLEAN,
602 'title' => ts('Field Display') ,
603 'description' => 'Should the multi-record custom field values be displayed in tab table listing',
604 'table_name' => 'civicrm_custom_field',
605 'entity' => 'CustomField',
606 'bao' => 'CRM_Core_BAO_CustomField',
607 'localizable' => 0,
608 ) ,
609 );
610 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
611 }
612 return Civi::$statics[__CLASS__]['fields'];
613 }
614 /**
615 * Return a mapping from field-name to the corresponding key (as used in fields()).
616 *
617 * @return array
618 * Array(string $name => string $uniqueName).
619 */
620 static function &fieldKeys() {
621 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
622 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
623 }
624 return Civi::$statics[__CLASS__]['fieldKeys'];
625 }
626 /**
627 * Returns the names of this table
628 *
629 * @return string
630 */
631 static function getTableName() {
632 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
633 }
634 /**
635 * Returns if this table needs to be logged
636 *
637 * @return boolean
638 */
639 function getLog() {
640 return self::$_log;
641 }
642 /**
643 * Returns the list of fields that can be imported
644 *
645 * @param bool $prefix
646 *
647 * @return array
648 */
649 static function &import($prefix = false) {
650 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'custom_field', $prefix, array());
651 return $r;
652 }
653 /**
654 * Returns the list of fields that can be exported
655 *
656 * @param bool $prefix
657 *
658 * @return array
659 */
660 static function &export($prefix = false) {
661 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'custom_field', $prefix, array());
662 return $r;
663 }
664 /**
665 * Returns the list of indices
666 */
667 public static function indices($localize = TRUE) {
668 $indices = array(
669 'UI_label_custom_group_id' => array(
670 'name' => 'UI_label_custom_group_id',
671 'field' => array(
672 0 => 'label',
673 1 => 'custom_group_id',
674 ) ,
675 'localizable' => true,
676 'unique' => true,
677 'sig' => 'civicrm_custom_field::1::label::custom_group_id',
678 ) ,
679 'UI_name_custom_group_id' => array(
680 'name' => 'UI_name_custom_group_id',
681 'field' => array(
682 0 => 'name',
683 1 => 'custom_group_id',
684 ) ,
685 'localizable' => false,
686 'unique' => true,
687 'sig' => 'civicrm_custom_field::1::name::custom_group_id',
688 ) ,
689 );
690 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
691 }
692 }