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