Merge pull request #14367 from MegaphoneJon/financial-58
[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
a8fdb24e 9 * (GenCodeChecksum:8036ec1084e88e8fcd65e69072592388)
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',
a8fdb24e 316 'abbrColumn' => 'symbol',
e6ca0a57 317 ],
c3fc2621
CW
318 ],
319 'financial_type_id' => [
e501603b
TO
320 'name' => 'financial_type_id',
321 'type' => CRM_Utils_Type::T_INT,
c3fc2621 322 'title' => ts('Financial Type'),
215b423e 323 'description' => ts('FK to Financial Type.'),
a36434b9 324 'where' => 'civicrm_product.financial_type_id',
e501603b 325 'default' => 'NULL',
522a26c9 326 'table_name' => 'civicrm_product',
327 'entity' => 'Product',
45a83e42 328 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 329 'localizable' => 0,
e501603b 330 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
c3fc2621 331 'pseudoconstant' => [
e501603b
TO
332 'table' => 'civicrm_financial_type',
333 'keyColumn' => 'id',
334 'labelColumn' => 'name',
e6ca0a57 335 ],
c3fc2621
CW
336 ],
337 'min_contribution' => [
e501603b
TO
338 'name' => 'min_contribution',
339 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 340 'title' => ts('Minimum Contribution'),
215b423e 341 'description' => ts('Minimum contribution required to be eligible to select this premium.'),
c3fc2621 342 'precision' => [
e501603b 343 20,
fb607354 344 2,
c3fc2621 345 ],
a36434b9 346 'where' => 'civicrm_product.min_contribution',
522a26c9 347 'table_name' => 'civicrm_product',
348 'entity' => 'Product',
45a83e42 349 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 350 'localizable' => 0,
c3fc2621
CW
351 ],
352 'cost' => [
e501603b
TO
353 'name' => 'cost',
354 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 355 'title' => ts('Cost'),
215b423e 356 'description' => ts('Actual cost of this product. Useful to determine net return from sale or using this as an incentive.'),
c3fc2621 357 'precision' => [
e501603b 358 20,
fb607354 359 2,
c3fc2621 360 ],
a36434b9 361 'where' => 'civicrm_product.cost',
522a26c9 362 'table_name' => 'civicrm_product',
363 'entity' => 'Product',
45a83e42 364 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 365 'localizable' => 0,
c3fc2621
CW
366 ],
367 'is_active' => [
e501603b
TO
368 'name' => 'is_active',
369 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 370 'title' => ts('Is Active'),
215b423e 371 'description' => ts('Disabling premium removes it from the premiums_premium join table below.'),
c3fc2621 372 'required' => TRUE,
a36434b9 373 'where' => 'civicrm_product.is_active',
522a26c9 374 'table_name' => 'civicrm_product',
375 'entity' => 'Product',
45a83e42 376 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 377 'localizable' => 0,
c3fc2621
CW
378 ],
379 'period_type' => [
e501603b
TO
380 'name' => 'period_type',
381 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 382 'title' => ts('Period Type'),
215b423e 383 'description' => ts('Rolling means we set start/end based on current day, fixed means we set start/end for current year or month
384 (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
385 'maxlength' => 8,
386 'size' => CRM_Utils_Type::EIGHT,
a36434b9 387 'where' => 'civicrm_product.period_type',
e501603b 388 'default' => 'rolling',
522a26c9 389 'table_name' => 'civicrm_product',
390 'entity' => 'Product',
45a83e42 391 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 392 'localizable' => 0,
c3fc2621 393 'html' => [
e501603b 394 'type' => 'Select',
c3fc2621
CW
395 ],
396 'pseudoconstant' => [
e501603b 397 'callback' => 'CRM_Core_SelectValues::periodType',
e6ca0a57 398 ],
c3fc2621
CW
399 ],
400 'fixed_period_start_day' => [
e501603b
TO
401 'name' => 'fixed_period_start_day',
402 'type' => CRM_Utils_Type::T_INT,
c3fc2621 403 'title' => ts('Fixed Period Start Day'),
215b423e 404 'description' => ts('Month and day (MMDD) that fixed period type subscription or membership starts.'),
a36434b9 405 'where' => 'civicrm_product.fixed_period_start_day',
e501603b 406 'default' => '0101',
522a26c9 407 'table_name' => 'civicrm_product',
408 'entity' => 'Product',
45a83e42 409 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 410 'localizable' => 0,
c3fc2621
CW
411 ],
412 'duration_unit' => [
e501603b
TO
413 'name' => 'duration_unit',
414 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 415 'title' => ts('Duration Unit'),
e501603b
TO
416 'maxlength' => 8,
417 'size' => CRM_Utils_Type::EIGHT,
a36434b9 418 'where' => 'civicrm_product.duration_unit',
e501603b 419 'default' => 'year',
522a26c9 420 'table_name' => 'civicrm_product',
421 'entity' => 'Product',
45a83e42 422 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 423 'localizable' => 0,
c3fc2621 424 'html' => [
e501603b 425 'type' => 'Select',
c3fc2621
CW
426 ],
427 'pseudoconstant' => [
e501603b 428 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
e6ca0a57 429 ],
c3fc2621
CW
430 ],
431 'duration_interval' => [
e501603b
TO
432 'name' => 'duration_interval',
433 'type' => CRM_Utils_Type::T_INT,
c3fc2621 434 'title' => ts('Duration Interval'),
215b423e 435 'description' => ts('Number of units for total duration of subscription, service, membership (e.g. 12 Months).'),
a36434b9 436 'where' => 'civicrm_product.duration_interval',
522a26c9 437 'table_name' => 'civicrm_product',
438 'entity' => 'Product',
45a83e42 439 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 440 'localizable' => 0,
c3fc2621
CW
441 ],
442 'frequency_unit' => [
e501603b
TO
443 'name' => 'frequency_unit',
444 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 445 'title' => ts('Frequency Unit'),
215b423e 446 'description' => ts('Frequency unit and interval allow option to store actual delivery frequency for a subscription or service.'),
e501603b
TO
447 'maxlength' => 8,
448 'size' => CRM_Utils_Type::EIGHT,
a36434b9 449 'where' => 'civicrm_product.frequency_unit',
e501603b 450 'default' => 'month',
522a26c9 451 'table_name' => 'civicrm_product',
452 'entity' => 'Product',
45a83e42 453 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 454 'localizable' => 0,
c3fc2621 455 'html' => [
e501603b 456 'type' => 'Select',
c3fc2621
CW
457 ],
458 'pseudoconstant' => [
e501603b 459 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
e6ca0a57 460 ],
c3fc2621
CW
461 ],
462 'frequency_interval' => [
e501603b
TO
463 'name' => 'frequency_interval',
464 'type' => CRM_Utils_Type::T_INT,
c3fc2621 465 'title' => ts('Frequency Interval'),
215b423e 466 'description' => ts('Number of units for delivery frequency of subscription, service, membership (e.g. every 3 Months).'),
a36434b9 467 'where' => 'civicrm_product.frequency_interval',
522a26c9 468 'table_name' => 'civicrm_product',
469 'entity' => 'Product',
45a83e42 470 'bao' => 'CRM_Contribute_BAO_Product',
6a7e5e5d 471 'localizable' => 0,
c3fc2621
CW
472 ],
473 ];
346aaaba 474 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 475 }
346aaaba 476 return Civi::$statics[__CLASS__]['fields'];
e501603b 477 }
c3fc2621 478
e501603b 479 /**
bd8e0b14 480 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
481 *
482 * @return array
bd8e0b14 483 * Array(string $name => string $uniqueName).
e501603b 484 */
c3fc2621 485 public static function &fieldKeys() {
bd8e0b14
TO
486 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
487 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 488 }
bd8e0b14 489 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 490 }
c3fc2621 491
e501603b
TO
492 /**
493 * Returns the names of this table
494 *
495 * @return string
496 */
c3fc2621 497 public static function getTableName() {
e501603b
TO
498 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
499 }
c3fc2621 500
e501603b
TO
501 /**
502 * Returns if this table needs to be logged
503 *
c3fc2621 504 * @return bool
e501603b 505 */
c3fc2621 506 public function getLog() {
e501603b
TO
507 return self::$_log;
508 }
c3fc2621 509
e501603b
TO
510 /**
511 * Returns the list of fields that can be imported
512 *
513 * @param bool $prefix
514 *
515 * @return array
516 */
c3fc2621
CW
517 public static function &import($prefix = FALSE) {
518 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'product', $prefix, []);
60808919 519 return $r;
e501603b 520 }
c3fc2621 521
e501603b
TO
522 /**
523 * Returns the list of fields that can be exported
524 *
525 * @param bool $prefix
526 *
527 * @return array
528 */
c3fc2621
CW
529 public static function &export($prefix = FALSE) {
530 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'product', $prefix, []);
60808919 531 return $r;
e501603b 532 }
c3fc2621 533
e7a6b91a
AS
534 /**
535 * Returns the list of indices
c3fc2621
CW
536 *
537 * @param bool $localize
538 *
539 * @return array
e7a6b91a
AS
540 */
541 public static function indices($localize = TRUE) {
c3fc2621 542 $indices = [];
e7a6b91a
AS
543 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
544 }
c3fc2621 545
e501603b 546}