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