Merge pull request #22587 from colemanw/apiNull
[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:0619aa3946bcadcab1919672c9ecf35a)
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|null
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|null
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|null
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 'import' => TRUE,
425 'where' => 'civicrm_membership.is_override',
426 'headerPattern' => '/override$/i',
427 'export' => TRUE,
428 'table_name' => 'civicrm_membership',
429 'entity' => 'Membership',
430 'bao' => 'CRM_Member_BAO_Membership',
431 'localizable' => 0,
432 'html' => [
433 'type' => 'CheckBox',
434 ],
435 'add' => '1.5',
436 ],
437 'status_override_end_date' => [
438 'name' => 'status_override_end_date',
439 'type' => CRM_Utils_Type::T_DATE,
440 'title' => ts('Status Override End Date'),
441 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
442 'import' => TRUE,
443 'where' => 'civicrm_membership.status_override_end_date',
444 'export' => TRUE,
445 'default' => NULL,
446 'table_name' => 'civicrm_membership',
447 'entity' => 'Membership',
448 'bao' => 'CRM_Member_BAO_Membership',
449 'localizable' => 0,
450 'html' => [
451 'type' => 'Select Date',
452 'formatType' => 'activityDate',
453 ],
454 'add' => '4.7',
455 ],
456 'owner_membership_id' => [
457 'name' => 'owner_membership_id',
458 'type' => CRM_Utils_Type::T_INT,
459 'title' => ts('Primary Member ID'),
460 'description' => ts('Optional FK to Parent Membership.'),
461 'where' => 'civicrm_membership.owner_membership_id',
462 'export' => TRUE,
463 'table_name' => 'civicrm_membership',
464 'entity' => 'Membership',
465 'bao' => 'CRM_Member_BAO_Membership',
466 'localizable' => 0,
467 'FKClassName' => 'CRM_Member_DAO_Membership',
468 'html' => [
469 'label' => ts("Primary Member"),
470 ],
471 'add' => '1.7',
472 ],
473 'max_related' => [
474 'name' => 'max_related',
475 'type' => CRM_Utils_Type::T_INT,
476 'title' => ts('Max Related'),
477 'description' => ts('Maximum number of related memberships (membership_type override).'),
478 'where' => 'civicrm_membership.max_related',
479 'export' => TRUE,
480 'table_name' => 'civicrm_membership',
481 'entity' => 'Membership',
482 'bao' => 'CRM_Member_BAO_Membership',
483 'localizable' => 0,
484 'html' => [
485 'type' => 'Text',
486 'label' => ts("Maximum number of related memberships"),
487 ],
488 'add' => '4.3',
489 ],
490 'member_is_test' => [
491 'name' => 'is_test',
492 'type' => CRM_Utils_Type::T_BOOLEAN,
493 'title' => ts('Test'),
494 'import' => TRUE,
495 'where' => 'civicrm_membership.is_test',
496 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
497 'export' => TRUE,
498 'default' => '0',
499 'table_name' => 'civicrm_membership',
500 'entity' => 'Membership',
501 'bao' => 'CRM_Member_BAO_Membership',
502 'localizable' => 0,
503 'html' => [
504 'type' => 'CheckBox',
505 ],
506 'add' => NULL,
507 ],
508 'member_is_pay_later' => [
509 'name' => 'is_pay_later',
510 'type' => CRM_Utils_Type::T_BOOLEAN,
511 'title' => ts('Is Pay Later'),
512 'import' => TRUE,
513 'where' => 'civicrm_membership.is_pay_later',
514 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
515 'export' => TRUE,
516 'default' => '0',
517 'table_name' => 'civicrm_membership',
518 'entity' => 'Membership',
519 'bao' => 'CRM_Member_BAO_Membership',
520 'localizable' => 0,
521 'html' => [
522 'type' => 'CheckBox',
523 ],
524 'add' => '2.1',
525 ],
526 'membership_recur_id' => [
527 'name' => 'contribution_recur_id',
528 'type' => CRM_Utils_Type::T_INT,
529 'title' => ts('Recurring Contribution ID'),
530 '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.'),
531 'where' => 'civicrm_membership.contribution_recur_id',
532 'export' => TRUE,
533 'table_name' => 'civicrm_membership',
534 'entity' => 'Membership',
535 'bao' => 'CRM_Member_BAO_Membership',
536 'localizable' => 0,
537 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
538 'html' => [
539 'label' => ts("Recurring Contribution"),
540 ],
541 'add' => '3.3',
542 ],
543 'member_campaign_id' => [
544 'name' => 'campaign_id',
545 'type' => CRM_Utils_Type::T_INT,
546 'title' => ts('Campaign ID'),
547 'description' => ts('The campaign for which this membership is attached.'),
548 'import' => TRUE,
549 'where' => 'civicrm_membership.campaign_id',
550 'export' => TRUE,
551 'table_name' => 'civicrm_membership',
552 'entity' => 'Membership',
553 'bao' => 'CRM_Member_BAO_Membership',
554 'localizable' => 0,
555 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
556 'component' => 'CiviCampaign',
557 'html' => [
558 'type' => 'EntityRef',
559 'label' => ts("Campaign"),
560 ],
561 'pseudoconstant' => [
562 'table' => 'civicrm_campaign',
563 'keyColumn' => 'id',
564 'labelColumn' => 'title',
565 'prefetch' => 'FALSE',
566 ],
567 'add' => '3.4',
568 ],
569 ];
570 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
571 }
572 return Civi::$statics[__CLASS__]['fields'];
573 }
574
575 /**
576 * Return a mapping from field-name to the corresponding key (as used in fields()).
577 *
578 * @return array
579 * Array(string $name => string $uniqueName).
580 */
581 public static function &fieldKeys() {
582 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
583 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
584 }
585 return Civi::$statics[__CLASS__]['fieldKeys'];
586 }
587
588 /**
589 * Returns the names of this table
590 *
591 * @return string
592 */
593 public static function getTableName() {
594 return self::$_tableName;
595 }
596
597 /**
598 * Returns if this table needs to be logged
599 *
600 * @return bool
601 */
602 public function getLog() {
603 return self::$_log;
604 }
605
606 /**
607 * Returns the list of fields that can be imported
608 *
609 * @param bool $prefix
610 *
611 * @return array
612 */
613 public static function &import($prefix = FALSE) {
614 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, []);
615 return $r;
616 }
617
618 /**
619 * Returns the list of fields that can be exported
620 *
621 * @param bool $prefix
622 *
623 * @return array
624 */
625 public static function &export($prefix = FALSE) {
626 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, []);
627 return $r;
628 }
629
630 /**
631 * Returns the list of indices
632 *
633 * @param bool $localize
634 *
635 * @return array
636 */
637 public static function indices($localize = TRUE) {
638 $indices = [
639 'index_owner_membership_id' => [
640 'name' => 'index_owner_membership_id',
641 'field' => [
642 0 => 'owner_membership_id',
643 ],
644 'localizable' => FALSE,
645 'sig' => 'civicrm_membership::0::owner_membership_id',
646 ],
647 ];
648 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
649 }
650
651 }