Merge branch '5.11' of https://github.com/civicrm/civicrm-core
[civicrm-core.git] / CRM / Member / DAO / Membership.php
CommitLineData
e501603b 1<?php
c3fc2621 2
e501603b
TO
3/**
4 * @package CRM
6b83d5bd 5 * @copyright CiviCRM LLC (c) 2004-2019
e501603b
TO
6 *
7 * Generated from xml/schema/CRM/Member/Membership.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
e380ee3b 9 * (GenCodeChecksum:f292ac185330c17ffa8c647359ab07b4)
e501603b 10 */
c3fc2621 11
f41f0342 12/**
c3fc2621 13 * Database access object for the Membership entity.
f41f0342 14 */
e501603b 15class CRM_Member_DAO_Membership extends CRM_Core_DAO {
c3fc2621 16
e501603b 17 /**
f41f0342 18 * Static instance to hold the table name.
e501603b
TO
19 *
20 * @var string
21 */
22 static $_tableName = 'civicrm_membership';
c3fc2621 23
e501603b 24 /**
f41f0342 25 * Should CiviCRM log any modifications to this table in the civicrm_log table.
e501603b 26 *
c3fc2621 27 * @var bool
e501603b 28 */
c3fc2621
CW
29 static $_log = TRUE;
30
e501603b
TO
31 /**
32 * Membership Id
33 *
34 * @var int unsigned
35 */
36 public $id;
c3fc2621 37
e501603b
TO
38 /**
39 * FK to Contact ID
40 *
41 * @var int unsigned
42 */
43 public $contact_id;
c3fc2621 44
e501603b
TO
45 /**
46 * FK to Membership Type
47 *
48 * @var int unsigned
49 */
50 public $membership_type_id;
c3fc2621 51
e501603b
TO
52 /**
53 * Beginning of initial membership period (member since...).
54 *
55 * @var date
56 */
57 public $join_date;
c3fc2621 58
e501603b
TO
59 /**
60 * Beginning of current uninterrupted membership period.
61 *
62 * @var date
63 */
64 public $start_date;
c3fc2621 65
e501603b
TO
66 /**
67 * Current membership period expire date.
68 *
69 * @var date
70 */
71 public $end_date;
c3fc2621 72
e501603b 73 /**
e501603b
TO
74 * @var string
75 */
76 public $source;
c3fc2621 77
e501603b
TO
78 /**
79 * FK to Membership Status
80 *
81 * @var int unsigned
82 */
83 public $status_id;
c3fc2621 84
e501603b
TO
85 /**
86 * 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.
87 *
88 * @var boolean
89 */
90 public $is_override;
c3fc2621 91
e136f704
O
92 /**
93 * Then end date of membership status override if 'Override until selected date' override type is selected.
94 *
95 * @var date
96 */
97 public $status_override_end_date;
98
e501603b
TO
99 /**
100 * Optional FK to Parent Membership.
101 *
102 * @var int unsigned
103 */
104 public $owner_membership_id;
c3fc2621 105
e501603b
TO
106 /**
107 * Maximum number of related memberships (membership_type override).
108 *
109 * @var int
110 */
111 public $max_related;
c3fc2621 112
e501603b 113 /**
e501603b
TO
114 * @var boolean
115 */
116 public $is_test;
c3fc2621 117
e501603b 118 /**
e501603b
TO
119 * @var boolean
120 */
121 public $is_pay_later;
c3fc2621 122
e501603b
TO
123 /**
124 * 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.
125 *
126 * @var int unsigned
127 */
128 public $contribution_recur_id;
c3fc2621 129
e501603b
TO
130 /**
131 * The campaign for which this membership is attached.
132 *
133 * @var int unsigned
134 */
135 public $campaign_id;
c3fc2621 136
e501603b 137 /**
f41f0342 138 * Class constructor.
e501603b 139 */
c3fc2621 140 public function __construct() {
e501603b
TO
141 $this->__table = 'civicrm_membership';
142 parent::__construct();
143 }
c3fc2621 144
e501603b 145 /**
f41f0342 146 * Returns foreign keys and entity references.
e501603b
TO
147 *
148 * @return array
149 * [CRM_Core_Reference_Interface]
150 */
c3fc2621 151 public static function getReferenceColumns() {
346aaaba
TO
152 if (!isset(Civi::$statics[__CLASS__]['links'])) {
153 Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
c3fc2621
CW
154 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
155 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'membership_type_id', 'civicrm_membership_type', 'id');
156 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'status_id', 'civicrm_membership_status', 'id');
157 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'owner_membership_id', 'civicrm_membership', 'id');
158 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
159 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
346aaaba 160 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
e501603b 161 }
346aaaba 162 return Civi::$statics[__CLASS__]['links'];
e501603b 163 }
c3fc2621 164
e501603b
TO
165 /**
166 * Returns all the column names of this table
167 *
168 * @return array
169 */
c3fc2621 170 public static function &fields() {
346aaaba 171 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
c3fc2621
CW
172 Civi::$statics[__CLASS__]['fields'] = [
173 'membership_id' => [
e501603b
TO
174 'name' => 'id',
175 'type' => CRM_Utils_Type::T_INT,
c3fc2621 176 'title' => ts('Membership ID'),
215b423e 177 'description' => ts('Membership Id'),
c3fc2621
CW
178 'required' => TRUE,
179 'import' => TRUE,
e501603b
TO
180 'where' => 'civicrm_membership.id',
181 'headerPattern' => '/^(m(embership\s)?id)$/i',
182 'dataPattern' => '',
c3fc2621 183 'export' => TRUE,
522a26c9 184 'table_name' => 'civicrm_membership',
185 'entity' => 'Membership',
186 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 187 'localizable' => 0,
c3fc2621
CW
188 ],
189 'membership_contact_id' => [
e501603b
TO
190 'name' => 'contact_id',
191 'type' => CRM_Utils_Type::T_INT,
c3fc2621 192 'title' => ts('Contact ID'),
215b423e 193 'description' => ts('FK to Contact ID'),
c3fc2621
CW
194 'required' => TRUE,
195 'import' => TRUE,
e501603b
TO
196 'where' => 'civicrm_membership.contact_id',
197 'headerPattern' => '/contact(.?id)?/i',
198 'dataPattern' => '/^\d+$/',
c3fc2621 199 'export' => TRUE,
522a26c9 200 'table_name' => 'civicrm_membership',
201 'entity' => 'Membership',
202 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 203 'localizable' => 0,
e501603b 204 'FKClassName' => 'CRM_Contact_DAO_Contact',
c3fc2621 205 'html' => [
e501603b 206 'type' => 'EntityRef',
c3fc2621
CW
207 ],
208 ],
209 'membership_type_id' => [
e501603b
TO
210 'name' => 'membership_type_id',
211 'type' => CRM_Utils_Type::T_INT,
c3fc2621 212 'title' => ts('Membership Type Id'),
215b423e 213 'description' => ts('FK to Membership Type'),
c3fc2621
CW
214 'required' => TRUE,
215 'import' => TRUE,
e501603b
TO
216 'where' => 'civicrm_membership.membership_type_id',
217 'headerPattern' => '/^(m(embership\s)?type)$/i',
218 'dataPattern' => '',
c3fc2621 219 'export' => FALSE,
522a26c9 220 'table_name' => 'civicrm_membership',
221 'entity' => 'Membership',
222 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 223 'localizable' => 0,
e501603b 224 'FKClassName' => 'CRM_Member_DAO_MembershipType',
c3fc2621 225 'html' => [
e501603b 226 'type' => 'Select',
c3fc2621
CW
227 ],
228 'pseudoconstant' => [
e501603b
TO
229 'table' => 'civicrm_membership_type',
230 'keyColumn' => 'id',
231 'labelColumn' => 'name',
c3fc2621
CW
232 ]
233 ],
234 'join_date' => [
e501603b
TO
235 'name' => 'join_date',
236 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 237 'title' => ts('Member Since'),
215b423e 238 'description' => ts('Beginning of initial membership period (member since...).'),
c3fc2621 239 'import' => TRUE,
e501603b
TO
240 'where' => 'civicrm_membership.join_date',
241 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
242 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
c3fc2621 243 'export' => TRUE,
522a26c9 244 'table_name' => 'civicrm_membership',
245 'entity' => 'Membership',
246 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 247 'localizable' => 0,
c3fc2621 248 'html' => [
e501603b 249 'type' => 'Select Date',
24317d89 250 'formatType' => 'activityDate',
c3fc2621
CW
251 ],
252 ],
253 'membership_start_date' => [
e501603b
TO
254 'name' => 'start_date',
255 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 256 'title' => ts('Membership Start Date'),
215b423e 257 'description' => ts('Beginning of current uninterrupted membership period.'),
c3fc2621 258 'import' => TRUE,
e501603b
TO
259 'where' => 'civicrm_membership.start_date',
260 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
261 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
c3fc2621 262 'export' => TRUE,
522a26c9 263 'table_name' => 'civicrm_membership',
264 'entity' => 'Membership',
265 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 266 'localizable' => 0,
c3fc2621 267 'html' => [
e501603b 268 'type' => 'Select Date',
24317d89 269 'formatType' => 'activityDate',
c3fc2621
CW
270 ],
271 ],
272 'membership_end_date' => [
e501603b
TO
273 'name' => 'end_date',
274 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 275 'title' => ts('Membership Expiration Date'),
215b423e 276 'description' => ts('Current membership period expire date.'),
c3fc2621 277 'import' => TRUE,
e501603b
TO
278 'where' => 'civicrm_membership.end_date',
279 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
280 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
c3fc2621 281 'export' => TRUE,
522a26c9 282 'table_name' => 'civicrm_membership',
283 'entity' => 'Membership',
284 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 285 'localizable' => 0,
c3fc2621 286 'html' => [
e501603b 287 'type' => 'Select Date',
24317d89 288 'formatType' => 'activityDate',
c3fc2621
CW
289 ],
290 ],
291 'membership_source' => [
e501603b
TO
292 'name' => 'source',
293 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 294 'title' => ts('Source'),
e501603b
TO
295 'maxlength' => 128,
296 'size' => CRM_Utils_Type::HUGE,
c3fc2621 297 'import' => TRUE,
e501603b
TO
298 'where' => 'civicrm_membership.source',
299 'headerPattern' => '/^(member(ship?))?source$/i',
300 'dataPattern' => '',
c3fc2621 301 'export' => TRUE,
522a26c9 302 'table_name' => 'civicrm_membership',
303 'entity' => 'Membership',
304 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 305 'localizable' => 0,
c3fc2621 306 'html' => [
e501603b 307 'type' => 'Text',
c3fc2621
CW
308 ],
309 ],
310 'status_id' => [
e501603b
TO
311 'name' => 'status_id',
312 'type' => CRM_Utils_Type::T_INT,
c3fc2621 313 'title' => ts('Membership Status Id'),
215b423e 314 'description' => ts('FK to Membership Status'),
c3fc2621
CW
315 'required' => TRUE,
316 'import' => TRUE,
e501603b
TO
317 'where' => 'civicrm_membership.status_id',
318 'headerPattern' => '/(member(ship|).)?(status)$/i',
319 'dataPattern' => '',
c3fc2621 320 'export' => FALSE,
522a26c9 321 'table_name' => 'civicrm_membership',
322 'entity' => 'Membership',
323 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 324 'localizable' => 0,
e501603b 325 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
c3fc2621 326 'html' => [
e501603b 327 'type' => 'Select',
c3fc2621
CW
328 ],
329 'pseudoconstant' => [
e501603b
TO
330 'table' => 'civicrm_membership_status',
331 'keyColumn' => 'id',
332 'labelColumn' => 'label',
c3fc2621
CW
333 ]
334 ],
335 'is_override' => [
e501603b
TO
336 'name' => 'is_override',
337 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 338 'title' => ts('Status Override'),
215b423e 339 '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.'),
c3fc2621 340 'import' => TRUE,
e501603b
TO
341 'where' => 'civicrm_membership.is_override',
342 'headerPattern' => '/override$/i',
343 'dataPattern' => '',
c3fc2621 344 'export' => TRUE,
522a26c9 345 'table_name' => 'civicrm_membership',
346 'entity' => 'Membership',
347 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 348 'localizable' => 0,
c3fc2621 349 'html' => [
e501603b 350 'type' => 'CheckBox',
c3fc2621
CW
351 ],
352 ],
e136f704
O
353 'status_override_end_date' => [
354 'name' => 'status_override_end_date',
355 'type' => CRM_Utils_Type::T_DATE,
356 'title' => ts('Status Override End Date'),
215b423e 357 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
e136f704
O
358 'import' => TRUE,
359 'where' => 'civicrm_membership.status_override_end_date',
360 'headerPattern' => '',
361 'dataPattern' => '',
362 'export' => TRUE,
363 'default' => 'NULL',
364 'table_name' => 'civicrm_membership',
365 'entity' => 'Membership',
366 'bao' => 'CRM_Member_BAO_Membership',
367 'localizable' => 0,
368 'html' => [
369 'type' => 'Select Date',
370 ],
371 ],
c3fc2621 372 'owner_membership_id' => [
e501603b
TO
373 'name' => 'owner_membership_id',
374 'type' => CRM_Utils_Type::T_INT,
c3fc2621 375 'title' => ts('Primary Member ID'),
215b423e 376 'description' => ts('Optional FK to Parent Membership.'),
c3fc2621 377 'export' => TRUE,
e501603b
TO
378 'where' => 'civicrm_membership.owner_membership_id',
379 'headerPattern' => '',
380 'dataPattern' => '',
522a26c9 381 'table_name' => 'civicrm_membership',
382 'entity' => 'Membership',
383 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 384 'localizable' => 0,
e501603b 385 'FKClassName' => 'CRM_Member_DAO_Membership',
c3fc2621
CW
386 ],
387 'max_related' => [
e501603b
TO
388 'name' => 'max_related',
389 'type' => CRM_Utils_Type::T_INT,
c3fc2621 390 'title' => ts('Max Related'),
215b423e 391 'description' => ts('Maximum number of related memberships (membership_type override).'),
522a26c9 392 'table_name' => 'civicrm_membership',
393 'entity' => 'Membership',
394 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 395 'localizable' => 0,
c3fc2621 396 'html' => [
e501603b 397 'type' => 'Text',
c3fc2621
CW
398 ],
399 ],
400 'member_is_test' => [
e501603b
TO
401 'name' => 'is_test',
402 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621
CW
403 'title' => ts('Test'),
404 'import' => TRUE,
e501603b
TO
405 'where' => 'civicrm_membership.is_test',
406 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
407 'dataPattern' => '',
c3fc2621 408 'export' => TRUE,
45a83e42 409 'default' => '0',
522a26c9 410 'table_name' => 'civicrm_membership',
411 'entity' => 'Membership',
412 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 413 'localizable' => 0,
c3fc2621 414 'html' => [
e501603b 415 'type' => 'CheckBox',
c3fc2621
CW
416 ],
417 ],
418 'member_is_pay_later' => [
e501603b
TO
419 'name' => 'is_pay_later',
420 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621
CW
421 'title' => ts('Is Pay Later'),
422 'import' => TRUE,
e501603b
TO
423 'where' => 'civicrm_membership.is_pay_later',
424 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
425 'dataPattern' => '',
c3fc2621 426 'export' => TRUE,
45a83e42 427 'default' => '0',
522a26c9 428 'table_name' => 'civicrm_membership',
429 'entity' => 'Membership',
430 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 431 'localizable' => 0,
c3fc2621 432 'html' => [
e501603b 433 'type' => 'CheckBox',
c3fc2621
CW
434 ],
435 ],
436 'contribution_recur_id' => [
e501603b
TO
437 'name' => 'contribution_recur_id',
438 'type' => CRM_Utils_Type::T_INT,
c3fc2621 439 'title' => ts('Membership Recurring Contribution'),
215b423e 440 '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.'),
522a26c9 441 'table_name' => 'civicrm_membership',
442 'entity' => 'Membership',
443 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 444 'localizable' => 0,
e501603b 445 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
c3fc2621
CW
446 ],
447 'member_campaign_id' => [
e501603b
TO
448 'name' => 'campaign_id',
449 'type' => CRM_Utils_Type::T_INT,
c3fc2621 450 'title' => ts('Campaign'),
215b423e 451 'description' => ts('The campaign for which this membership is attached.'),
c3fc2621 452 'import' => TRUE,
e501603b
TO
453 'where' => 'civicrm_membership.campaign_id',
454 'headerPattern' => '',
455 'dataPattern' => '',
c3fc2621 456 'export' => TRUE,
522a26c9 457 'table_name' => 'civicrm_membership',
458 'entity' => 'Membership',
459 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 460 'localizable' => 0,
e501603b 461 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
c3fc2621 462 'html' => [
e501603b 463 'type' => 'Select',
c3fc2621
CW
464 ],
465 'pseudoconstant' => [
e501603b
TO
466 'table' => 'civicrm_campaign',
467 'keyColumn' => 'id',
468 'labelColumn' => 'title',
c3fc2621
CW
469 ]
470 ],
471 ];
346aaaba 472 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 473 }
346aaaba 474 return Civi::$statics[__CLASS__]['fields'];
e501603b 475 }
c3fc2621 476
e501603b 477 /**
bd8e0b14 478 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
479 *
480 * @return array
bd8e0b14 481 * Array(string $name => string $uniqueName).
e501603b 482 */
c3fc2621 483 public static function &fieldKeys() {
bd8e0b14
TO
484 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
485 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 486 }
bd8e0b14 487 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 488 }
c3fc2621 489
e501603b
TO
490 /**
491 * Returns the names of this table
492 *
493 * @return string
494 */
c3fc2621 495 public static function getTableName() {
e501603b
TO
496 return self::$_tableName;
497 }
c3fc2621 498
e501603b
TO
499 /**
500 * Returns if this table needs to be logged
501 *
c3fc2621 502 * @return bool
e501603b 503 */
c3fc2621 504 public function getLog() {
e501603b
TO
505 return self::$_log;
506 }
c3fc2621 507
e501603b
TO
508 /**
509 * Returns the list of fields that can be imported
510 *
511 * @param bool $prefix
512 *
513 * @return array
514 */
c3fc2621
CW
515 public static function &import($prefix = FALSE) {
516 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, []);
60808919 517 return $r;
e501603b 518 }
c3fc2621 519
e501603b
TO
520 /**
521 * Returns the list of fields that can be exported
522 *
523 * @param bool $prefix
524 *
525 * @return array
526 */
c3fc2621
CW
527 public static function &export($prefix = FALSE) {
528 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, []);
60808919 529 return $r;
e501603b 530 }
c3fc2621 531
e7a6b91a
AS
532 /**
533 * Returns the list of indices
c3fc2621
CW
534 *
535 * @param bool $localize
536 *
537 * @return array
e7a6b91a
AS
538 */
539 public static function indices($localize = TRUE) {
c3fc2621
CW
540 $indices = [
541 'index_owner_membership_id' => [
e7a6b91a 542 'name' => 'index_owner_membership_id',
c3fc2621 543 'field' => [
e7a6b91a 544 0 => 'owner_membership_id',
c3fc2621
CW
545 ],
546 'localizable' => FALSE,
e7a6b91a 547 'sig' => 'civicrm_membership::0::owner_membership_id',
c3fc2621
CW
548 ],
549 ];
e7a6b91a
AS
550 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
551 }
c3fc2621 552
e501603b 553}