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