5 * @copyright CiviCRM LLC https://civicrm.org/licensing
7 * Generated from xml/schema/CRM/Contribute/Product.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:91d2e693a0c58cadf111686646d057d6)
13 * Database access object for the Product entity.
15 class CRM_Contribute_DAO_Product
extends CRM_Core_DAO
{
16 const EXT
= 'civicrm';
17 const TABLE_ADDED
= '1.4';
18 const COMPONENT
= 'CiviContribute';
21 * Static instance to hold the table name.
25 public static $_tableName = 'civicrm_product';
28 * Field to show when displaying a record.
32 public static $_labelField = 'name';
35 * Should CiviCRM log any modifications to this table in the civicrm_log table.
39 public static $_log = TRUE;
42 * @var int|string|null
43 * (SQL type: int unsigned)
44 * Note that values will be retrieved from the database as a string.
49 * Required product/premium name
52 * (SQL type: varchar(255))
53 * Note that values will be retrieved from the database as a string.
58 * Optional description of the product/premium.
62 * Note that values will be retrieved from the database as a string.
67 * Optional product sku or code.
70 * (SQL type: varchar(50))
71 * Note that values will be retrieved from the database as a string.
76 * Store comma-delimited list of color, size, etc. options for the product.
80 * Note that values will be retrieved from the database as a string.
85 * Full or relative URL to uploaded image - fullsize.
88 * (SQL type: varchar(255))
89 * Note that values will be retrieved from the database as a string.
94 * Full or relative URL to image thumbnail.
97 * (SQL type: varchar(255))
98 * Note that values will be retrieved from the database as a string.
103 * Sell price or market value for premiums. For tax-deductible contributions, this will be stored as non_deductible_amount in the contribution record.
105 * @var float|string|null
106 * (SQL type: decimal(20,2))
107 * Note that values will be retrieved from the database as a string.
112 * 3 character string, value from config setting or input via user.
115 * (SQL type: varchar(3))
116 * Note that values will be retrieved from the database as a string.
121 * FK to Financial Type.
123 * @var int|string|null
124 * (SQL type: int unsigned)
125 * Note that values will be retrieved from the database as a string.
127 public $financial_type_id;
130 * Minimum contribution required to be eligible to select this premium.
132 * @var float|string|null
133 * (SQL type: decimal(20,2))
134 * Note that values will be retrieved from the database as a string.
136 public $min_contribution;
139 * Actual cost of this product. Useful to determine net return from sale or using this as an incentive.
141 * @var float|string|null
142 * (SQL type: decimal(20,2))
143 * Note that values will be retrieved from the database as a string.
148 * Disabling premium removes it from the premiums_premium join table below.
151 * (SQL type: tinyint)
152 * Note that values will be retrieved from the database as a string.
157 * Rolling means we set start/end based on current day, fixed means we set start/end for current year or month
158 * (e.g. 1 year + fixed -> we would set start/end for 1/1/06 thru 12/31/06 for any premium chosen in 2006)
161 * (SQL type: varchar(8))
162 * Note that values will be retrieved from the database as a string.
167 * Month and day (MMDD) that fixed period type subscription or membership starts.
169 * @var int|string|null
171 * Note that values will be retrieved from the database as a string.
173 public $fixed_period_start_day;
177 * (SQL type: varchar(8))
178 * Note that values will be retrieved from the database as a string.
180 public $duration_unit;
183 * Number of units for total duration of subscription, service, membership (e.g. 12 Months).
185 * @var int|string|null
187 * Note that values will be retrieved from the database as a string.
189 public $duration_interval;
192 * Frequency unit and interval allow option to store actual delivery frequency for a subscription or service.
195 * (SQL type: varchar(8))
196 * Note that values will be retrieved from the database as a string.
198 public $frequency_unit;
201 * Number of units for delivery frequency of subscription, service, membership (e.g. every 3 Months).
203 * @var int|string|null
205 * Note that values will be retrieved from the database as a string.
207 public $frequency_interval;
212 public function __construct() {
213 $this->__table
= 'civicrm_product';
214 parent
::__construct();
218 * Returns localized title of this entity.
220 * @param bool $plural
221 * Whether to return the plural version of the title.
223 public static function getEntityTitle($plural = FALSE) {
224 return $plural ?
ts('Products') : ts('Product');
228 * Returns foreign keys and entity references.
231 * [CRM_Core_Reference_Interface]
233 public static function getReferenceColumns() {
234 if (!isset(Civi
::$statics[__CLASS__
]['links'])) {
235 Civi
::$statics[__CLASS__
]['links'] = static::createReferenceColumns(__CLASS__
);
236 Civi
::$statics[__CLASS__
]['links'][] = new CRM_Core_Reference_Basic(self
::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
237 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'links_callback', Civi
::$statics[__CLASS__
]['links']);
239 return Civi
::$statics[__CLASS__
]['links'];
243 * Returns all the column names of this table
247 public static function &fields() {
248 if (!isset(Civi
::$statics[__CLASS__
]['fields'])) {
249 Civi
::$statics[__CLASS__
]['fields'] = [
252 'type' => CRM_Utils_Type
::T_INT
,
253 'title' => ts('Product ID'),
255 'where' => 'civicrm_product.id',
256 'table_name' => 'civicrm_product',
257 'entity' => 'Product',
258 'bao' => 'CRM_Contribute_BAO_Product',
268 'type' => CRM_Utils_Type
::T_STRING
,
269 'title' => ts('Product Name'),
270 'description' => ts('Required product/premium name'),
273 'size' => CRM_Utils_Type
::HUGE
,
274 'where' => 'civicrm_product.name',
276 'table_name' => 'civicrm_product',
277 'entity' => 'Product',
278 'bao' => 'CRM_Contribute_BAO_Product',
283 'name' => 'description',
284 'type' => CRM_Utils_Type
::T_TEXT
,
285 'title' => ts('Description'),
286 'description' => ts('Optional description of the product/premium.'),
287 'where' => 'civicrm_product.description',
288 'table_name' => 'civicrm_product',
289 'entity' => 'Product',
290 'bao' => 'CRM_Contribute_BAO_Product',
296 'type' => CRM_Utils_Type
::T_STRING
,
297 'title' => ts('SKU'),
298 'description' => ts('Optional product sku or code.'),
300 'size' => CRM_Utils_Type
::BIG
,
301 'where' => 'civicrm_product.sku',
303 'table_name' => 'civicrm_product',
304 'entity' => 'Product',
305 'bao' => 'CRM_Contribute_BAO_Product',
311 'type' => CRM_Utils_Type
::T_TEXT
,
312 'title' => ts('Options'),
313 'description' => ts('Store comma-delimited list of color, size, etc. options for the product.'),
314 'where' => 'civicrm_product.options',
315 'table_name' => 'civicrm_product',
316 'entity' => 'Product',
317 'bao' => 'CRM_Contribute_BAO_Product',
323 'type' => CRM_Utils_Type
::T_STRING
,
324 'title' => ts('Image'),
325 'description' => ts('Full or relative URL to uploaded image - fullsize.'),
327 'size' => CRM_Utils_Type
::HUGE
,
328 'where' => 'civicrm_product.image',
329 'table_name' => 'civicrm_product',
330 'entity' => 'Product',
331 'bao' => 'CRM_Contribute_BAO_Product',
336 'name' => 'thumbnail',
337 'type' => CRM_Utils_Type
::T_STRING
,
338 'title' => ts('Thumbnail'),
339 'description' => ts('Full or relative URL to image thumbnail.'),
341 'size' => CRM_Utils_Type
::HUGE
,
342 'where' => 'civicrm_product.thumbnail',
343 'table_name' => 'civicrm_product',
344 'entity' => 'Product',
345 'bao' => 'CRM_Contribute_BAO_Product',
351 'type' => CRM_Utils_Type
::T_MONEY
,
352 'title' => ts('Price'),
353 '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.'),
358 'where' => 'civicrm_product.price',
359 'table_name' => 'civicrm_product',
360 'entity' => 'Product',
361 'bao' => 'CRM_Contribute_BAO_Product',
366 'name' => 'currency',
367 'type' => CRM_Utils_Type
::T_STRING
,
368 'title' => ts('Currency'),
369 'description' => ts('3 character string, value from config setting or input via user.'),
371 'size' => CRM_Utils_Type
::FOUR
,
372 'where' => 'civicrm_product.currency',
374 'table_name' => 'civicrm_product',
375 'entity' => 'Product',
376 'bao' => 'CRM_Contribute_BAO_Product',
380 'label' => ts("Currency"),
382 'pseudoconstant' => [
383 'table' => 'civicrm_currency',
384 'keyColumn' => 'name',
385 'labelColumn' => 'full_name',
386 'nameColumn' => 'name',
387 'abbrColumn' => 'symbol',
391 'financial_type_id' => [
392 'name' => 'financial_type_id',
393 'type' => CRM_Utils_Type
::T_INT
,
394 'title' => ts('Financial Type ID'),
395 'description' => ts('FK to Financial Type.'),
396 'where' => 'civicrm_product.financial_type_id',
398 'table_name' => 'civicrm_product',
399 'entity' => 'Product',
400 'bao' => 'CRM_Contribute_BAO_Product',
402 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
404 'label' => ts("Financial Type"),
406 'pseudoconstant' => [
407 'table' => 'civicrm_financial_type',
409 'labelColumn' => 'name',
413 'min_contribution' => [
414 'name' => 'min_contribution',
415 'type' => CRM_Utils_Type
::T_MONEY
,
416 'title' => ts('Minimum Contribution'),
417 'description' => ts('Minimum contribution required to be eligible to select this premium.'),
422 'where' => 'civicrm_product.min_contribution',
423 'table_name' => 'civicrm_product',
424 'entity' => 'Product',
425 'bao' => 'CRM_Contribute_BAO_Product',
431 'type' => CRM_Utils_Type
::T_MONEY
,
432 'title' => ts('Cost'),
433 'description' => ts('Actual cost of this product. Useful to determine net return from sale or using this as an incentive.'),
438 'where' => 'civicrm_product.cost',
439 'table_name' => 'civicrm_product',
440 'entity' => 'Product',
441 'bao' => 'CRM_Contribute_BAO_Product',
446 'name' => 'is_active',
447 'type' => CRM_Utils_Type
::T_BOOLEAN
,
448 'title' => ts('Is Active'),
449 'description' => ts('Disabling premium removes it from the premiums_premium join table below.'),
451 'where' => 'civicrm_product.is_active',
452 'table_name' => 'civicrm_product',
453 'entity' => 'Product',
454 'bao' => 'CRM_Contribute_BAO_Product',
459 'name' => 'period_type',
460 'type' => CRM_Utils_Type
::T_STRING
,
461 'title' => ts('Period Type'),
462 'description' => ts('Rolling means we set start/end based on current day, fixed means we set start/end for current year or month
463 (e.g. 1 year + fixed -> we would set start/end for 1/1/06 thru 12/31/06 for any premium chosen in 2006) '),
465 'size' => CRM_Utils_Type
::EIGHT
,
466 'where' => 'civicrm_product.period_type',
467 'default' => 'rolling',
468 'table_name' => 'civicrm_product',
469 'entity' => 'Product',
470 'bao' => 'CRM_Contribute_BAO_Product',
475 'pseudoconstant' => [
476 'callback' => 'CRM_Core_SelectValues::periodType',
480 'fixed_period_start_day' => [
481 'name' => 'fixed_period_start_day',
482 'type' => CRM_Utils_Type
::T_INT
,
483 'title' => ts('Fixed Period Start Day'),
484 'description' => ts('Month and day (MMDD) that fixed period type subscription or membership starts.'),
485 'where' => 'civicrm_product.fixed_period_start_day',
487 'table_name' => 'civicrm_product',
488 'entity' => 'Product',
489 'bao' => 'CRM_Contribute_BAO_Product',
494 'name' => 'duration_unit',
495 'type' => CRM_Utils_Type
::T_STRING
,
496 'title' => ts('Duration Unit'),
498 'size' => CRM_Utils_Type
::EIGHT
,
499 'where' => 'civicrm_product.duration_unit',
501 'table_name' => 'civicrm_product',
502 'entity' => 'Product',
503 'bao' => 'CRM_Contribute_BAO_Product',
508 'pseudoconstant' => [
509 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
513 'duration_interval' => [
514 'name' => 'duration_interval',
515 'type' => CRM_Utils_Type
::T_INT
,
516 'title' => ts('Duration Interval'),
517 'description' => ts('Number of units for total duration of subscription, service, membership (e.g. 12 Months).'),
518 'where' => 'civicrm_product.duration_interval',
519 'table_name' => 'civicrm_product',
520 'entity' => 'Product',
521 'bao' => 'CRM_Contribute_BAO_Product',
525 'frequency_unit' => [
526 'name' => 'frequency_unit',
527 'type' => CRM_Utils_Type
::T_STRING
,
528 'title' => ts('Frequency Unit'),
529 'description' => ts('Frequency unit and interval allow option to store actual delivery frequency for a subscription or service.'),
531 'size' => CRM_Utils_Type
::EIGHT
,
532 'where' => 'civicrm_product.frequency_unit',
533 'default' => 'month',
534 'table_name' => 'civicrm_product',
535 'entity' => 'Product',
536 'bao' => 'CRM_Contribute_BAO_Product',
541 'pseudoconstant' => [
542 'callback' => 'CRM_Core_SelectValues::getPremiumUnits',
546 'frequency_interval' => [
547 'name' => 'frequency_interval',
548 'type' => CRM_Utils_Type
::T_INT
,
549 'title' => ts('Frequency Interval'),
550 'description' => ts('Number of units for delivery frequency of subscription, service, membership (e.g. every 3 Months).'),
551 'where' => 'civicrm_product.frequency_interval',
552 'table_name' => 'civicrm_product',
553 'entity' => 'Product',
554 'bao' => 'CRM_Contribute_BAO_Product',
559 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
561 return Civi
::$statics[__CLASS__
]['fields'];
565 * Return a mapping from field-name to the corresponding key (as used in fields()).
568 * Array(string $name => string $uniqueName).
570 public static function &fieldKeys() {
571 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
572 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
574 return Civi
::$statics[__CLASS__
]['fieldKeys'];
578 * Returns the names of this table
582 public static function getTableName() {
583 return CRM_Core_DAO
::getLocaleTableName(self
::$_tableName);
587 * Returns if this table needs to be logged
591 public function getLog() {
596 * Returns the list of fields that can be imported
598 * @param bool $prefix
602 public static function &import($prefix = FALSE) {
603 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'product', $prefix, []);
608 * Returns the list of fields that can be exported
610 * @param bool $prefix
614 public static function &export($prefix = FALSE) {
615 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'product', $prefix, []);
620 * Returns the list of indices
622 * @param bool $localize
626 public static function indices($localize = TRUE) {
628 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;