Merge pull request #22558 from eileenmcnaughton/coleman
[civicrm-core.git] / CRM / Contribute / DAO / Product.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Contribute/Product.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:91d2e693a0c58cadf111686646d057d6)
10 */
11
12 /**
13 * Database access object for the Product entity.
14 */
15 class CRM_Contribute_DAO_Product extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.4';
18 const COMPONENT = 'CiviContribute';
19
20 /**
21 * Static instance to hold the table name.
22 *
23 * @var string
24 */
25 public static $_tableName = 'civicrm_product';
26
27 /**
28 * Field to show when displaying a record.
29 *
30 * @var string
31 */
32 public static $_labelField = 'name';
33
34 /**
35 * Should CiviCRM log any modifications to this table in the civicrm_log table.
36 *
37 * @var bool
38 */
39 public static $_log = TRUE;
40
41 /**
42 * @var int|string|null
43 * (SQL type: int unsigned)
44 * Note that values will be retrieved from the database as a string.
45 */
46 public $id;
47
48 /**
49 * Required product/premium name
50 *
51 * @var string
52 * (SQL type: varchar(255))
53 * Note that values will be retrieved from the database as a string.
54 */
55 public $name;
56
57 /**
58 * Optional description of the product/premium.
59 *
60 * @var string|null
61 * (SQL type: text)
62 * Note that values will be retrieved from the database as a string.
63 */
64 public $description;
65
66 /**
67 * Optional product sku or code.
68 *
69 * @var string|null
70 * (SQL type: varchar(50))
71 * Note that values will be retrieved from the database as a string.
72 */
73 public $sku;
74
75 /**
76 * Store comma-delimited list of color, size, etc. options for the product.
77 *
78 * @var string|null
79 * (SQL type: text)
80 * Note that values will be retrieved from the database as a string.
81 */
82 public $options;
83
84 /**
85 * Full or relative URL to uploaded image - fullsize.
86 *
87 * @var string|null
88 * (SQL type: varchar(255))
89 * Note that values will be retrieved from the database as a string.
90 */
91 public $image;
92
93 /**
94 * Full or relative URL to image thumbnail.
95 *
96 * @var string|null
97 * (SQL type: varchar(255))
98 * Note that values will be retrieved from the database as a string.
99 */
100 public $thumbnail;
101
102 /**
103 * Sell price or market value for premiums. For tax-deductible contributions, this will be stored as non_deductible_amount in the contribution record.
104 *
105 * @var float|string|null
106 * (SQL type: decimal(20,2))
107 * Note that values will be retrieved from the database as a string.
108 */
109 public $price;
110
111 /**
112 * 3 character string, value from config setting or input via user.
113 *
114 * @var string|null
115 * (SQL type: varchar(3))
116 * Note that values will be retrieved from the database as a string.
117 */
118 public $currency;
119
120 /**
121 * FK to Financial Type.
122 *
123 * @var int|string|null
124 * (SQL type: int unsigned)
125 * Note that values will be retrieved from the database as a string.
126 */
127 public $financial_type_id;
128
129 /**
130 * Minimum contribution required to be eligible to select this premium.
131 *
132 * @var float|string|null
133 * (SQL type: decimal(20,2))
134 * Note that values will be retrieved from the database as a string.
135 */
136 public $min_contribution;
137
138 /**
139 * Actual cost of this product. Useful to determine net return from sale or using this as an incentive.
140 *
141 * @var float|string|null
142 * (SQL type: decimal(20,2))
143 * Note that values will be retrieved from the database as a string.
144 */
145 public $cost;
146
147 /**
148 * Disabling premium removes it from the premiums_premium join table below.
149 *
150 * @var bool|string
151 * (SQL type: tinyint)
152 * Note that values will be retrieved from the database as a string.
153 */
154 public $is_active;
155
156 /**
157 * Rolling means we set start/end based on current day, fixed means we set start/end for current year or month
158 * (e.g. 1 year + fixed -> we would set start/end for 1/1/06 thru 12/31/06 for any premium chosen in 2006)
159 *
160 * @var string|null
161 * (SQL type: varchar(8))
162 * Note that values will be retrieved from the database as a string.
163 */
164 public $period_type;
165
166 /**
167 * Month and day (MMDD) that fixed period type subscription or membership starts.
168 *
169 * @var int|string|null
170 * (SQL type: int)
171 * Note that values will be retrieved from the database as a string.
172 */
173 public $fixed_period_start_day;
174
175 /**
176 * @var string|null
177 * (SQL type: varchar(8))
178 * Note that values will be retrieved from the database as a string.
179 */
180 public $duration_unit;
181
182 /**
183 * Number of units for total duration of subscription, service, membership (e.g. 12 Months).
184 *
185 * @var int|string|null
186 * (SQL type: int)
187 * Note that values will be retrieved from the database as a string.
188 */
189 public $duration_interval;
190
191 /**
192 * Frequency unit and interval allow option to store actual delivery frequency for a subscription or service.
193 *
194 * @var string|null
195 * (SQL type: varchar(8))
196 * Note that values will be retrieved from the database as a string.
197 */
198 public $frequency_unit;
199
200 /**
201 * Number of units for delivery frequency of subscription, service, membership (e.g. every 3 Months).
202 *
203 * @var int|string|null
204 * (SQL type: int)
205 * Note that values will be retrieved from the database as a string.
206 */
207 public $frequency_interval;
208
209 /**
210 * Class constructor.
211 */
212 public function __construct() {
213 $this->__table = 'civicrm_product';
214 parent::__construct();
215 }
216
217 /**
218 * Returns localized title of this entity.
219 *
220 * @param bool $plural
221 * Whether to return the plural version of the title.
222 */
223 public static function getEntityTitle($plural = FALSE) {
224 return $plural ? ts('Products') : ts('Product');
225 }
226
227 /**
228 * Returns foreign keys and entity references.
229 *
230 * @return array
231 * [CRM_Core_Reference_Interface]
232 */
233 public static function getReferenceColumns() {
234 if (!isset(Civi::$statics[__CLASS__]['links'])) {
235 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
236 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
237 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
238 }
239 return Civi::$statics[__CLASS__]['links'];
240 }
241
242 /**
243 * Returns all the column names of this table
244 *
245 * @return array
246 */
247 public static function &fields() {
248 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
249 Civi::$statics[__CLASS__]['fields'] = [
250 'id' => [
251 'name' => 'id',
252 'type' => CRM_Utils_Type::T_INT,
253 'title' => ts('Product ID'),
254 'required' => TRUE,
255 'where' => 'civicrm_product.id',
256 'table_name' => 'civicrm_product',
257 'entity' => 'Product',
258 'bao' => 'CRM_Contribute_BAO_Product',
259 'localizable' => 0,
260 'html' => [
261 'type' => 'Number',
262 ],
263 'readonly' => TRUE,
264 'add' => '1.4',
265 ],
266 'product_name' => [
267 'name' => 'name',
268 'type' => CRM_Utils_Type::T_STRING,
269 'title' => ts('Product Name'),
270 'description' => ts('Required product/premium name'),
271 'required' => TRUE,
272 'maxlength' => 255,
273 'size' => CRM_Utils_Type::HUGE,
274 'where' => 'civicrm_product.name',
275 'export' => TRUE,
276 'table_name' => 'civicrm_product',
277 'entity' => 'Product',
278 'bao' => 'CRM_Contribute_BAO_Product',
279 'localizable' => 1,
280 'add' => '1.4',
281 ],
282 'description' => [
283 'name' => 'description',
284 'type' => CRM_Utils_Type::T_TEXT,
285 'title' => ts('Description'),
286 'description' => ts('Optional description of the product/premium.'),
287 'where' => 'civicrm_product.description',
288 'table_name' => 'civicrm_product',
289 'entity' => 'Product',
290 'bao' => 'CRM_Contribute_BAO_Product',
291 'localizable' => 1,
292 'add' => '1.4',
293 ],
294 'sku' => [
295 'name' => 'sku',
296 'type' => CRM_Utils_Type::T_STRING,
297 'title' => ts('SKU'),
298 'description' => ts('Optional product sku or code.'),
299 'maxlength' => 50,
300 'size' => CRM_Utils_Type::BIG,
301 'where' => 'civicrm_product.sku',
302 'export' => TRUE,
303 'table_name' => 'civicrm_product',
304 'entity' => 'Product',
305 'bao' => 'CRM_Contribute_BAO_Product',
306 'localizable' => 0,
307 'add' => '1.4',
308 ],
309 'options' => [
310 'name' => 'options',
311 'type' => CRM_Utils_Type::T_TEXT,
312 'title' => ts('Options'),
313 'description' => ts('Store comma-delimited list of color, size, etc. options for the product.'),
314 'where' => 'civicrm_product.options',
315 'table_name' => 'civicrm_product',
316 'entity' => 'Product',
317 'bao' => 'CRM_Contribute_BAO_Product',
318 'localizable' => 1,
319 'add' => '1.4',
320 ],
321 'image' => [
322 'name' => 'image',
323 'type' => CRM_Utils_Type::T_STRING,
324 'title' => ts('Image'),
325 'description' => ts('Full or relative URL to uploaded image - fullsize.'),
326 'maxlength' => 255,
327 'size' => CRM_Utils_Type::HUGE,
328 'where' => 'civicrm_product.image',
329 'table_name' => 'civicrm_product',
330 'entity' => 'Product',
331 'bao' => 'CRM_Contribute_BAO_Product',
332 'localizable' => 0,
333 'add' => '1.4',
334 ],
335 'thumbnail' => [
336 'name' => 'thumbnail',
337 'type' => CRM_Utils_Type::T_STRING,
338 'title' => ts('Thumbnail'),
339 'description' => ts('Full or relative URL to image thumbnail.'),
340 'maxlength' => 255,
341 'size' => CRM_Utils_Type::HUGE,
342 'where' => 'civicrm_product.thumbnail',
343 'table_name' => 'civicrm_product',
344 'entity' => 'Product',
345 'bao' => 'CRM_Contribute_BAO_Product',
346 'localizable' => 0,
347 'add' => '1.4',
348 ],
349 'price' => [
350 'name' => 'price',
351 'type' => CRM_Utils_Type::T_MONEY,
352 'title' => ts('Price'),
353 'description' => ts('Sell price or market value for premiums. For tax-deductible contributions, this will be stored as non_deductible_amount in the contribution record.'),
354 'precision' => [
355 20,
356 2,
357 ],
358 'where' => 'civicrm_product.price',
359 'table_name' => 'civicrm_product',
360 'entity' => 'Product',
361 'bao' => 'CRM_Contribute_BAO_Product',
362 'localizable' => 0,
363 'add' => '1.4',
364 ],
365 'currency' => [
366 'name' => 'currency',
367 'type' => CRM_Utils_Type::T_STRING,
368 'title' => ts('Currency'),
369 'description' => ts('3 character string, value from config setting or input via user.'),
370 'maxlength' => 3,
371 'size' => CRM_Utils_Type::FOUR,
372 'where' => 'civicrm_product.currency',
373 'default' => NULL,
374 'table_name' => 'civicrm_product',
375 'entity' => 'Product',
376 'bao' => 'CRM_Contribute_BAO_Product',
377 'localizable' => 0,
378 'html' => [
379 'type' => 'Select',
380 'label' => ts("Currency"),
381 ],
382 'pseudoconstant' => [
383 'table' => 'civicrm_currency',
384 'keyColumn' => 'name',
385 'labelColumn' => 'full_name',
386 'nameColumn' => 'name',
387 'abbrColumn' => 'symbol',
388 ],
389 'add' => '3.2',
390 ],
391 'financial_type_id' => [
392 'name' => 'financial_type_id',
393 'type' => CRM_Utils_Type::T_INT,
394 'title' => ts('Financial Type ID'),
395 'description' => ts('FK to Financial Type.'),
396 'where' => 'civicrm_product.financial_type_id',
397 'default' => NULL,
398 'table_name' => 'civicrm_product',
399 'entity' => 'Product',
400 'bao' => 'CRM_Contribute_BAO_Product',
401 'localizable' => 0,
402 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
403 'html' => [
404 'label' => ts("Financial Type"),
405 ],
406 'pseudoconstant' => [
407 'table' => 'civicrm_financial_type',
408 'keyColumn' => 'id',
409 'labelColumn' => 'name',
410 ],
411 'add' => '4.3',
412 ],
413 'min_contribution' => [
414 'name' => 'min_contribution',
415 'type' => CRM_Utils_Type::T_MONEY,
416 'title' => ts('Minimum Contribution'),
417 'description' => ts('Minimum contribution required to be eligible to select this premium.'),
418 'precision' => [
419 20,
420 2,
421 ],
422 'where' => 'civicrm_product.min_contribution',
423 'table_name' => 'civicrm_product',
424 'entity' => 'Product',
425 'bao' => 'CRM_Contribute_BAO_Product',
426 'localizable' => 0,
427 'add' => '1.4',
428 ],
429 'cost' => [
430 'name' => 'cost',
431 'type' => CRM_Utils_Type::T_MONEY,
432 'title' => ts('Cost'),
433 'description' => ts('Actual cost of this product. Useful to determine net return from sale or using this as an incentive.'),
434 'precision' => [
435 20,
436 2,
437 ],
438 'where' => 'civicrm_product.cost',
439 'table_name' => 'civicrm_product',
440 'entity' => 'Product',
441 'bao' => 'CRM_Contribute_BAO_Product',
442 'localizable' => 0,
443 'add' => '1.4',
444 ],
445 'is_active' => [
446 'name' => 'is_active',
447 'type' => CRM_Utils_Type::T_BOOLEAN,
448 'title' => ts('Is Active'),
449 'description' => ts('Disabling premium removes it from the premiums_premium join table below.'),
450 'required' => TRUE,
451 'where' => 'civicrm_product.is_active',
452 'table_name' => 'civicrm_product',
453 'entity' => 'Product',
454 'bao' => 'CRM_Contribute_BAO_Product',
455 'localizable' => 0,
456 'add' => '1.4',
457 ],
458 'period_type' => [
459 'name' => 'period_type',
460 'type' => CRM_Utils_Type::T_STRING,
461 'title' => ts('Period Type'),
462 'description' => ts('Rolling means we set start/end based on current day, fixed means we set start/end for current year or month
463 (e.g. 1 year + fixed -> we would set start/end for 1/1/06 thru 12/31/06 for any premium chosen in 2006) '),
464 'maxlength' => 8,
465 'size' => CRM_Utils_Type::EIGHT,
466 'where' => 'civicrm_product.period_type',
467 'default' => 'rolling',
468 'table_name' => 'civicrm_product',
469 'entity' => 'Product',
470 'bao' => 'CRM_Contribute_BAO_Product',
471 'localizable' => 0,
472 'html' => [
473 'type' => 'Select',
474 ],
475 'pseudoconstant' => [
476 'callback' => 'CRM_Core_SelectValues::periodType',
477 ],
478 'add' => '1.4',
479 ],
480 'fixed_period_start_day' => [
481 'name' => 'fixed_period_start_day',
482 'type' => CRM_Utils_Type::T_INT,
483 'title' => ts('Fixed Period Start Day'),
484 'description' => ts('Month and day (MMDD) that fixed period type subscription or membership starts.'),
485 'where' => 'civicrm_product.fixed_period_start_day',
486 'default' => '0101',
487 'table_name' => 'civicrm_product',
488 'entity' => 'Product',
489 'bao' => 'CRM_Contribute_BAO_Product',
490 'localizable' => 0,
491 'add' => '1.4',
492 ],
493 'duration_unit' => [
494 'name' => 'duration_unit',
495 'type' => CRM_Utils_Type::T_STRING,
496 'title' => ts('Duration Unit'),
497 'maxlength' => 8,
498 'size' => CRM_Utils_Type::EIGHT,
499 'where' => 'civicrm_product.duration_unit',
500 'default' => 'year',
501 'table_name' => 'civicrm_product',
502 'entity' => 'Product',
503 'bao' => 'CRM_Contribute_BAO_Product',
504 'localizable' => 0,
505 'html' => [
506 'type' => 'Select',
507 ],
508 'pseudoconstant' => [
509 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
510 ],
511 'add' => '1.4',
512 ],
513 'duration_interval' => [
514 'name' => 'duration_interval',
515 'type' => CRM_Utils_Type::T_INT,
516 'title' => ts('Duration Interval'),
517 'description' => ts('Number of units for total duration of subscription, service, membership (e.g. 12 Months).'),
518 'where' => 'civicrm_product.duration_interval',
519 'table_name' => 'civicrm_product',
520 'entity' => 'Product',
521 'bao' => 'CRM_Contribute_BAO_Product',
522 'localizable' => 0,
523 'add' => '1.4',
524 ],
525 'frequency_unit' => [
526 'name' => 'frequency_unit',
527 'type' => CRM_Utils_Type::T_STRING,
528 'title' => ts('Frequency Unit'),
529 'description' => ts('Frequency unit and interval allow option to store actual delivery frequency for a subscription or service.'),
530 'maxlength' => 8,
531 'size' => CRM_Utils_Type::EIGHT,
532 'where' => 'civicrm_product.frequency_unit',
533 'default' => 'month',
534 'table_name' => 'civicrm_product',
535 'entity' => 'Product',
536 'bao' => 'CRM_Contribute_BAO_Product',
537 'localizable' => 0,
538 'html' => [
539 'type' => 'Select',
540 ],
541 'pseudoconstant' => [
542 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
543 ],
544 'add' => '1.4',
545 ],
546 'frequency_interval' => [
547 'name' => 'frequency_interval',
548 'type' => CRM_Utils_Type::T_INT,
549 'title' => ts('Frequency Interval'),
550 'description' => ts('Number of units for delivery frequency of subscription, service, membership (e.g. every 3 Months).'),
551 'where' => 'civicrm_product.frequency_interval',
552 'table_name' => 'civicrm_product',
553 'entity' => 'Product',
554 'bao' => 'CRM_Contribute_BAO_Product',
555 'localizable' => 0,
556 'add' => '1.4',
557 ],
558 ];
559 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
560 }
561 return Civi::$statics[__CLASS__]['fields'];
562 }
563
564 /**
565 * Return a mapping from field-name to the corresponding key (as used in fields()).
566 *
567 * @return array
568 * Array(string $name => string $uniqueName).
569 */
570 public static function &fieldKeys() {
571 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
572 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
573 }
574 return Civi::$statics[__CLASS__]['fieldKeys'];
575 }
576
577 /**
578 * Returns the names of this table
579 *
580 * @return string
581 */
582 public static function getTableName() {
583 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
584 }
585
586 /**
587 * Returns if this table needs to be logged
588 *
589 * @return bool
590 */
591 public function getLog() {
592 return self::$_log;
593 }
594
595 /**
596 * Returns the list of fields that can be imported
597 *
598 * @param bool $prefix
599 *
600 * @return array
601 */
602 public static function &import($prefix = FALSE) {
603 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'product', $prefix, []);
604 return $r;
605 }
606
607 /**
608 * Returns the list of fields that can be exported
609 *
610 * @param bool $prefix
611 *
612 * @return array
613 */
614 public static function &export($prefix = FALSE) {
615 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'product', $prefix, []);
616 return $r;
617 }
618
619 /**
620 * Returns the list of indices
621 *
622 * @param bool $localize
623 *
624 * @return array
625 */
626 public static function indices($localize = TRUE) {
627 $indices = [];
628 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
629 }
630
631 }