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