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