[Ref] Minor code extraction
[civicrm-core.git] / CRM / Price / DAO / PriceSet.php
CommitLineData
e501603b 1<?php
c3fc2621 2
e501603b
TO
3/**
4 * @package CRM
ca5cec67 5 * @copyright CiviCRM LLC https://civicrm.org/licensing
e501603b
TO
6 *
7 * Generated from xml/schema/CRM/Price/PriceSet.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
f5e61d50 9 * (GenCodeChecksum:98eebd80f22712ce0809cec244b6f92a)
e501603b 10 */
c3fc2621 11
f41f0342 12/**
c3fc2621 13 * Database access object for the PriceSet entity.
f41f0342 14 */
e501603b 15class CRM_Price_DAO_PriceSet extends CRM_Core_DAO {
929a1c14
CW
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.8';
c3fc2621 18
e501603b 19 /**
f41f0342 20 * Static instance to hold the table name.
e501603b
TO
21 *
22 * @var string
23 */
fa45b5b9 24 public static $_tableName = 'civicrm_price_set';
c3fc2621 25
e501603b 26 /**
f41f0342 27 * Should CiviCRM log any modifications to this table in the civicrm_log table.
e501603b 28 *
c3fc2621 29 * @var bool
e501603b 30 */
fa45b5b9 31 public static $_log = TRUE;
c3fc2621 32
e501603b
TO
33 /**
34 * Price Set
35 *
e6ca0a57 36 * @var int
e501603b
TO
37 */
38 public $id;
c3fc2621 39
e501603b
TO
40 /**
41 * Which Domain is this price-set for
42 *
e6ca0a57 43 * @var int
e501603b
TO
44 */
45 public $domain_id;
c3fc2621 46
e501603b
TO
47 /**
48 * Variable name/programmatic handle for this set of price fields.
49 *
50 * @var string
51 */
52 public $name;
c3fc2621 53
e501603b
TO
54 /**
55 * Displayed title for the Price Set.
56 *
57 * @var string
58 */
59 public $title;
c3fc2621 60
e501603b
TO
61 /**
62 * Is this price set active
63 *
e6ca0a57 64 * @var bool
e501603b
TO
65 */
66 public $is_active;
c3fc2621 67
e501603b
TO
68 /**
69 * Description and/or help text to display before fields in form.
70 *
71 * @var text
72 */
73 public $help_pre;
c3fc2621 74
e501603b
TO
75 /**
76 * Description and/or help text to display after fields in form.
77 *
78 * @var text
79 */
80 public $help_post;
c3fc2621 81
e501603b
TO
82 /**
83 * Optional Javascript script function(s) included on the form with this price_set. Can be used for conditional
84 *
85 * @var string
86 */
87 public $javascript;
c3fc2621 88
e501603b
TO
89 /**
90 * What components are using this price set?
91 *
92 * @var string
93 */
94 public $extends;
c3fc2621 95
e501603b
TO
96 /**
97 * FK to Financial Type(for membership price sets only).
98 *
e6ca0a57 99 * @var int
e501603b
TO
100 */
101 public $financial_type_id;
c3fc2621 102
e501603b
TO
103 /**
104 * Is set if edited on Contribution or Event Page rather than through Manage Price Sets
105 *
e6ca0a57 106 * @var bool
e501603b
TO
107 */
108 public $is_quick_config;
c3fc2621 109
e501603b
TO
110 /**
111 * Is this a predefined system price set (i.e. it can not be deleted, edited)?
112 *
e6ca0a57 113 * @var bool
e501603b
TO
114 */
115 public $is_reserved;
c3fc2621 116
601c7a24 117 /**
118 * Minimum Amount required for this set.
119 *
f5e61d50 120 * @var float
601c7a24 121 */
122 public $min_amount;
c3fc2621 123
e501603b 124 /**
f41f0342 125 * Class constructor.
e501603b 126 */
c3fc2621 127 public function __construct() {
e501603b
TO
128 $this->__table = 'civicrm_price_set';
129 parent::__construct();
130 }
c3fc2621 131
449c4e6b
CW
132 /**
133 * Returns localized title of this entity.
7b66c3b5
AH
134 *
135 * @param bool $plural
136 * Whether to return the plural version of the title.
449c4e6b 137 */
7b66c3b5
AH
138 public static function getEntityTitle($plural = FALSE) {
139 return $plural ? ts('Price Sets') : ts('Price Set');
449c4e6b
CW
140 }
141
e501603b 142 /**
f41f0342 143 * Returns foreign keys and entity references.
e501603b
TO
144 *
145 * @return array
146 * [CRM_Core_Reference_Interface]
147 */
c3fc2621 148 public static function getReferenceColumns() {
346aaaba 149 if (!isset(Civi::$statics[__CLASS__]['links'])) {
fa45b5b9 150 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
c3fc2621
CW
151 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'domain_id', 'civicrm_domain', 'id');
152 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
346aaaba 153 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
e501603b 154 }
346aaaba 155 return Civi::$statics[__CLASS__]['links'];
e501603b 156 }
c3fc2621 157
e501603b
TO
158 /**
159 * Returns all the column names of this table
160 *
161 * @return array
162 */
c3fc2621 163 public static function &fields() {
346aaaba 164 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
c3fc2621
CW
165 Civi::$statics[__CLASS__]['fields'] = [
166 'id' => [
e501603b
TO
167 'name' => 'id',
168 'type' => CRM_Utils_Type::T_INT,
a0a2c91d 169 'title' => ts('Price Set'),
215b423e 170 'description' => ts('Price Set'),
c3fc2621 171 'required' => TRUE,
a36434b9 172 'where' => 'civicrm_price_set.id',
522a26c9 173 'table_name' => 'civicrm_price_set',
174 'entity' => 'PriceSet',
175 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 176 'localizable' => 0,
a0a2c91d
MWMC
177 'html' => [
178 'type' => 'Select',
179 ],
a9d0587b 180 'add' => '1.8',
c3fc2621
CW
181 ],
182 'domain_id' => [
e501603b
TO
183 'name' => 'domain_id',
184 'type' => CRM_Utils_Type::T_INT,
c3fc2621 185 'title' => ts('Price Set Domain'),
215b423e 186 'description' => ts('Which Domain is this price-set for'),
a36434b9 187 'where' => 'civicrm_price_set.domain_id',
522a26c9 188 'table_name' => 'civicrm_price_set',
189 'entity' => 'PriceSet',
190 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 191 'localizable' => 0,
e501603b 192 'FKClassName' => 'CRM_Core_DAO_Domain',
c3fc2621 193 'html' => [
e501603b 194 'type' => 'Text',
c3fc2621
CW
195 ],
196 'pseudoconstant' => [
e501603b
TO
197 'table' => 'civicrm_domain',
198 'keyColumn' => 'id',
199 'labelColumn' => 'name',
e6ca0a57 200 ],
a9d0587b 201 'add' => '3.1',
c3fc2621
CW
202 ],
203 'name' => [
e501603b
TO
204 'name' => 'name',
205 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 206 'title' => ts('Name'),
215b423e 207 'description' => ts('Variable name/programmatic handle for this set of price fields.'),
c3fc2621 208 'required' => TRUE,
e501603b
TO
209 'maxlength' => 255,
210 'size' => CRM_Utils_Type::HUGE,
a36434b9 211 'where' => 'civicrm_price_set.name',
522a26c9 212 'table_name' => 'civicrm_price_set',
213 'entity' => 'PriceSet',
214 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 215 'localizable' => 0,
c3fc2621 216 'html' => [
e501603b 217 'type' => 'Text',
c3fc2621 218 ],
a9d0587b 219 'add' => '1.8',
c3fc2621
CW
220 ],
221 'title' => [
e501603b
TO
222 'name' => 'title',
223 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 224 'title' => ts('Price Set Title'),
215b423e 225 'description' => ts('Displayed title for the Price Set.'),
c3fc2621 226 'required' => TRUE,
e501603b
TO
227 'maxlength' => 255,
228 'size' => CRM_Utils_Type::HUGE,
a36434b9 229 'where' => 'civicrm_price_set.title',
522a26c9 230 'table_name' => 'civicrm_price_set',
231 'entity' => 'PriceSet',
232 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 233 'localizable' => 1,
c3fc2621 234 'html' => [
e501603b 235 'type' => 'Text',
c3fc2621 236 ],
a9d0587b 237 'add' => '1.8',
c3fc2621
CW
238 ],
239 'is_active' => [
e501603b
TO
240 'name' => 'is_active',
241 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 242 'title' => ts('Price Set Is Active?'),
215b423e 243 'description' => ts('Is this price set active'),
a36434b9 244 'where' => 'civicrm_price_set.is_active',
e501603b 245 'default' => '1',
522a26c9 246 'table_name' => 'civicrm_price_set',
247 'entity' => 'PriceSet',
248 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 249 'localizable' => 0,
c3fc2621 250 'html' => [
e501603b 251 'type' => 'CheckBox',
c3fc2621 252 ],
a9d0587b 253 'add' => '1.8',
c3fc2621
CW
254 ],
255 'help_pre' => [
e501603b
TO
256 'name' => 'help_pre',
257 'type' => CRM_Utils_Type::T_TEXT,
c3fc2621 258 'title' => ts('Price Set Pre Help'),
215b423e 259 'description' => ts('Description and/or help text to display before fields in form.'),
e501603b
TO
260 'rows' => 4,
261 'cols' => 80,
a36434b9 262 'where' => 'civicrm_price_set.help_pre',
522a26c9 263 'table_name' => 'civicrm_price_set',
264 'entity' => 'PriceSet',
265 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 266 'localizable' => 1,
c3fc2621 267 'html' => [
e501603b 268 'type' => 'TextArea',
c3fc2621 269 ],
a9d0587b 270 'add' => '1.8',
c3fc2621
CW
271 ],
272 'help_post' => [
e501603b
TO
273 'name' => 'help_post',
274 'type' => CRM_Utils_Type::T_TEXT,
c3fc2621 275 'title' => ts('Price Set Post Help'),
215b423e 276 'description' => ts('Description and/or help text to display after fields in form.'),
e501603b
TO
277 'rows' => 4,
278 'cols' => 80,
a36434b9 279 'where' => 'civicrm_price_set.help_post',
522a26c9 280 'table_name' => 'civicrm_price_set',
281 'entity' => 'PriceSet',
282 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 283 'localizable' => 1,
c3fc2621 284 'html' => [
e501603b 285 'type' => 'TextArea',
c3fc2621 286 ],
a9d0587b 287 'add' => '1.8',
c3fc2621
CW
288 ],
289 'javascript' => [
e501603b
TO
290 'name' => 'javascript',
291 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 292 'title' => ts('Price Set Javascript'),
215b423e 293 'description' => ts('Optional Javascript script function(s) included on the form with this price_set. Can be used for conditional'),
e501603b
TO
294 'maxlength' => 64,
295 'size' => CRM_Utils_Type::BIG,
a36434b9 296 'where' => 'civicrm_price_set.javascript',
522a26c9 297 'table_name' => 'civicrm_price_set',
298 'entity' => 'PriceSet',
299 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 300 'localizable' => 0,
c3fc2621 301 'html' => [
e501603b 302 'type' => 'Text',
c3fc2621 303 ],
a9d0587b 304 'add' => '1.8',
c3fc2621
CW
305 ],
306 'extends' => [
e501603b
TO
307 'name' => 'extends',
308 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 309 'title' => ts('Price Set Extends'),
215b423e 310 'description' => ts('What components are using this price set?'),
c3fc2621 311 'required' => TRUE,
e501603b
TO
312 'maxlength' => 255,
313 'size' => CRM_Utils_Type::HUGE,
a36434b9 314 'where' => 'civicrm_price_set.extends',
522a26c9 315 'table_name' => 'civicrm_price_set',
316 'entity' => 'PriceSet',
317 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 318 'localizable' => 0,
c3fc2621 319 'html' => [
e501603b 320 'type' => 'Text',
c3fc2621
CW
321 ],
322 'pseudoconstant' => [
e501603b
TO
323 'table' => 'civicrm_component',
324 'keyColumn' => 'id',
325 'labelColumn' => 'name',
e6ca0a57 326 ],
a9d0587b 327 'add' => '3.1',
c3fc2621
CW
328 ],
329 'financial_type_id' => [
e501603b
TO
330 'name' => 'financial_type_id',
331 'type' => CRM_Utils_Type::T_INT,
c3fc2621 332 'title' => ts('Financial Type'),
215b423e 333 'description' => ts('FK to Financial Type(for membership price sets only).'),
a36434b9 334 'where' => 'civicrm_price_set.financial_type_id',
e501603b 335 'default' => 'NULL',
522a26c9 336 'table_name' => 'civicrm_price_set',
337 'entity' => 'PriceSet',
338 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 339 'localizable' => 0,
e501603b 340 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
c3fc2621 341 'html' => [
e501603b 342 'type' => 'Select',
c3fc2621
CW
343 ],
344 'pseudoconstant' => [
e501603b
TO
345 'table' => 'civicrm_financial_type',
346 'keyColumn' => 'id',
347 'labelColumn' => 'name',
e6ca0a57 348 ],
a9d0587b 349 'add' => '4.3',
c3fc2621
CW
350 ],
351 'is_quick_config' => [
e501603b
TO
352 'name' => 'is_quick_config',
353 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 354 'title' => ts('Is Price Set Quick Config?'),
215b423e 355 'description' => ts('Is set if edited on Contribution or Event Page rather than through Manage Price Sets'),
a36434b9 356 'where' => 'civicrm_price_set.is_quick_config',
45a83e42 357 'default' => '0',
522a26c9 358 'table_name' => 'civicrm_price_set',
359 'entity' => 'PriceSet',
360 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 361 'localizable' => 0,
c3fc2621 362 'html' => [
e501603b 363 'type' => 'CheckBox',
c3fc2621 364 ],
a9d0587b 365 'add' => '4.1',
c3fc2621
CW
366 ],
367 'is_reserved' => [
e501603b
TO
368 'name' => 'is_reserved',
369 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 370 'title' => ts('Price Set Is Reserved'),
215b423e 371 'description' => ts('Is this a predefined system price set (i.e. it can not be deleted, edited)?'),
a36434b9 372 'where' => 'civicrm_price_set.is_reserved',
45a83e42 373 'default' => '0',
522a26c9 374 'table_name' => 'civicrm_price_set',
375 'entity' => 'PriceSet',
376 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 377 'localizable' => 0,
c3fc2621 378 'html' => [
e501603b 379 'type' => 'CheckBox',
c3fc2621 380 ],
a9d0587b 381 'add' => '4.2',
c3fc2621
CW
382 ],
383 'min_amount' => [
601c7a24 384 'name' => 'min_amount',
f5e61d50 385 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 386 'title' => ts('Minimum Amount'),
215b423e 387 'description' => ts('Minimum Amount required for this set.'),
f5e61d50
PN
388 'precision' => [
389 20,
390 2,
391 ],
a36434b9 392 'where' => 'civicrm_price_set.min_amount',
f5e61d50 393 'default' => '0.0',
522a26c9 394 'table_name' => 'civicrm_price_set',
395 'entity' => 'PriceSet',
396 'bao' => 'CRM_Price_BAO_PriceSet',
6a7e5e5d 397 'localizable' => 0,
c3fc2621 398 'html' => [
601c7a24 399 'type' => 'Text',
c3fc2621 400 ],
a9d0587b 401 'add' => '4.7',
c3fc2621
CW
402 ],
403 ];
346aaaba 404 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 405 }
346aaaba 406 return Civi::$statics[__CLASS__]['fields'];
e501603b 407 }
c3fc2621 408
e501603b 409 /**
bd8e0b14 410 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
411 *
412 * @return array
bd8e0b14 413 * Array(string $name => string $uniqueName).
e501603b 414 */
c3fc2621 415 public static function &fieldKeys() {
bd8e0b14
TO
416 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
417 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 418 }
bd8e0b14 419 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 420 }
c3fc2621 421
e501603b
TO
422 /**
423 * Returns the names of this table
424 *
425 * @return string
426 */
c3fc2621 427 public static function getTableName() {
e501603b
TO
428 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
429 }
c3fc2621 430
e501603b
TO
431 /**
432 * Returns if this table needs to be logged
433 *
c3fc2621 434 * @return bool
e501603b 435 */
c3fc2621 436 public function getLog() {
e501603b
TO
437 return self::$_log;
438 }
c3fc2621 439
e501603b
TO
440 /**
441 * Returns the list of fields that can be imported
442 *
443 * @param bool $prefix
444 *
445 * @return array
446 */
c3fc2621
CW
447 public static function &import($prefix = FALSE) {
448 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'price_set', $prefix, []);
60808919 449 return $r;
e501603b 450 }
c3fc2621 451
e501603b
TO
452 /**
453 * Returns the list of fields that can be exported
454 *
455 * @param bool $prefix
456 *
457 * @return array
458 */
c3fc2621
CW
459 public static function &export($prefix = FALSE) {
460 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'price_set', $prefix, []);
60808919 461 return $r;
e501603b 462 }
c3fc2621 463
e7a6b91a
AS
464 /**
465 * Returns the list of indices
c3fc2621
CW
466 *
467 * @param bool $localize
468 *
469 * @return array
e7a6b91a
AS
470 */
471 public static function indices($localize = TRUE) {
c3fc2621
CW
472 $indices = [
473 'UI_name' => [
e7a6b91a 474 'name' => 'UI_name',
c3fc2621 475 'field' => [
e7a6b91a 476 0 => 'name',
c3fc2621
CW
477 ],
478 'localizable' => FALSE,
479 'unique' => TRUE,
e7a6b91a 480 'sig' => 'civicrm_price_set::1::name',
c3fc2621
CW
481 ],
482 ];
e7a6b91a
AS
483 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
484 }
c3fc2621 485
e501603b 486}