Merge pull request #14322 from AlainBenbassat/5.14
[civicrm-core.git] / CRM / Contribute / DAO / Product.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC (c) 2004-2019
6 *
7 * Generated from xml/schema/CRM/Contribute/Product.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:7db77c58d48112d25da791aba4586080)
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 unsigned
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 unsigned
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 boolean
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 foreign keys and entity references.
171 *
172 * @return array
173 * [CRM_Core_Reference_Interface]
174 */
175 public static function getReferenceColumns() {
176 if (!isset(Civi::$statics[__CLASS__]['links'])) {
177 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
178 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
179 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
180 }
181 return Civi::$statics[__CLASS__]['links'];
182 }
183
184 /**
185 * Returns all the column names of this table
186 *
187 * @return array
188 */
189 public static function &fields() {
190 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
191 Civi::$statics[__CLASS__]['fields'] = [
192 'id' => [
193 'name' => 'id',
194 'type' => CRM_Utils_Type::T_INT,
195 'title' => ts('Product ID'),
196 'required' => TRUE,
197 'where' => 'civicrm_product.id',
198 'table_name' => 'civicrm_product',
199 'entity' => 'Product',
200 'bao' => 'CRM_Contribute_BAO_Product',
201 'localizable' => 0,
202 ],
203 'product_name' => [
204 'name' => 'name',
205 'type' => CRM_Utils_Type::T_STRING,
206 'title' => ts('Product Name'),
207 'description' => ts('Required product/premium name'),
208 'required' => TRUE,
209 'maxlength' => 255,
210 'size' => CRM_Utils_Type::HUGE,
211 'where' => 'civicrm_product.name',
212 'export' => TRUE,
213 'table_name' => 'civicrm_product',
214 'entity' => 'Product',
215 'bao' => 'CRM_Contribute_BAO_Product',
216 'localizable' => 1,
217 ],
218 'description' => [
219 'name' => 'description',
220 'type' => CRM_Utils_Type::T_TEXT,
221 'title' => ts('Description'),
222 'description' => ts('Optional description of the product/premium.'),
223 'where' => 'civicrm_product.description',
224 'table_name' => 'civicrm_product',
225 'entity' => 'Product',
226 'bao' => 'CRM_Contribute_BAO_Product',
227 'localizable' => 1,
228 ],
229 'sku' => [
230 'name' => 'sku',
231 'type' => CRM_Utils_Type::T_STRING,
232 'title' => ts('SKU'),
233 'description' => ts('Optional product sku or code.'),
234 'maxlength' => 50,
235 'size' => CRM_Utils_Type::BIG,
236 'where' => 'civicrm_product.sku',
237 'export' => TRUE,
238 'table_name' => 'civicrm_product',
239 'entity' => 'Product',
240 'bao' => 'CRM_Contribute_BAO_Product',
241 'localizable' => 0,
242 ],
243 'options' => [
244 'name' => 'options',
245 'type' => CRM_Utils_Type::T_TEXT,
246 'title' => ts('Options'),
247 'description' => ts('Store comma-delimited list of color, size, etc. options for the product.'),
248 'where' => 'civicrm_product.options',
249 'table_name' => 'civicrm_product',
250 'entity' => 'Product',
251 'bao' => 'CRM_Contribute_BAO_Product',
252 'localizable' => 1,
253 ],
254 'image' => [
255 'name' => 'image',
256 'type' => CRM_Utils_Type::T_STRING,
257 'title' => ts('Image'),
258 'description' => ts('Full or relative URL to uploaded image - fullsize.'),
259 'maxlength' => 255,
260 'size' => CRM_Utils_Type::HUGE,
261 'where' => 'civicrm_product.image',
262 'table_name' => 'civicrm_product',
263 'entity' => 'Product',
264 'bao' => 'CRM_Contribute_BAO_Product',
265 'localizable' => 0,
266 ],
267 'thumbnail' => [
268 'name' => 'thumbnail',
269 'type' => CRM_Utils_Type::T_STRING,
270 'title' => ts('Thumbnail'),
271 'description' => ts('Full or relative URL to image thumbnail.'),
272 'maxlength' => 255,
273 'size' => CRM_Utils_Type::HUGE,
274 'where' => 'civicrm_product.thumbnail',
275 'table_name' => 'civicrm_product',
276 'entity' => 'Product',
277 'bao' => 'CRM_Contribute_BAO_Product',
278 'localizable' => 0,
279 ],
280 'price' => [
281 'name' => 'price',
282 'type' => CRM_Utils_Type::T_MONEY,
283 'title' => ts('Price'),
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.'),
285 'precision' => [
286 20,
287 2
288 ],
289 'where' => 'civicrm_product.price',
290 'table_name' => 'civicrm_product',
291 'entity' => 'Product',
292 'bao' => 'CRM_Contribute_BAO_Product',
293 'localizable' => 0,
294 ],
295 'currency' => [
296 'name' => 'currency',
297 'type' => CRM_Utils_Type::T_STRING,
298 'title' => ts('Currency'),
299 'description' => ts('3 character string, value from config setting or input via user.'),
300 'maxlength' => 3,
301 'size' => CRM_Utils_Type::FOUR,
302 'where' => 'civicrm_product.currency',
303 'default' => 'NULL',
304 'table_name' => 'civicrm_product',
305 'entity' => 'Product',
306 'bao' => 'CRM_Contribute_BAO_Product',
307 'localizable' => 0,
308 'html' => [
309 'type' => 'Select',
310 ],
311 'pseudoconstant' => [
312 'table' => 'civicrm_currency',
313 'keyColumn' => 'name',
314 'labelColumn' => 'full_name',
315 'nameColumn' => 'name',
316 ]
317 ],
318 'financial_type_id' => [
319 'name' => 'financial_type_id',
320 'type' => CRM_Utils_Type::T_INT,
321 'title' => ts('Financial Type'),
322 'description' => ts('FK to Financial Type.'),
323 'where' => 'civicrm_product.financial_type_id',
324 'default' => 'NULL',
325 'table_name' => 'civicrm_product',
326 'entity' => 'Product',
327 'bao' => 'CRM_Contribute_BAO_Product',
328 'localizable' => 0,
329 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
330 'pseudoconstant' => [
331 'table' => 'civicrm_financial_type',
332 'keyColumn' => 'id',
333 'labelColumn' => 'name',
334 ]
335 ],
336 'min_contribution' => [
337 'name' => 'min_contribution',
338 'type' => CRM_Utils_Type::T_MONEY,
339 'title' => ts('Minimum Contribution'),
340 'description' => ts('Minimum contribution required to be eligible to select this premium.'),
341 'precision' => [
342 20,
343 2
344 ],
345 'where' => 'civicrm_product.min_contribution',
346 'table_name' => 'civicrm_product',
347 'entity' => 'Product',
348 'bao' => 'CRM_Contribute_BAO_Product',
349 'localizable' => 0,
350 ],
351 'cost' => [
352 'name' => 'cost',
353 'type' => CRM_Utils_Type::T_MONEY,
354 'title' => ts('Cost'),
355 'description' => ts('Actual cost of this product. Useful to determine net return from sale or using this as an incentive.'),
356 'precision' => [
357 20,
358 2
359 ],
360 'where' => 'civicrm_product.cost',
361 'table_name' => 'civicrm_product',
362 'entity' => 'Product',
363 'bao' => 'CRM_Contribute_BAO_Product',
364 'localizable' => 0,
365 ],
366 'is_active' => [
367 'name' => 'is_active',
368 'type' => CRM_Utils_Type::T_BOOLEAN,
369 'title' => ts('Is Active'),
370 'description' => ts('Disabling premium removes it from the premiums_premium join table below.'),
371 'required' => TRUE,
372 'where' => 'civicrm_product.is_active',
373 'table_name' => 'civicrm_product',
374 'entity' => 'Product',
375 'bao' => 'CRM_Contribute_BAO_Product',
376 'localizable' => 0,
377 ],
378 'period_type' => [
379 'name' => 'period_type',
380 'type' => CRM_Utils_Type::T_STRING,
381 'title' => ts('Period Type'),
382 'description' => ts('Rolling means we set start/end based on current day, fixed means we set start/end for current year or month
383 (e.g. 1 year + fixed -> we would set start/end for 1/1/06 thru 12/31/06 for any premium chosen in 2006) '),
384 'maxlength' => 8,
385 'size' => CRM_Utils_Type::EIGHT,
386 'where' => 'civicrm_product.period_type',
387 'default' => 'rolling',
388 'table_name' => 'civicrm_product',
389 'entity' => 'Product',
390 'bao' => 'CRM_Contribute_BAO_Product',
391 'localizable' => 0,
392 'html' => [
393 'type' => 'Select',
394 ],
395 'pseudoconstant' => [
396 'callback' => 'CRM_Core_SelectValues::periodType',
397 ]
398 ],
399 'fixed_period_start_day' => [
400 'name' => 'fixed_period_start_day',
401 'type' => CRM_Utils_Type::T_INT,
402 'title' => ts('Fixed Period Start Day'),
403 'description' => ts('Month and day (MMDD) that fixed period type subscription or membership starts.'),
404 'where' => 'civicrm_product.fixed_period_start_day',
405 'default' => '0101',
406 'table_name' => 'civicrm_product',
407 'entity' => 'Product',
408 'bao' => 'CRM_Contribute_BAO_Product',
409 'localizable' => 0,
410 ],
411 'duration_unit' => [
412 'name' => 'duration_unit',
413 'type' => CRM_Utils_Type::T_STRING,
414 'title' => ts('Duration Unit'),
415 'maxlength' => 8,
416 'size' => CRM_Utils_Type::EIGHT,
417 'where' => 'civicrm_product.duration_unit',
418 'default' => 'year',
419 'table_name' => 'civicrm_product',
420 'entity' => 'Product',
421 'bao' => 'CRM_Contribute_BAO_Product',
422 'localizable' => 0,
423 'html' => [
424 'type' => 'Select',
425 ],
426 'pseudoconstant' => [
427 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
428 ]
429 ],
430 'duration_interval' => [
431 'name' => 'duration_interval',
432 'type' => CRM_Utils_Type::T_INT,
433 'title' => ts('Duration Interval'),
434 'description' => ts('Number of units for total duration of subscription, service, membership (e.g. 12 Months).'),
435 'where' => 'civicrm_product.duration_interval',
436 'table_name' => 'civicrm_product',
437 'entity' => 'Product',
438 'bao' => 'CRM_Contribute_BAO_Product',
439 'localizable' => 0,
440 ],
441 'frequency_unit' => [
442 'name' => 'frequency_unit',
443 'type' => CRM_Utils_Type::T_STRING,
444 'title' => ts('Frequency Unit'),
445 'description' => ts('Frequency unit and interval allow option to store actual delivery frequency for a subscription or service.'),
446 'maxlength' => 8,
447 'size' => CRM_Utils_Type::EIGHT,
448 'where' => 'civicrm_product.frequency_unit',
449 'default' => 'month',
450 'table_name' => 'civicrm_product',
451 'entity' => 'Product',
452 'bao' => 'CRM_Contribute_BAO_Product',
453 'localizable' => 0,
454 'html' => [
455 'type' => 'Select',
456 ],
457 'pseudoconstant' => [
458 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
459 ]
460 ],
461 'frequency_interval' => [
462 'name' => 'frequency_interval',
463 'type' => CRM_Utils_Type::T_INT,
464 'title' => ts('Frequency Interval'),
465 'description' => ts('Number of units for delivery frequency of subscription, service, membership (e.g. every 3 Months).'),
466 'where' => 'civicrm_product.frequency_interval',
467 'table_name' => 'civicrm_product',
468 'entity' => 'Product',
469 'bao' => 'CRM_Contribute_BAO_Product',
470 'localizable' => 0,
471 ],
472 ];
473 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
474 }
475 return Civi::$statics[__CLASS__]['fields'];
476 }
477
478 /**
479 * Return a mapping from field-name to the corresponding key (as used in fields()).
480 *
481 * @return array
482 * Array(string $name => string $uniqueName).
483 */
484 public static function &fieldKeys() {
485 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
486 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
487 }
488 return Civi::$statics[__CLASS__]['fieldKeys'];
489 }
490
491 /**
492 * Returns the names of this table
493 *
494 * @return string
495 */
496 public static function getTableName() {
497 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
498 }
499
500 /**
501 * Returns if this table needs to be logged
502 *
503 * @return bool
504 */
505 public function getLog() {
506 return self::$_log;
507 }
508
509 /**
510 * Returns the list of fields that can be imported
511 *
512 * @param bool $prefix
513 *
514 * @return array
515 */
516 public static function &import($prefix = FALSE) {
517 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'product', $prefix, []);
518 return $r;
519 }
520
521 /**
522 * Returns the list of fields that can be exported
523 *
524 * @param bool $prefix
525 *
526 * @return array
527 */
528 public static function &export($prefix = FALSE) {
529 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'product', $prefix, []);
530 return $r;
531 }
532
533 /**
534 * Returns the list of indices
535 *
536 * @param bool $localize
537 *
538 * @return array
539 */
540 public static function indices($localize = TRUE) {
541 $indices = [];
542 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
543 }
544
545 }