Merge pull request #23947 from totten/master-php81-global
[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:1668d4d8a9f2e1686bf9f5b6ea1c55dc)
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|string|null
57 * (SQL type: int unsigned)
58 * Note that values will be retrieved from the database as a string.
59 */
60 public $id;
61
62 /**
63 * FK to Contact ID
64 *
65 * @var int|string
66 * (SQL type: int unsigned)
67 * Note that values will be retrieved from the database as a string.
68 */
69 public $contact_id;
70
71 /**
72 * FK to Membership Type
73 *
74 * @var int|string
75 * (SQL type: int unsigned)
76 * Note that values will be retrieved from the database as a string.
77 */
78 public $membership_type_id;
79
80 /**
81 * Beginning of initial membership period (member since...).
82 *
83 * @var string|null
84 * (SQL type: date)
85 * Note that values will be retrieved from the database as a string.
86 */
87 public $join_date;
88
89 /**
90 * Beginning of current uninterrupted membership period.
91 *
92 * @var string|null
93 * (SQL type: date)
94 * Note that values will be retrieved from the database as a string.
95 */
96 public $start_date;
97
98 /**
99 * Current membership period expire date.
100 *
101 * @var string|null
102 * (SQL type: date)
103 * Note that values will be retrieved from the database as a string.
104 */
105 public $end_date;
106
107 /**
108 * @var string|null
109 * (SQL type: varchar(128))
110 * Note that values will be retrieved from the database as a string.
111 */
112 public $source;
113
114 /**
115 * FK to Membership Status
116 *
117 * @var int|string
118 * (SQL type: int unsigned)
119 * Note that values will be retrieved from the database as a string.
120 */
121 public $status_id;
122
123 /**
124 * 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.
125 *
126 * @var bool|string
127 * (SQL type: tinyint)
128 * Note that values will be retrieved from the database as a string.
129 */
130 public $is_override;
131
132 /**
133 * Then end date of membership status override if 'Override until selected date' override type is selected.
134 *
135 * @var string|null
136 * (SQL type: date)
137 * Note that values will be retrieved from the database as a string.
138 */
139 public $status_override_end_date;
140
141 /**
142 * Optional FK to Parent Membership.
143 *
144 * @var int|string|null
145 * (SQL type: int unsigned)
146 * Note that values will be retrieved from the database as a string.
147 */
148 public $owner_membership_id;
149
150 /**
151 * Maximum number of related memberships (membership_type override).
152 *
153 * @var int|string|null
154 * (SQL type: int)
155 * Note that values will be retrieved from the database as a string.
156 */
157 public $max_related;
158
159 /**
160 * @var bool|string
161 * (SQL type: tinyint)
162 * Note that values will be retrieved from the database as a string.
163 */
164 public $is_test;
165
166 /**
167 * @var bool|string
168 * (SQL type: tinyint)
169 * Note that values will be retrieved from the database as a string.
170 */
171 public $is_pay_later;
172
173 /**
174 * 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.
175 *
176 * @var int|string|null
177 * (SQL type: int unsigned)
178 * Note that values will be retrieved from the database as a string.
179 */
180 public $contribution_recur_id;
181
182 /**
183 * The campaign for which this membership is attached.
184 *
185 * @var int|string|null
186 * (SQL type: int unsigned)
187 * Note that values will be retrieved from the database as a string.
188 */
189 public $campaign_id;
190
191 /**
192 * Class constructor.
193 */
194 public function __construct() {
195 $this->__table = 'civicrm_membership';
196 parent::__construct();
197 }
198
199 /**
200 * Returns localized title of this entity.
201 *
202 * @param bool $plural
203 * Whether to return the plural version of the title.
204 */
205 public static function getEntityTitle($plural = FALSE) {
206 return $plural ? ts('Memberships') : ts('Membership');
207 }
208
209 /**
210 * Returns user-friendly description of this entity.
211 *
212 * @return string
213 */
214 public static function getEntityDescription() {
215 return ts('Records of contacts belonging to an organization\'s membership program.');
216 }
217
218 /**
219 * Returns foreign keys and entity references.
220 *
221 * @return array
222 * [CRM_Core_Reference_Interface]
223 */
224 public static function getReferenceColumns() {
225 if (!isset(Civi::$statics[__CLASS__]['links'])) {
226 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
227 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
228 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'membership_type_id', 'civicrm_membership_type', 'id');
229 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'status_id', 'civicrm_membership_status', 'id');
230 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'owner_membership_id', 'civicrm_membership', 'id');
231 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
232 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
233 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
234 }
235 return Civi::$statics[__CLASS__]['links'];
236 }
237
238 /**
239 * Returns all the column names of this table
240 *
241 * @return array
242 */
243 public static function &fields() {
244 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
245 Civi::$statics[__CLASS__]['fields'] = [
246 'membership_id' => [
247 'name' => 'id',
248 'type' => CRM_Utils_Type::T_INT,
249 'title' => ts('Membership ID'),
250 'description' => ts('Membership ID'),
251 'required' => TRUE,
252 'import' => TRUE,
253 'where' => 'civicrm_membership.id',
254 'headerPattern' => '/^(m(embership\s)?id)$/i',
255 'export' => TRUE,
256 'table_name' => 'civicrm_membership',
257 'entity' => 'Membership',
258 'bao' => 'CRM_Member_BAO_Membership',
259 'localizable' => 0,
260 'html' => [
261 'type' => 'Number',
262 ],
263 'readonly' => TRUE,
264 'add' => '1.5',
265 ],
266 'membership_contact_id' => [
267 'name' => 'contact_id',
268 'type' => CRM_Utils_Type::T_INT,
269 'title' => ts('Contact ID'),
270 'description' => ts('FK to Contact ID'),
271 'required' => TRUE,
272 'import' => TRUE,
273 'where' => 'civicrm_membership.contact_id',
274 'headerPattern' => '/contact(.?id)?/i',
275 'dataPattern' => '/^\d+$/',
276 'export' => TRUE,
277 'table_name' => 'civicrm_membership',
278 'entity' => 'Membership',
279 'bao' => 'CRM_Member_BAO_Membership',
280 'localizable' => 0,
281 'FKClassName' => 'CRM_Contact_DAO_Contact',
282 'html' => [
283 'type' => 'EntityRef',
284 'label' => ts("Contact"),
285 ],
286 'add' => '1.5',
287 ],
288 'membership_type_id' => [
289 'name' => 'membership_type_id',
290 'type' => CRM_Utils_Type::T_INT,
291 'title' => ts('Membership Type ID'),
292 'description' => ts('FK to Membership Type'),
293 'required' => TRUE,
294 'import' => TRUE,
295 'where' => 'civicrm_membership.membership_type_id',
296 'headerPattern' => '/^(m(embership\s)?type)$/i',
297 'export' => FALSE,
298 'table_name' => 'civicrm_membership',
299 'entity' => 'Membership',
300 'bao' => 'CRM_Member_BAO_Membership',
301 'localizable' => 0,
302 'FKClassName' => 'CRM_Member_DAO_MembershipType',
303 'html' => [
304 'type' => 'Select',
305 'label' => ts("Membership Type"),
306 ],
307 'pseudoconstant' => [
308 'table' => 'civicrm_membership_type',
309 'keyColumn' => 'id',
310 'labelColumn' => 'name',
311 ],
312 'add' => '1.5',
313 ],
314 'membership_join_date' => [
315 'name' => 'join_date',
316 'type' => CRM_Utils_Type::T_DATE,
317 'title' => ts('Member Since'),
318 'description' => ts('Beginning of initial membership period (member since...).'),
319 'import' => TRUE,
320 'where' => 'civicrm_membership.join_date',
321 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
322 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
323 'export' => TRUE,
324 'table_name' => 'civicrm_membership',
325 'entity' => 'Membership',
326 'bao' => 'CRM_Member_BAO_Membership',
327 'localizable' => 0,
328 'html' => [
329 'type' => 'Select Date',
330 'formatType' => 'activityDate',
331 ],
332 'add' => '1.5',
333 ],
334 'membership_start_date' => [
335 'name' => 'start_date',
336 'type' => CRM_Utils_Type::T_DATE,
337 'title' => ts('Membership Start Date'),
338 'description' => ts('Beginning of current uninterrupted membership period.'),
339 'import' => TRUE,
340 'where' => 'civicrm_membership.start_date',
341 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
342 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
343 'export' => TRUE,
344 'table_name' => 'civicrm_membership',
345 'entity' => 'Membership',
346 'bao' => 'CRM_Member_BAO_Membership',
347 'localizable' => 0,
348 'html' => [
349 'type' => 'Select Date',
350 'formatType' => 'activityDate',
351 ],
352 'add' => '1.5',
353 ],
354 'membership_end_date' => [
355 'name' => 'end_date',
356 'type' => CRM_Utils_Type::T_DATE,
357 'title' => ts('Membership Expiration Date'),
358 'description' => ts('Current membership period expire date.'),
359 'import' => TRUE,
360 'where' => 'civicrm_membership.end_date',
361 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
362 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
363 'export' => TRUE,
364 'table_name' => 'civicrm_membership',
365 'entity' => 'Membership',
366 'bao' => 'CRM_Member_BAO_Membership',
367 'localizable' => 0,
368 'html' => [
369 'type' => 'Select Date',
370 'formatType' => 'activityDate',
371 ],
372 'add' => '1.5',
373 ],
374 'membership_source' => [
375 'name' => 'source',
376 'type' => CRM_Utils_Type::T_STRING,
377 'title' => ts('Source'),
378 'maxlength' => 128,
379 'size' => CRM_Utils_Type::HUGE,
380 'import' => TRUE,
381 'where' => 'civicrm_membership.source',
382 'headerPattern' => '/^(member(ship?))?source$/i',
383 'export' => TRUE,
384 'table_name' => 'civicrm_membership',
385 'entity' => 'Membership',
386 'bao' => 'CRM_Member_BAO_Membership',
387 'localizable' => 0,
388 'html' => [
389 'type' => 'Text',
390 ],
391 'add' => '1.5',
392 ],
393 'status_id' => [
394 'name' => 'status_id',
395 'type' => CRM_Utils_Type::T_INT,
396 'title' => ts('Status ID'),
397 'description' => ts('FK to Membership Status'),
398 'required' => TRUE,
399 'import' => TRUE,
400 'where' => 'civicrm_membership.status_id',
401 'headerPattern' => '/(member(ship|).)?(status)$/i',
402 'export' => FALSE,
403 'table_name' => 'civicrm_membership',
404 'entity' => 'Membership',
405 'bao' => 'CRM_Member_BAO_Membership',
406 'localizable' => 0,
407 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
408 'html' => [
409 'type' => 'Select',
410 'label' => ts("Status"),
411 ],
412 'pseudoconstant' => [
413 'table' => 'civicrm_membership_status',
414 'keyColumn' => 'id',
415 'labelColumn' => 'label',
416 ],
417 'add' => '1.5',
418 ],
419 'member_is_override' => [
420 'name' => 'is_override',
421 'type' => CRM_Utils_Type::T_BOOLEAN,
422 'title' => ts('Status Override'),
423 '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.'),
424 'required' => TRUE,
425 'import' => TRUE,
426 'where' => 'civicrm_membership.is_override',
427 'headerPattern' => '/override$/i',
428 'export' => TRUE,
429 'default' => '0',
430 'table_name' => 'civicrm_membership',
431 'entity' => 'Membership',
432 'bao' => 'CRM_Member_BAO_Membership',
433 'localizable' => 0,
434 'html' => [
435 'type' => 'CheckBox',
436 ],
437 'add' => '1.5',
438 ],
439 'status_override_end_date' => [
440 'name' => 'status_override_end_date',
441 'type' => CRM_Utils_Type::T_DATE,
442 'title' => ts('Status Override End Date'),
443 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
444 'import' => TRUE,
445 'where' => 'civicrm_membership.status_override_end_date',
446 'export' => TRUE,
447 'default' => NULL,
448 'table_name' => 'civicrm_membership',
449 'entity' => 'Membership',
450 'bao' => 'CRM_Member_BAO_Membership',
451 'localizable' => 0,
452 'html' => [
453 'type' => 'Select Date',
454 'formatType' => 'activityDate',
455 ],
456 'add' => '4.7',
457 ],
458 'owner_membership_id' => [
459 'name' => 'owner_membership_id',
460 'type' => CRM_Utils_Type::T_INT,
461 'title' => ts('Primary Member ID'),
462 'description' => ts('Optional FK to Parent Membership.'),
463 'where' => 'civicrm_membership.owner_membership_id',
464 'export' => TRUE,
465 'table_name' => 'civicrm_membership',
466 'entity' => 'Membership',
467 'bao' => 'CRM_Member_BAO_Membership',
468 'localizable' => 0,
469 'FKClassName' => 'CRM_Member_DAO_Membership',
470 'html' => [
471 'label' => ts("Primary Member"),
472 ],
473 'add' => '1.7',
474 ],
475 'max_related' => [
476 'name' => 'max_related',
477 'type' => CRM_Utils_Type::T_INT,
478 'title' => ts('Max Related'),
479 'description' => ts('Maximum number of related memberships (membership_type override).'),
480 'where' => 'civicrm_membership.max_related',
481 'export' => TRUE,
482 'table_name' => 'civicrm_membership',
483 'entity' => 'Membership',
484 'bao' => 'CRM_Member_BAO_Membership',
485 'localizable' => 0,
486 'html' => [
487 'type' => 'Text',
488 'label' => ts("Maximum number of related memberships"),
489 ],
490 'add' => '4.3',
491 ],
492 'member_is_test' => [
493 'name' => 'is_test',
494 'type' => CRM_Utils_Type::T_BOOLEAN,
495 'title' => ts('Test'),
496 'required' => TRUE,
497 'import' => TRUE,
498 'where' => 'civicrm_membership.is_test',
499 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
500 'export' => TRUE,
501 'default' => '0',
502 'table_name' => 'civicrm_membership',
503 'entity' => 'Membership',
504 'bao' => 'CRM_Member_BAO_Membership',
505 'localizable' => 0,
506 'html' => [
507 'type' => 'CheckBox',
508 ],
509 'add' => NULL,
510 ],
511 'member_is_pay_later' => [
512 'name' => 'is_pay_later',
513 'type' => CRM_Utils_Type::T_BOOLEAN,
514 'title' => ts('Is Pay Later'),
515 'required' => TRUE,
516 'import' => TRUE,
517 'where' => 'civicrm_membership.is_pay_later',
518 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
519 'export' => TRUE,
520 'default' => '0',
521 'table_name' => 'civicrm_membership',
522 'entity' => 'Membership',
523 'bao' => 'CRM_Member_BAO_Membership',
524 'localizable' => 0,
525 'html' => [
526 'type' => 'CheckBox',
527 ],
528 'add' => '2.1',
529 ],
530 'membership_recur_id' => [
531 'name' => 'contribution_recur_id',
532 'type' => CRM_Utils_Type::T_INT,
533 'title' => ts('Recurring Contribution ID'),
534 '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.'),
535 'where' => 'civicrm_membership.contribution_recur_id',
536 'export' => TRUE,
537 'table_name' => 'civicrm_membership',
538 'entity' => 'Membership',
539 'bao' => 'CRM_Member_BAO_Membership',
540 'localizable' => 0,
541 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
542 'html' => [
543 'label' => ts("Recurring Contribution"),
544 ],
545 'add' => '3.3',
546 ],
547 'member_campaign_id' => [
548 'name' => 'campaign_id',
549 'type' => CRM_Utils_Type::T_INT,
550 'title' => ts('Campaign ID'),
551 'description' => ts('The campaign for which this membership is attached.'),
552 'import' => TRUE,
553 'where' => 'civicrm_membership.campaign_id',
554 'export' => TRUE,
555 'table_name' => 'civicrm_membership',
556 'entity' => 'Membership',
557 'bao' => 'CRM_Member_BAO_Membership',
558 'localizable' => 0,
559 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
560 'component' => 'CiviCampaign',
561 'html' => [
562 'type' => 'EntityRef',
563 'label' => ts("Campaign"),
564 ],
565 'pseudoconstant' => [
566 'table' => 'civicrm_campaign',
567 'keyColumn' => 'id',
568 'labelColumn' => 'title',
569 'prefetch' => 'FALSE',
570 ],
571 'add' => '3.4',
572 ],
573 ];
574 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
575 }
576 return Civi::$statics[__CLASS__]['fields'];
577 }
578
579 /**
580 * Return a mapping from field-name to the corresponding key (as used in fields()).
581 *
582 * @return array
583 * Array(string $name => string $uniqueName).
584 */
585 public static function &fieldKeys() {
586 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
587 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
588 }
589 return Civi::$statics[__CLASS__]['fieldKeys'];
590 }
591
592 /**
593 * Returns the names of this table
594 *
595 * @return string
596 */
597 public static function getTableName() {
598 return self::$_tableName;
599 }
600
601 /**
602 * Returns if this table needs to be logged
603 *
604 * @return bool
605 */
606 public function getLog() {
607 return self::$_log;
608 }
609
610 /**
611 * Returns the list of fields that can be imported
612 *
613 * @param bool $prefix
614 *
615 * @return array
616 */
617 public static function &import($prefix = FALSE) {
618 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, []);
619 return $r;
620 }
621
622 /**
623 * Returns the list of fields that can be exported
624 *
625 * @param bool $prefix
626 *
627 * @return array
628 */
629 public static function &export($prefix = FALSE) {
630 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, []);
631 return $r;
632 }
633
634 /**
635 * Returns the list of indices
636 *
637 * @param bool $localize
638 *
639 * @return array
640 */
641 public static function indices($localize = TRUE) {
642 $indices = [
643 'index_owner_membership_id' => [
644 'name' => 'index_owner_membership_id',
645 'field' => [
646 0 => 'owner_membership_id',
647 ],
648 'localizable' => FALSE,
649 'sig' => 'civicrm_membership::0::owner_membership_id',
650 ],
651 ];
652 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
653 }
654
655 }