Merge pull request #22460 from civicrm/5.46
[civicrm-core.git] / CRM / Core / DAO / Discount.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Core/Discount.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:681876b76553a2f0db5a0c0f9d18eda0)
10 */
11
12 /**
13 * Database access object for the Discount entity.
14 */
15 class CRM_Core_DAO_Discount extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '2.1';
18
19 /**
20 * Static instance to hold the table name.
21 *
22 * @var string
23 */
24 public static $_tableName = 'civicrm_discount';
25
26 /**
27 * Should CiviCRM log any modifications to this table in the civicrm_log table.
28 *
29 * @var bool
30 */
31 public static $_log = TRUE;
32
33 /**
34 * primary key
35 *
36 * @var int
37 */
38 public $id;
39
40 /**
41 * physical tablename for entity being joined to discount, e.g. civicrm_event
42 *
43 * @var string
44 */
45 public $entity_table;
46
47 /**
48 * FK to entity table specified in entity_table column.
49 *
50 * @var int
51 */
52 public $entity_id;
53
54 /**
55 * FK to civicrm_price_set
56 *
57 * @var int
58 */
59 public $price_set_id;
60
61 /**
62 * Date when discount starts.
63 *
64 * @var date
65 */
66 public $start_date;
67
68 /**
69 * Date when discount ends.
70 *
71 * @var date
72 */
73 public $end_date;
74
75 /**
76 * Class constructor.
77 */
78 public function __construct() {
79 $this->__table = 'civicrm_discount';
80 parent::__construct();
81 }
82
83 /**
84 * Returns localized title of this entity.
85 *
86 * @param bool $plural
87 * Whether to return the plural version of the title.
88 */
89 public static function getEntityTitle($plural = FALSE) {
90 return $plural ? ts('Discounts') : ts('Discount');
91 }
92
93 /**
94 * Returns foreign keys and entity references.
95 *
96 * @return array
97 * [CRM_Core_Reference_Interface]
98 */
99 public static function getReferenceColumns() {
100 if (!isset(Civi::$statics[__CLASS__]['links'])) {
101 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
102 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'price_set_id', 'civicrm_price_set', 'id');
103 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), 'entity_id', NULL, 'id', 'entity_table');
104 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
105 }
106 return Civi::$statics[__CLASS__]['links'];
107 }
108
109 /**
110 * Returns all the column names of this table
111 *
112 * @return array
113 */
114 public static function &fields() {
115 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
116 Civi::$statics[__CLASS__]['fields'] = [
117 'id' => [
118 'name' => 'id',
119 'type' => CRM_Utils_Type::T_INT,
120 'title' => ts('Discount ID'),
121 'description' => ts('primary key'),
122 'required' => TRUE,
123 'where' => 'civicrm_discount.id',
124 'table_name' => 'civicrm_discount',
125 'entity' => 'Discount',
126 'bao' => 'CRM_Core_BAO_Discount',
127 'localizable' => 0,
128 'html' => [
129 'type' => 'Number',
130 ],
131 'readonly' => TRUE,
132 'add' => '2.1',
133 ],
134 'entity_table' => [
135 'name' => 'entity_table',
136 'type' => CRM_Utils_Type::T_STRING,
137 'title' => ts('Entity Table'),
138 'description' => ts('physical tablename for entity being joined to discount, e.g. civicrm_event'),
139 'maxlength' => 64,
140 'size' => CRM_Utils_Type::BIG,
141 'where' => 'civicrm_discount.entity_table',
142 'table_name' => 'civicrm_discount',
143 'entity' => 'Discount',
144 'bao' => 'CRM_Core_BAO_Discount',
145 'localizable' => 0,
146 'add' => '2.1',
147 ],
148 'entity_id' => [
149 'name' => 'entity_id',
150 'type' => CRM_Utils_Type::T_INT,
151 'title' => ts('Entity ID'),
152 'description' => ts('FK to entity table specified in entity_table column.'),
153 'required' => TRUE,
154 'where' => 'civicrm_discount.entity_id',
155 'table_name' => 'civicrm_discount',
156 'entity' => 'Discount',
157 'bao' => 'CRM_Core_BAO_Discount',
158 'localizable' => 0,
159 'add' => '2.1',
160 ],
161 'participant_discount_name' => [
162 'name' => 'price_set_id',
163 'type' => CRM_Utils_Type::T_INT,
164 'title' => ts('Price Set ID'),
165 'description' => ts('FK to civicrm_price_set'),
166 'required' => TRUE,
167 'where' => 'civicrm_discount.price_set_id',
168 'export' => TRUE,
169 'table_name' => 'civicrm_discount',
170 'entity' => 'Discount',
171 'bao' => 'CRM_Core_BAO_Discount',
172 'localizable' => 0,
173 'FKClassName' => 'CRM_Price_DAO_PriceSet',
174 'html' => [
175 'label' => ts("Price Set"),
176 ],
177 'pseudoconstant' => [
178 'table' => 'civicrm_price_set',
179 'keyColumn' => 'id',
180 'labelColumn' => 'title',
181 ],
182 'add' => '4.3',
183 ],
184 'start_date' => [
185 'name' => 'start_date',
186 'type' => CRM_Utils_Type::T_DATE,
187 'title' => ts('Discount Start Date'),
188 'description' => ts('Date when discount starts.'),
189 'where' => 'civicrm_discount.start_date',
190 'table_name' => 'civicrm_discount',
191 'entity' => 'Discount',
192 'bao' => 'CRM_Core_BAO_Discount',
193 'localizable' => 0,
194 'add' => '2.1',
195 ],
196 'end_date' => [
197 'name' => 'end_date',
198 'type' => CRM_Utils_Type::T_DATE,
199 'title' => ts('Discount End Date'),
200 'description' => ts('Date when discount ends.'),
201 'where' => 'civicrm_discount.end_date',
202 'table_name' => 'civicrm_discount',
203 'entity' => 'Discount',
204 'bao' => 'CRM_Core_BAO_Discount',
205 'localizable' => 0,
206 'add' => '2.1',
207 ],
208 ];
209 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
210 }
211 return Civi::$statics[__CLASS__]['fields'];
212 }
213
214 /**
215 * Return a mapping from field-name to the corresponding key (as used in fields()).
216 *
217 * @return array
218 * Array(string $name => string $uniqueName).
219 */
220 public static function &fieldKeys() {
221 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
222 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
223 }
224 return Civi::$statics[__CLASS__]['fieldKeys'];
225 }
226
227 /**
228 * Returns the names of this table
229 *
230 * @return string
231 */
232 public static function getTableName() {
233 return self::$_tableName;
234 }
235
236 /**
237 * Returns if this table needs to be logged
238 *
239 * @return bool
240 */
241 public function getLog() {
242 return self::$_log;
243 }
244
245 /**
246 * Returns the list of fields that can be imported
247 *
248 * @param bool $prefix
249 *
250 * @return array
251 */
252 public static function &import($prefix = FALSE) {
253 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'discount', $prefix, []);
254 return $r;
255 }
256
257 /**
258 * Returns the list of fields that can be exported
259 *
260 * @param bool $prefix
261 *
262 * @return array
263 */
264 public static function &export($prefix = FALSE) {
265 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'discount', $prefix, []);
266 return $r;
267 }
268
269 /**
270 * Returns the list of indices
271 *
272 * @param bool $localize
273 *
274 * @return array
275 */
276 public static function indices($localize = TRUE) {
277 $indices = [
278 'index_entity' => [
279 'name' => 'index_entity',
280 'field' => [
281 0 => 'entity_table',
282 1 => 'entity_id',
283 ],
284 'localizable' => FALSE,
285 'sig' => 'civicrm_discount::0::entity_table::entity_id',
286 ],
287 'index_entity_option_id' => [
288 'name' => 'index_entity_option_id',
289 'field' => [
290 0 => 'entity_table',
291 1 => 'entity_id',
292 2 => 'price_set_id',
293 ],
294 'localizable' => FALSE,
295 'sig' => 'civicrm_discount::0::entity_table::entity_id::price_set_id',
296 ],
297 ];
298 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
299 }
300
301 }