Add "labelField" metadata to entities
[civicrm-core.git] / CRM / Price / DAO / LineItem.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Price/LineItem.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:352b3e74d3a66e445f53670cecaf6d02)
10 */
11
12 /**
13 * Database access object for the LineItem entity.
14 */
15 class CRM_Price_DAO_LineItem extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.7';
18 const COMPONENT = 'CiviContribute';
19
20 /**
21 * Static instance to hold the table name.
22 *
23 * @var string
24 */
25 public static $_tableName = 'civicrm_line_item';
26
27 /**
28 * Should CiviCRM log any modifications to this table in the civicrm_log table.
29 *
30 * @var bool
31 */
32 public static $_log = TRUE;
33
34 /**
35 * Line Item
36 *
37 * @var int
38 */
39 public $id;
40
41 /**
42 * table which has the transaction
43 *
44 * @var string
45 */
46 public $entity_table;
47
48 /**
49 * entry in table
50 *
51 * @var int
52 */
53 public $entity_id;
54
55 /**
56 * FK to civicrm_contribution
57 *
58 * @var int
59 */
60 public $contribution_id;
61
62 /**
63 * FK to civicrm_price_field
64 *
65 * @var int
66 */
67 public $price_field_id;
68
69 /**
70 * descriptive label for item - from price_field_value.label
71 *
72 * @var string
73 */
74 public $label;
75
76 /**
77 * How many items ordered
78 *
79 * @var float
80 */
81 public $qty;
82
83 /**
84 * price of each item
85 *
86 * @var float
87 */
88 public $unit_price;
89
90 /**
91 * qty * unit_price
92 *
93 * @var float
94 */
95 public $line_total;
96
97 /**
98 * Participant count for field
99 *
100 * @var int
101 */
102 public $participant_count;
103
104 /**
105 * FK to civicrm_price_field_value
106 *
107 * @var int
108 */
109 public $price_field_value_id;
110
111 /**
112 * FK to Financial Type.
113 *
114 * @var int
115 */
116 public $financial_type_id;
117
118 /**
119 * Portion of total amount which is NOT tax deductible.
120 *
121 * @var float
122 */
123 public $non_deductible_amount;
124
125 /**
126 * tax of each item
127 *
128 * @var float
129 */
130 public $tax_amount;
131
132 /**
133 * Class constructor.
134 */
135 public function __construct() {
136 $this->__table = 'civicrm_line_item';
137 parent::__construct();
138 }
139
140 /**
141 * Returns localized title of this entity.
142 *
143 * @param bool $plural
144 * Whether to return the plural version of the title.
145 */
146 public static function getEntityTitle($plural = FALSE) {
147 return $plural ? ts('Line Items') : ts('Line Item');
148 }
149
150 /**
151 * Returns foreign keys and entity references.
152 *
153 * @return array
154 * [CRM_Core_Reference_Interface]
155 */
156 public static function getReferenceColumns() {
157 if (!isset(Civi::$statics[__CLASS__]['links'])) {
158 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
159 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_id', 'civicrm_contribution', 'id');
160 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'price_field_id', 'civicrm_price_field', 'id');
161 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'price_field_value_id', 'civicrm_price_field_value', 'id');
162 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
163 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), 'entity_id', NULL, 'id', 'entity_table');
164 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
165 }
166 return Civi::$statics[__CLASS__]['links'];
167 }
168
169 /**
170 * Returns all the column names of this table
171 *
172 * @return array
173 */
174 public static function &fields() {
175 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
176 Civi::$statics[__CLASS__]['fields'] = [
177 'id' => [
178 'name' => 'id',
179 'type' => CRM_Utils_Type::T_INT,
180 'title' => ts('Line Item ID'),
181 'description' => ts('Line Item'),
182 'required' => TRUE,
183 'where' => 'civicrm_line_item.id',
184 'table_name' => 'civicrm_line_item',
185 'entity' => 'LineItem',
186 'bao' => 'CRM_Price_BAO_LineItem',
187 'localizable' => 0,
188 'add' => '1.7',
189 ],
190 'entity_table' => [
191 'name' => 'entity_table',
192 'type' => CRM_Utils_Type::T_STRING,
193 'title' => ts('Line Item Entity Type'),
194 'description' => ts('table which has the transaction'),
195 'required' => TRUE,
196 'maxlength' => 64,
197 'size' => CRM_Utils_Type::BIG,
198 'where' => 'civicrm_line_item.entity_table',
199 'table_name' => 'civicrm_line_item',
200 'entity' => 'LineItem',
201 'bao' => 'CRM_Price_BAO_LineItem',
202 'localizable' => 0,
203 'add' => '1.7',
204 ],
205 'entity_id' => [
206 'name' => 'entity_id',
207 'type' => CRM_Utils_Type::T_INT,
208 'title' => ts('Line Item Entity'),
209 'description' => ts('entry in table'),
210 'required' => TRUE,
211 'where' => 'civicrm_line_item.entity_id',
212 'table_name' => 'civicrm_line_item',
213 'entity' => 'LineItem',
214 'bao' => 'CRM_Price_BAO_LineItem',
215 'localizable' => 0,
216 'add' => '1.7',
217 ],
218 'contribution_id' => [
219 'name' => 'contribution_id',
220 'type' => CRM_Utils_Type::T_INT,
221 'title' => ts('Line Item Contribution'),
222 'description' => ts('FK to civicrm_contribution'),
223 'where' => 'civicrm_line_item.contribution_id',
224 'table_name' => 'civicrm_line_item',
225 'entity' => 'LineItem',
226 'bao' => 'CRM_Price_BAO_LineItem',
227 'localizable' => 0,
228 'FKClassName' => 'CRM_Contribute_DAO_Contribution',
229 'add' => '4.5',
230 ],
231 'price_field_id' => [
232 'name' => 'price_field_id',
233 'type' => CRM_Utils_Type::T_INT,
234 'title' => ts('Line Item Price Field'),
235 'description' => ts('FK to civicrm_price_field'),
236 'where' => 'civicrm_line_item.price_field_id',
237 'table_name' => 'civicrm_line_item',
238 'entity' => 'LineItem',
239 'bao' => 'CRM_Price_BAO_LineItem',
240 'localizable' => 0,
241 'FKClassName' => 'CRM_Price_DAO_PriceField',
242 'pseudoconstant' => [
243 'table' => 'civicrm_price_field',
244 'keyColumn' => 'id',
245 'labelColumn' => 'label',
246 'nameColumn' => 'name',
247 ],
248 'add' => '1.7',
249 ],
250 'label' => [
251 'name' => 'label',
252 'type' => CRM_Utils_Type::T_STRING,
253 'title' => ts('Line Item Label'),
254 'description' => ts('descriptive label for item - from price_field_value.label'),
255 'maxlength' => 255,
256 'size' => CRM_Utils_Type::HUGE,
257 'where' => 'civicrm_line_item.label',
258 'default' => 'NULL',
259 'table_name' => 'civicrm_line_item',
260 'entity' => 'LineItem',
261 'bao' => 'CRM_Price_BAO_LineItem',
262 'localizable' => 0,
263 'html' => [
264 'type' => 'Text',
265 ],
266 'add' => '1.7',
267 ],
268 'qty' => [
269 'name' => 'qty',
270 'type' => CRM_Utils_Type::T_MONEY,
271 'title' => ts('Line Item Quantity'),
272 'description' => ts('How many items ordered'),
273 'required' => TRUE,
274 'precision' => [
275 20,
276 2,
277 ],
278 'where' => 'civicrm_line_item.qty',
279 'table_name' => 'civicrm_line_item',
280 'entity' => 'LineItem',
281 'bao' => 'CRM_Price_BAO_LineItem',
282 'localizable' => 0,
283 'html' => [
284 'type' => 'Text',
285 ],
286 'add' => '1.7',
287 ],
288 'unit_price' => [
289 'name' => 'unit_price',
290 'type' => CRM_Utils_Type::T_MONEY,
291 'title' => ts('Unit Price'),
292 'description' => ts('price of each item'),
293 'required' => TRUE,
294 'precision' => [
295 20,
296 2,
297 ],
298 'where' => 'civicrm_line_item.unit_price',
299 'table_name' => 'civicrm_line_item',
300 'entity' => 'LineItem',
301 'bao' => 'CRM_Price_BAO_LineItem',
302 'localizable' => 0,
303 'html' => [
304 'type' => 'Text',
305 ],
306 'add' => '1.7',
307 ],
308 'line_total' => [
309 'name' => 'line_total',
310 'type' => CRM_Utils_Type::T_MONEY,
311 'title' => ts('Line Item Total'),
312 'description' => ts('qty * unit_price'),
313 'required' => TRUE,
314 'precision' => [
315 20,
316 2,
317 ],
318 'where' => 'civicrm_line_item.line_total',
319 'table_name' => 'civicrm_line_item',
320 'entity' => 'LineItem',
321 'bao' => 'CRM_Price_BAO_LineItem',
322 'localizable' => 0,
323 'add' => '1.7',
324 ],
325 'participant_count' => [
326 'name' => 'participant_count',
327 'type' => CRM_Utils_Type::T_INT,
328 'title' => ts('Line Item Participant Count'),
329 'description' => ts('Participant count for field'),
330 'where' => 'civicrm_line_item.participant_count',
331 'default' => 'NULL',
332 'table_name' => 'civicrm_line_item',
333 'entity' => 'LineItem',
334 'bao' => 'CRM_Price_BAO_LineItem',
335 'localizable' => 0,
336 'html' => [
337 'type' => 'Text',
338 ],
339 'add' => '3.2',
340 ],
341 'price_field_value_id' => [
342 'name' => 'price_field_value_id',
343 'type' => CRM_Utils_Type::T_INT,
344 'title' => ts('Line Item Option'),
345 'description' => ts('FK to civicrm_price_field_value'),
346 'where' => 'civicrm_line_item.price_field_value_id',
347 'default' => 'NULL',
348 'table_name' => 'civicrm_line_item',
349 'entity' => 'LineItem',
350 'bao' => 'CRM_Price_BAO_LineItem',
351 'localizable' => 0,
352 'FKClassName' => 'CRM_Price_DAO_PriceFieldValue',
353 'pseudoconstant' => [
354 'table' => 'civicrm_price_field_value',
355 'keyColumn' => 'id',
356 'labelColumn' => 'label',
357 'nameColumn' => 'name',
358 ],
359 'add' => '3.3',
360 ],
361 'financial_type_id' => [
362 'name' => 'financial_type_id',
363 'type' => CRM_Utils_Type::T_INT,
364 'title' => ts('Financial Type ID'),
365 'description' => ts('FK to Financial Type.'),
366 'where' => 'civicrm_line_item.financial_type_id',
367 'default' => 'NULL',
368 'table_name' => 'civicrm_line_item',
369 'entity' => 'LineItem',
370 'bao' => 'CRM_Price_BAO_LineItem',
371 'localizable' => 0,
372 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
373 'html' => [
374 'type' => 'Select',
375 'label' => ts("Financial Type"),
376 ],
377 'pseudoconstant' => [
378 'table' => 'civicrm_financial_type',
379 'keyColumn' => 'id',
380 'labelColumn' => 'name',
381 ],
382 'add' => '4.3',
383 ],
384 'non_deductible_amount' => [
385 'name' => 'non_deductible_amount',
386 'type' => CRM_Utils_Type::T_MONEY,
387 'title' => ts('Non-deductible Amount'),
388 'description' => ts('Portion of total amount which is NOT tax deductible.'),
389 'required' => TRUE,
390 'precision' => [
391 20,
392 2,
393 ],
394 'where' => 'civicrm_line_item.non_deductible_amount',
395 'headerPattern' => '/non?.?deduct/i',
396 'dataPattern' => '/^\d+(\.\d{2})?$/',
397 'default' => '0.0',
398 'table_name' => 'civicrm_line_item',
399 'entity' => 'LineItem',
400 'bao' => 'CRM_Price_BAO_LineItem',
401 'localizable' => 0,
402 'html' => [
403 'type' => 'Text',
404 ],
405 'add' => '4.7',
406 ],
407 'tax_amount' => [
408 'name' => 'tax_amount',
409 'type' => CRM_Utils_Type::T_MONEY,
410 'title' => ts('Tax Amount'),
411 'description' => ts('tax of each item'),
412 'precision' => [
413 20,
414 2,
415 ],
416 'import' => TRUE,
417 'where' => 'civicrm_line_item.tax_amount',
418 'headerPattern' => '/tax(.?am(ou)?nt)?/i',
419 'dataPattern' => '/^\d+(\.\d{2})?$/',
420 'export' => TRUE,
421 'table_name' => 'civicrm_line_item',
422 'entity' => 'LineItem',
423 'bao' => 'CRM_Price_BAO_LineItem',
424 'localizable' => 0,
425 'html' => [
426 'type' => 'Text',
427 ],
428 'add' => '4.6',
429 ],
430 ];
431 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
432 }
433 return Civi::$statics[__CLASS__]['fields'];
434 }
435
436 /**
437 * Return a mapping from field-name to the corresponding key (as used in fields()).
438 *
439 * @return array
440 * Array(string $name => string $uniqueName).
441 */
442 public static function &fieldKeys() {
443 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
444 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
445 }
446 return Civi::$statics[__CLASS__]['fieldKeys'];
447 }
448
449 /**
450 * Returns the names of this table
451 *
452 * @return string
453 */
454 public static function getTableName() {
455 return self::$_tableName;
456 }
457
458 /**
459 * Returns if this table needs to be logged
460 *
461 * @return bool
462 */
463 public function getLog() {
464 return self::$_log;
465 }
466
467 /**
468 * Returns the list of fields that can be imported
469 *
470 * @param bool $prefix
471 *
472 * @return array
473 */
474 public static function &import($prefix = FALSE) {
475 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'line_item', $prefix, []);
476 return $r;
477 }
478
479 /**
480 * Returns the list of fields that can be exported
481 *
482 * @param bool $prefix
483 *
484 * @return array
485 */
486 public static function &export($prefix = FALSE) {
487 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'line_item', $prefix, []);
488 return $r;
489 }
490
491 /**
492 * Returns the list of indices
493 *
494 * @param bool $localize
495 *
496 * @return array
497 */
498 public static function indices($localize = TRUE) {
499 $indices = [
500 'index_entity' => [
501 'name' => 'index_entity',
502 'field' => [
503 0 => 'entity_table',
504 1 => 'entity_id',
505 ],
506 'localizable' => FALSE,
507 'sig' => 'civicrm_line_item::0::entity_table::entity_id',
508 ],
509 'UI_line_item_value' => [
510 'name' => 'UI_line_item_value',
511 'field' => [
512 0 => 'entity_table',
513 1 => 'entity_id',
514 2 => 'contribution_id',
515 3 => 'price_field_value_id',
516 4 => 'price_field_id',
517 ],
518 'localizable' => FALSE,
519 'unique' => TRUE,
520 'sig' => 'civicrm_line_item::1::entity_table::entity_id::contribution_id::price_field_value_id::price_field_id',
521 ],
522 ];
523 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
524 }
525
526 }