Merge pull request #19581 from seamuslee001/dao_regen
[civicrm-core.git] / CRM / Member / DAO / Membership.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Member/Membership.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:595cdfb5731f1391fee016c91e425124)
10 */
11
12 /**
13 * Database access object for the Membership entity.
14 */
15 class CRM_Member_DAO_Membership extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.5';
18 const COMPONENT = 'CiviMember';
19
20 /**
21 * Static instance to hold the table name.
22 *
23 * @var string
24 */
25 public static $_tableName = 'civicrm_membership';
26
27 /**
28 * Icon associated with this entity.
29 *
30 * @var string
31 */
32 public static $_icon = 'fa-id-badge';
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 * Paths for accessing this entity in the UI.
43 *
44 * @var string[]
45 */
46 protected static $_paths = [
47 'add' => 'civicrm/member/add?reset=1&action=add&context=standalone',
48 'view' => 'civicrm/contact/view/membership?reset=1&action=view&id=[id]&cid=[contact_id]',
49 'update' => 'civicrm/contact/view/membership?reset=1&action=update&id=[id]&cid=[contact_id]',
50 'delete' => 'civicrm/contact/view/membership?reset=1&action=delete&id=[id]&cid=[contact_id]',
51 ];
52
53 /**
54 * Membership ID
55 *
56 * @var int
57 */
58 public $id;
59
60 /**
61 * FK to Contact ID
62 *
63 * @var int
64 */
65 public $contact_id;
66
67 /**
68 * FK to Membership Type
69 *
70 * @var int
71 */
72 public $membership_type_id;
73
74 /**
75 * Beginning of initial membership period (member since...).
76 *
77 * @var date
78 */
79 public $join_date;
80
81 /**
82 * Beginning of current uninterrupted membership period.
83 *
84 * @var date
85 */
86 public $start_date;
87
88 /**
89 * Current membership period expire date.
90 *
91 * @var date
92 */
93 public $end_date;
94
95 /**
96 * @var string
97 */
98 public $source;
99
100 /**
101 * FK to Membership Status
102 *
103 * @var int
104 */
105 public $status_id;
106
107 /**
108 * Admin users may set a manual status which overrides the calculated status. When this flag is true, automated status update scripts should NOT modify status for the record.
109 *
110 * @var bool
111 */
112 public $is_override;
113
114 /**
115 * Then end date of membership status override if 'Override until selected date' override type is selected.
116 *
117 * @var date
118 */
119 public $status_override_end_date;
120
121 /**
122 * Optional FK to Parent Membership.
123 *
124 * @var int
125 */
126 public $owner_membership_id;
127
128 /**
129 * Maximum number of related memberships (membership_type override).
130 *
131 * @var int
132 */
133 public $max_related;
134
135 /**
136 * @var bool
137 */
138 public $is_test;
139
140 /**
141 * @var bool
142 */
143 public $is_pay_later;
144
145 /**
146 * Conditional foreign key to civicrm_contribution_recur id. Each membership in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.
147 *
148 * @var int
149 */
150 public $contribution_recur_id;
151
152 /**
153 * The campaign for which this membership is attached.
154 *
155 * @var int
156 */
157 public $campaign_id;
158
159 /**
160 * Class constructor.
161 */
162 public function __construct() {
163 $this->__table = 'civicrm_membership';
164 parent::__construct();
165 }
166
167 /**
168 * Returns localized title of this entity.
169 *
170 * @param bool $plural
171 * Whether to return the plural version of the title.
172 */
173 public static function getEntityTitle($plural = FALSE) {
174 return $plural ? ts('Memberships') : ts('Membership');
175 }
176
177 /**
178 * Returns foreign keys and entity references.
179 *
180 * @return array
181 * [CRM_Core_Reference_Interface]
182 */
183 public static function getReferenceColumns() {
184 if (!isset(Civi::$statics[__CLASS__]['links'])) {
185 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
186 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
187 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'membership_type_id', 'civicrm_membership_type', 'id');
188 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'status_id', 'civicrm_membership_status', 'id');
189 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'owner_membership_id', 'civicrm_membership', 'id');
190 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
191 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
192 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
193 }
194 return Civi::$statics[__CLASS__]['links'];
195 }
196
197 /**
198 * Returns all the column names of this table
199 *
200 * @return array
201 */
202 public static function &fields() {
203 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
204 Civi::$statics[__CLASS__]['fields'] = [
205 'membership_id' => [
206 'name' => 'id',
207 'type' => CRM_Utils_Type::T_INT,
208 'title' => ts('Membership ID'),
209 'description' => ts('Membership ID'),
210 'required' => TRUE,
211 'import' => TRUE,
212 'where' => 'civicrm_membership.id',
213 'headerPattern' => '/^(m(embership\s)?id)$/i',
214 'export' => TRUE,
215 'table_name' => 'civicrm_membership',
216 'entity' => 'Membership',
217 'bao' => 'CRM_Member_BAO_Membership',
218 'localizable' => 0,
219 'html' => [
220 'type' => 'Number',
221 ],
222 'add' => '1.5',
223 ],
224 'membership_contact_id' => [
225 'name' => 'contact_id',
226 'type' => CRM_Utils_Type::T_INT,
227 'title' => ts('Contact ID'),
228 'description' => ts('FK to Contact ID'),
229 'required' => TRUE,
230 'import' => TRUE,
231 'where' => 'civicrm_membership.contact_id',
232 'headerPattern' => '/contact(.?id)?/i',
233 'dataPattern' => '/^\d+$/',
234 'export' => TRUE,
235 'table_name' => 'civicrm_membership',
236 'entity' => 'Membership',
237 'bao' => 'CRM_Member_BAO_Membership',
238 'localizable' => 0,
239 'FKClassName' => 'CRM_Contact_DAO_Contact',
240 'html' => [
241 'type' => 'EntityRef',
242 'label' => ts("Contact"),
243 ],
244 'add' => '1.5',
245 ],
246 'membership_type_id' => [
247 'name' => 'membership_type_id',
248 'type' => CRM_Utils_Type::T_INT,
249 'title' => ts('Membership Type ID'),
250 'description' => ts('FK to Membership Type'),
251 'required' => TRUE,
252 'import' => TRUE,
253 'where' => 'civicrm_membership.membership_type_id',
254 'headerPattern' => '/^(m(embership\s)?type)$/i',
255 'export' => FALSE,
256 'table_name' => 'civicrm_membership',
257 'entity' => 'Membership',
258 'bao' => 'CRM_Member_BAO_Membership',
259 'localizable' => 0,
260 'FKClassName' => 'CRM_Member_DAO_MembershipType',
261 'html' => [
262 'type' => 'Select',
263 'label' => ts("Membership Type"),
264 ],
265 'pseudoconstant' => [
266 'table' => 'civicrm_membership_type',
267 'keyColumn' => 'id',
268 'labelColumn' => 'name',
269 ],
270 'add' => '1.5',
271 ],
272 'membership_join_date' => [
273 'name' => 'join_date',
274 'type' => CRM_Utils_Type::T_DATE,
275 'title' => ts('Member Since'),
276 'description' => ts('Beginning of initial membership period (member since...).'),
277 'import' => TRUE,
278 'where' => 'civicrm_membership.join_date',
279 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
280 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
281 'export' => TRUE,
282 'table_name' => 'civicrm_membership',
283 'entity' => 'Membership',
284 'bao' => 'CRM_Member_BAO_Membership',
285 'localizable' => 0,
286 'html' => [
287 'type' => 'Select Date',
288 'formatType' => 'activityDate',
289 ],
290 'add' => '1.5',
291 ],
292 'membership_start_date' => [
293 'name' => 'start_date',
294 'type' => CRM_Utils_Type::T_DATE,
295 'title' => ts('Membership Start Date'),
296 'description' => ts('Beginning of current uninterrupted membership period.'),
297 'import' => TRUE,
298 'where' => 'civicrm_membership.start_date',
299 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
300 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
301 'export' => TRUE,
302 'table_name' => 'civicrm_membership',
303 'entity' => 'Membership',
304 'bao' => 'CRM_Member_BAO_Membership',
305 'localizable' => 0,
306 'html' => [
307 'type' => 'Select Date',
308 'formatType' => 'activityDate',
309 ],
310 'add' => '1.5',
311 ],
312 'membership_end_date' => [
313 'name' => 'end_date',
314 'type' => CRM_Utils_Type::T_DATE,
315 'title' => ts('Membership Expiration Date'),
316 'description' => ts('Current membership period expire date.'),
317 'import' => TRUE,
318 'where' => 'civicrm_membership.end_date',
319 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
320 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
321 'export' => TRUE,
322 'table_name' => 'civicrm_membership',
323 'entity' => 'Membership',
324 'bao' => 'CRM_Member_BAO_Membership',
325 'localizable' => 0,
326 'html' => [
327 'type' => 'Select Date',
328 'formatType' => 'activityDate',
329 ],
330 'add' => '1.5',
331 ],
332 'membership_source' => [
333 'name' => 'source',
334 'type' => CRM_Utils_Type::T_STRING,
335 'title' => ts('Source'),
336 'maxlength' => 128,
337 'size' => CRM_Utils_Type::HUGE,
338 'import' => TRUE,
339 'where' => 'civicrm_membership.source',
340 'headerPattern' => '/^(member(ship?))?source$/i',
341 'export' => TRUE,
342 'table_name' => 'civicrm_membership',
343 'entity' => 'Membership',
344 'bao' => 'CRM_Member_BAO_Membership',
345 'localizable' => 0,
346 'html' => [
347 'type' => 'Text',
348 ],
349 'add' => '1.5',
350 ],
351 'status_id' => [
352 'name' => 'status_id',
353 'type' => CRM_Utils_Type::T_INT,
354 'title' => ts('Status ID'),
355 'description' => ts('FK to Membership Status'),
356 'required' => TRUE,
357 'import' => TRUE,
358 'where' => 'civicrm_membership.status_id',
359 'headerPattern' => '/(member(ship|).)?(status)$/i',
360 'export' => FALSE,
361 'table_name' => 'civicrm_membership',
362 'entity' => 'Membership',
363 'bao' => 'CRM_Member_BAO_Membership',
364 'localizable' => 0,
365 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
366 'html' => [
367 'type' => 'Select',
368 'label' => ts("Status"),
369 ],
370 'pseudoconstant' => [
371 'table' => 'civicrm_membership_status',
372 'keyColumn' => 'id',
373 'labelColumn' => 'label',
374 ],
375 'add' => '1.5',
376 ],
377 'member_is_override' => [
378 'name' => 'is_override',
379 'type' => CRM_Utils_Type::T_BOOLEAN,
380 'title' => ts('Status Override'),
381 'description' => ts('Admin users may set a manual status which overrides the calculated status. When this flag is true, automated status update scripts should NOT modify status for the record.'),
382 'import' => TRUE,
383 'where' => 'civicrm_membership.is_override',
384 'headerPattern' => '/override$/i',
385 'export' => TRUE,
386 'table_name' => 'civicrm_membership',
387 'entity' => 'Membership',
388 'bao' => 'CRM_Member_BAO_Membership',
389 'localizable' => 0,
390 'html' => [
391 'type' => 'CheckBox',
392 ],
393 'add' => '1.5',
394 ],
395 'status_override_end_date' => [
396 'name' => 'status_override_end_date',
397 'type' => CRM_Utils_Type::T_DATE,
398 'title' => ts('Status Override End Date'),
399 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
400 'import' => TRUE,
401 'where' => 'civicrm_membership.status_override_end_date',
402 'export' => TRUE,
403 'default' => 'NULL',
404 'table_name' => 'civicrm_membership',
405 'entity' => 'Membership',
406 'bao' => 'CRM_Member_BAO_Membership',
407 'localizable' => 0,
408 'html' => [
409 'type' => 'Select Date',
410 'formatType' => 'activityDate',
411 ],
412 'add' => '4.7',
413 ],
414 'owner_membership_id' => [
415 'name' => 'owner_membership_id',
416 'type' => CRM_Utils_Type::T_INT,
417 'title' => ts('Primary Member ID'),
418 'description' => ts('Optional FK to Parent Membership.'),
419 'where' => 'civicrm_membership.owner_membership_id',
420 'export' => TRUE,
421 'table_name' => 'civicrm_membership',
422 'entity' => 'Membership',
423 'bao' => 'CRM_Member_BAO_Membership',
424 'localizable' => 0,
425 'FKClassName' => 'CRM_Member_DAO_Membership',
426 'html' => [
427 'label' => ts("Primary Member"),
428 ],
429 'add' => '1.7',
430 ],
431 'max_related' => [
432 'name' => 'max_related',
433 'type' => CRM_Utils_Type::T_INT,
434 'title' => ts('Max Related'),
435 'description' => ts('Maximum number of related memberships (membership_type override).'),
436 'where' => 'civicrm_membership.max_related',
437 'export' => TRUE,
438 'table_name' => 'civicrm_membership',
439 'entity' => 'Membership',
440 'bao' => 'CRM_Member_BAO_Membership',
441 'localizable' => 0,
442 'html' => [
443 'type' => 'Text',
444 'label' => ts("Maximum number of related memberships"),
445 ],
446 'add' => '4.3',
447 ],
448 'member_is_test' => [
449 'name' => 'is_test',
450 'type' => CRM_Utils_Type::T_BOOLEAN,
451 'title' => ts('Test'),
452 'import' => TRUE,
453 'where' => 'civicrm_membership.is_test',
454 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
455 'export' => TRUE,
456 'default' => '0',
457 'table_name' => 'civicrm_membership',
458 'entity' => 'Membership',
459 'bao' => 'CRM_Member_BAO_Membership',
460 'localizable' => 0,
461 'html' => [
462 'type' => 'CheckBox',
463 ],
464 'add' => NULL,
465 ],
466 'member_is_pay_later' => [
467 'name' => 'is_pay_later',
468 'type' => CRM_Utils_Type::T_BOOLEAN,
469 'title' => ts('Is Pay Later'),
470 'import' => TRUE,
471 'where' => 'civicrm_membership.is_pay_later',
472 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
473 'export' => TRUE,
474 'default' => '0',
475 'table_name' => 'civicrm_membership',
476 'entity' => 'Membership',
477 'bao' => 'CRM_Member_BAO_Membership',
478 'localizable' => 0,
479 'html' => [
480 'type' => 'CheckBox',
481 ],
482 'add' => '2.1',
483 ],
484 'membership_recur_id' => [
485 'name' => 'contribution_recur_id',
486 'type' => CRM_Utils_Type::T_INT,
487 'title' => ts('Recurring Contribution ID'),
488 'description' => ts('Conditional foreign key to civicrm_contribution_recur id. Each membership in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.'),
489 'where' => 'civicrm_membership.contribution_recur_id',
490 'export' => TRUE,
491 'table_name' => 'civicrm_membership',
492 'entity' => 'Membership',
493 'bao' => 'CRM_Member_BAO_Membership',
494 'localizable' => 0,
495 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
496 'html' => [
497 'label' => ts("Recurring Contribution"),
498 ],
499 'add' => '3.3',
500 ],
501 'member_campaign_id' => [
502 'name' => 'campaign_id',
503 'type' => CRM_Utils_Type::T_INT,
504 'title' => ts('Campaign ID'),
505 'description' => ts('The campaign for which this membership is attached.'),
506 'import' => TRUE,
507 'where' => 'civicrm_membership.campaign_id',
508 'export' => TRUE,
509 'table_name' => 'civicrm_membership',
510 'entity' => 'Membership',
511 'bao' => 'CRM_Member_BAO_Membership',
512 'localizable' => 0,
513 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
514 'html' => [
515 'type' => 'Select',
516 'label' => ts("Campaign"),
517 ],
518 'add' => '3.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 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__, 'membership', $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__, 'membership', $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 'index_owner_membership_id' => [
591 'name' => 'index_owner_membership_id',
592 'field' => [
593 0 => 'owner_membership_id',
594 ],
595 'localizable' => FALSE,
596 'sig' => 'civicrm_membership::0::owner_membership_id',
597 ],
598 ];
599 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
600 }
601
602 }