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