Declare API Key as a protected field for future use
[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
042043f1 9 * (GenCodeChecksum:72919c0169ae25f090c3f021904465e9)
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 */
fa45b5b9 22 public 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 */
fa45b5b9 29 public static $_log = TRUE;
c3fc2621 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 152 if (!isset(Civi::$statics[__CLASS__]['links'])) {
fa45b5b9 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',
c3fc2621 182 'export' => TRUE,
522a26c9 183 'table_name' => 'civicrm_membership',
184 'entity' => 'Membership',
185 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 186 'localizable' => 0,
c3fc2621
CW
187 ],
188 'membership_contact_id' => [
e501603b
TO
189 'name' => 'contact_id',
190 'type' => CRM_Utils_Type::T_INT,
c3fc2621 191 'title' => ts('Contact ID'),
215b423e 192 'description' => ts('FK to Contact ID'),
c3fc2621
CW
193 'required' => TRUE,
194 'import' => TRUE,
e501603b
TO
195 'where' => 'civicrm_membership.contact_id',
196 'headerPattern' => '/contact(.?id)?/i',
197 'dataPattern' => '/^\d+$/',
c3fc2621 198 'export' => TRUE,
522a26c9 199 'table_name' => 'civicrm_membership',
200 'entity' => 'Membership',
201 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 202 'localizable' => 0,
e501603b 203 'FKClassName' => 'CRM_Contact_DAO_Contact',
c3fc2621 204 'html' => [
e501603b 205 'type' => 'EntityRef',
c3fc2621
CW
206 ],
207 ],
208 'membership_type_id' => [
e501603b
TO
209 'name' => 'membership_type_id',
210 'type' => CRM_Utils_Type::T_INT,
c3fc2621 211 'title' => ts('Membership Type Id'),
215b423e 212 'description' => ts('FK to Membership Type'),
c3fc2621
CW
213 'required' => TRUE,
214 'import' => TRUE,
e501603b
TO
215 'where' => 'civicrm_membership.membership_type_id',
216 'headerPattern' => '/^(m(embership\s)?type)$/i',
c3fc2621 217 'export' => FALSE,
522a26c9 218 'table_name' => 'civicrm_membership',
219 'entity' => 'Membership',
220 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 221 'localizable' => 0,
e501603b 222 'FKClassName' => 'CRM_Member_DAO_MembershipType',
c3fc2621 223 'html' => [
e501603b 224 'type' => 'Select',
c3fc2621
CW
225 ],
226 'pseudoconstant' => [
e501603b
TO
227 'table' => 'civicrm_membership_type',
228 'keyColumn' => 'id',
229 'labelColumn' => 'name',
c3fc2621
CW
230 ]
231 ],
232 'join_date' => [
e501603b
TO
233 'name' => 'join_date',
234 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 235 'title' => ts('Member Since'),
215b423e 236 'description' => ts('Beginning of initial membership period (member since...).'),
c3fc2621 237 'import' => TRUE,
e501603b
TO
238 'where' => 'civicrm_membership.join_date',
239 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
240 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
c3fc2621 241 'export' => TRUE,
522a26c9 242 'table_name' => 'civicrm_membership',
243 'entity' => 'Membership',
244 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 245 'localizable' => 0,
c3fc2621 246 'html' => [
e501603b 247 'type' => 'Select Date',
24317d89 248 'formatType' => 'activityDate',
c3fc2621
CW
249 ],
250 ],
251 'membership_start_date' => [
e501603b
TO
252 'name' => 'start_date',
253 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 254 'title' => ts('Membership Start Date'),
215b423e 255 'description' => ts('Beginning of current uninterrupted membership period.'),
c3fc2621 256 'import' => TRUE,
e501603b
TO
257 'where' => 'civicrm_membership.start_date',
258 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
259 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
c3fc2621 260 'export' => TRUE,
522a26c9 261 'table_name' => 'civicrm_membership',
262 'entity' => 'Membership',
263 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 264 'localizable' => 0,
c3fc2621 265 'html' => [
e501603b 266 'type' => 'Select Date',
24317d89 267 'formatType' => 'activityDate',
c3fc2621
CW
268 ],
269 ],
270 'membership_end_date' => [
e501603b
TO
271 'name' => 'end_date',
272 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 273 'title' => ts('Membership Expiration Date'),
215b423e 274 'description' => ts('Current membership period expire date.'),
c3fc2621 275 'import' => TRUE,
e501603b
TO
276 'where' => 'civicrm_membership.end_date',
277 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
278 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
c3fc2621 279 'export' => TRUE,
522a26c9 280 'table_name' => 'civicrm_membership',
281 'entity' => 'Membership',
282 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 283 'localizable' => 0,
c3fc2621 284 'html' => [
e501603b 285 'type' => 'Select Date',
24317d89 286 'formatType' => 'activityDate',
c3fc2621
CW
287 ],
288 ],
289 'membership_source' => [
e501603b
TO
290 'name' => 'source',
291 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 292 'title' => ts('Source'),
e501603b
TO
293 'maxlength' => 128,
294 'size' => CRM_Utils_Type::HUGE,
c3fc2621 295 'import' => TRUE,
e501603b
TO
296 'where' => 'civicrm_membership.source',
297 'headerPattern' => '/^(member(ship?))?source$/i',
c3fc2621 298 'export' => TRUE,
522a26c9 299 'table_name' => 'civicrm_membership',
300 'entity' => 'Membership',
301 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 302 'localizable' => 0,
c3fc2621 303 'html' => [
e501603b 304 'type' => 'Text',
c3fc2621
CW
305 ],
306 ],
307 'status_id' => [
e501603b
TO
308 'name' => 'status_id',
309 'type' => CRM_Utils_Type::T_INT,
c3fc2621 310 'title' => ts('Membership Status Id'),
215b423e 311 'description' => ts('FK to Membership Status'),
c3fc2621
CW
312 'required' => TRUE,
313 'import' => TRUE,
e501603b
TO
314 'where' => 'civicrm_membership.status_id',
315 'headerPattern' => '/(member(ship|).)?(status)$/i',
c3fc2621 316 'export' => FALSE,
522a26c9 317 'table_name' => 'civicrm_membership',
318 'entity' => 'Membership',
319 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 320 'localizable' => 0,
e501603b 321 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
c3fc2621 322 'html' => [
e501603b 323 'type' => 'Select',
c3fc2621
CW
324 ],
325 'pseudoconstant' => [
e501603b
TO
326 'table' => 'civicrm_membership_status',
327 'keyColumn' => 'id',
328 'labelColumn' => 'label',
c3fc2621
CW
329 ]
330 ],
331 'is_override' => [
e501603b
TO
332 'name' => 'is_override',
333 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 334 'title' => ts('Status Override'),
215b423e 335 '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 336 'import' => TRUE,
e501603b
TO
337 'where' => 'civicrm_membership.is_override',
338 'headerPattern' => '/override$/i',
c3fc2621 339 'export' => TRUE,
522a26c9 340 'table_name' => 'civicrm_membership',
341 'entity' => 'Membership',
342 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 343 'localizable' => 0,
c3fc2621 344 'html' => [
e501603b 345 'type' => 'CheckBox',
c3fc2621
CW
346 ],
347 ],
e136f704
O
348 'status_override_end_date' => [
349 'name' => 'status_override_end_date',
350 'type' => CRM_Utils_Type::T_DATE,
351 'title' => ts('Status Override End Date'),
215b423e 352 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
e136f704
O
353 'import' => TRUE,
354 'where' => 'civicrm_membership.status_override_end_date',
e136f704
O
355 'export' => TRUE,
356 'default' => 'NULL',
357 'table_name' => 'civicrm_membership',
358 'entity' => 'Membership',
359 'bao' => 'CRM_Member_BAO_Membership',
360 'localizable' => 0,
361 'html' => [
362 'type' => 'Select Date',
363 ],
364 ],
c3fc2621 365 'owner_membership_id' => [
e501603b
TO
366 'name' => 'owner_membership_id',
367 'type' => CRM_Utils_Type::T_INT,
c3fc2621 368 'title' => ts('Primary Member ID'),
215b423e 369 'description' => ts('Optional FK to Parent Membership.'),
e501603b 370 'where' => 'civicrm_membership.owner_membership_id',
a36434b9 371 'export' => TRUE,
522a26c9 372 'table_name' => 'civicrm_membership',
373 'entity' => 'Membership',
374 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 375 'localizable' => 0,
e501603b 376 'FKClassName' => 'CRM_Member_DAO_Membership',
c3fc2621
CW
377 ],
378 'max_related' => [
e501603b
TO
379 'name' => 'max_related',
380 'type' => CRM_Utils_Type::T_INT,
c3fc2621 381 'title' => ts('Max Related'),
215b423e 382 'description' => ts('Maximum number of related memberships (membership_type override).'),
a36434b9 383 'where' => 'civicrm_membership.max_related',
522a26c9 384 'table_name' => 'civicrm_membership',
385 'entity' => 'Membership',
386 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 387 'localizable' => 0,
c3fc2621 388 'html' => [
e501603b 389 'type' => 'Text',
c3fc2621
CW
390 ],
391 ],
392 'member_is_test' => [
e501603b
TO
393 'name' => 'is_test',
394 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621
CW
395 'title' => ts('Test'),
396 'import' => TRUE,
e501603b
TO
397 'where' => 'civicrm_membership.is_test',
398 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
c3fc2621 399 'export' => TRUE,
45a83e42 400 'default' => '0',
522a26c9 401 'table_name' => 'civicrm_membership',
402 'entity' => 'Membership',
403 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 404 'localizable' => 0,
c3fc2621 405 'html' => [
e501603b 406 'type' => 'CheckBox',
c3fc2621
CW
407 ],
408 ],
409 'member_is_pay_later' => [
e501603b
TO
410 'name' => 'is_pay_later',
411 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621
CW
412 'title' => ts('Is Pay Later'),
413 'import' => TRUE,
e501603b
TO
414 'where' => 'civicrm_membership.is_pay_later',
415 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
c3fc2621 416 'export' => TRUE,
45a83e42 417 'default' => '0',
522a26c9 418 'table_name' => 'civicrm_membership',
419 'entity' => 'Membership',
420 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 421 'localizable' => 0,
c3fc2621 422 'html' => [
e501603b 423 'type' => 'CheckBox',
c3fc2621
CW
424 ],
425 ],
426 'contribution_recur_id' => [
e501603b
TO
427 'name' => 'contribution_recur_id',
428 'type' => CRM_Utils_Type::T_INT,
c3fc2621 429 'title' => ts('Membership Recurring Contribution'),
215b423e 430 '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.'),
a36434b9 431 'where' => 'civicrm_membership.contribution_recur_id',
522a26c9 432 'table_name' => 'civicrm_membership',
433 'entity' => 'Membership',
434 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 435 'localizable' => 0,
e501603b 436 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
c3fc2621
CW
437 ],
438 'member_campaign_id' => [
e501603b
TO
439 'name' => 'campaign_id',
440 'type' => CRM_Utils_Type::T_INT,
c3fc2621 441 'title' => ts('Campaign'),
215b423e 442 'description' => ts('The campaign for which this membership is attached.'),
c3fc2621 443 'import' => TRUE,
e501603b 444 'where' => 'civicrm_membership.campaign_id',
c3fc2621 445 'export' => TRUE,
522a26c9 446 'table_name' => 'civicrm_membership',
447 'entity' => 'Membership',
448 'bao' => 'CRM_Member_BAO_Membership',
6a7e5e5d 449 'localizable' => 0,
e501603b 450 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
c3fc2621 451 'html' => [
e501603b 452 'type' => 'Select',
c3fc2621
CW
453 ],
454 'pseudoconstant' => [
e501603b
TO
455 'table' => 'civicrm_campaign',
456 'keyColumn' => 'id',
457 'labelColumn' => 'title',
c3fc2621
CW
458 ]
459 ],
460 ];
346aaaba 461 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 462 }
346aaaba 463 return Civi::$statics[__CLASS__]['fields'];
e501603b 464 }
c3fc2621 465
e501603b 466 /**
bd8e0b14 467 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
468 *
469 * @return array
bd8e0b14 470 * Array(string $name => string $uniqueName).
e501603b 471 */
c3fc2621 472 public static function &fieldKeys() {
bd8e0b14
TO
473 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
474 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 475 }
bd8e0b14 476 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 477 }
c3fc2621 478
e501603b
TO
479 /**
480 * Returns the names of this table
481 *
482 * @return string
483 */
c3fc2621 484 public static function getTableName() {
e501603b
TO
485 return self::$_tableName;
486 }
c3fc2621 487
e501603b
TO
488 /**
489 * Returns if this table needs to be logged
490 *
c3fc2621 491 * @return bool
e501603b 492 */
c3fc2621 493 public function getLog() {
e501603b
TO
494 return self::$_log;
495 }
c3fc2621 496
e501603b
TO
497 /**
498 * Returns the list of fields that can be imported
499 *
500 * @param bool $prefix
501 *
502 * @return array
503 */
c3fc2621
CW
504 public static function &import($prefix = FALSE) {
505 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, []);
60808919 506 return $r;
e501603b 507 }
c3fc2621 508
e501603b
TO
509 /**
510 * Returns the list of fields that can be exported
511 *
512 * @param bool $prefix
513 *
514 * @return array
515 */
c3fc2621
CW
516 public static function &export($prefix = FALSE) {
517 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, []);
60808919 518 return $r;
e501603b 519 }
c3fc2621 520
e7a6b91a
AS
521 /**
522 * Returns the list of indices
c3fc2621
CW
523 *
524 * @param bool $localize
525 *
526 * @return array
e7a6b91a
AS
527 */
528 public static function indices($localize = TRUE) {
c3fc2621
CW
529 $indices = [
530 'index_owner_membership_id' => [
e7a6b91a 531 'name' => 'index_owner_membership_id',
c3fc2621 532 'field' => [
e7a6b91a 533 0 => 'owner_membership_id',
c3fc2621
CW
534 ],
535 'localizable' => FALSE,
e7a6b91a 536 'sig' => 'civicrm_membership::0::owner_membership_id',
c3fc2621
CW
537 ],
538 ];
e7a6b91a
AS
539 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
540 }
c3fc2621 541
e501603b 542}