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