Merge pull request #21881 from mariav0/patch-19
[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:fd3bcddc97a226b449f26e3280ef2ace)
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 user-friendly description of this entity.
179 *
180 * @return string
181 */
182 public static function getEntityDescription() {
183 return ts('Records of contacts belonging to an organization\'s membership program.');
184 }
185
186 /**
187 * Returns foreign keys and entity references.
188 *
189 * @return array
190 * [CRM_Core_Reference_Interface]
191 */
192 public static function getReferenceColumns() {
193 if (!isset(Civi::$statics[__CLASS__]['links'])) {
194 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
195 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
196 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'membership_type_id', 'civicrm_membership_type', 'id');
197 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'status_id', 'civicrm_membership_status', 'id');
198 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'owner_membership_id', 'civicrm_membership', 'id');
199 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
200 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
201 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
202 }
203 return Civi::$statics[__CLASS__]['links'];
204 }
205
206 /**
207 * Returns all the column names of this table
208 *
209 * @return array
210 */
211 public static function &fields() {
212 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
213 Civi::$statics[__CLASS__]['fields'] = [
214 'membership_id' => [
215 'name' => 'id',
216 'type' => CRM_Utils_Type::T_INT,
217 'title' => ts('Membership ID'),
218 'description' => ts('Membership ID'),
219 'required' => TRUE,
220 'import' => TRUE,
221 'where' => 'civicrm_membership.id',
222 'headerPattern' => '/^(m(embership\s)?id)$/i',
223 'export' => TRUE,
224 'table_name' => 'civicrm_membership',
225 'entity' => 'Membership',
226 'bao' => 'CRM_Member_BAO_Membership',
227 'localizable' => 0,
228 'html' => [
229 'type' => 'Number',
230 ],
231 'readonly' => TRUE,
232 'add' => '1.5',
233 ],
234 'membership_contact_id' => [
235 'name' => 'contact_id',
236 'type' => CRM_Utils_Type::T_INT,
237 'title' => ts('Contact ID'),
238 'description' => ts('FK to Contact ID'),
239 'required' => TRUE,
240 'import' => TRUE,
241 'where' => 'civicrm_membership.contact_id',
242 'headerPattern' => '/contact(.?id)?/i',
243 'dataPattern' => '/^\d+$/',
244 'export' => TRUE,
245 'table_name' => 'civicrm_membership',
246 'entity' => 'Membership',
247 'bao' => 'CRM_Member_BAO_Membership',
248 'localizable' => 0,
249 'FKClassName' => 'CRM_Contact_DAO_Contact',
250 'html' => [
251 'type' => 'EntityRef',
252 'label' => ts("Contact"),
253 ],
254 'add' => '1.5',
255 ],
256 'membership_type_id' => [
257 'name' => 'membership_type_id',
258 'type' => CRM_Utils_Type::T_INT,
259 'title' => ts('Membership Type ID'),
260 'description' => ts('FK to Membership Type'),
261 'required' => TRUE,
262 'import' => TRUE,
263 'where' => 'civicrm_membership.membership_type_id',
264 'headerPattern' => '/^(m(embership\s)?type)$/i',
265 'export' => FALSE,
266 'table_name' => 'civicrm_membership',
267 'entity' => 'Membership',
268 'bao' => 'CRM_Member_BAO_Membership',
269 'localizable' => 0,
270 'FKClassName' => 'CRM_Member_DAO_MembershipType',
271 'html' => [
272 'type' => 'Select',
273 'label' => ts("Membership Type"),
274 ],
275 'pseudoconstant' => [
276 'table' => 'civicrm_membership_type',
277 'keyColumn' => 'id',
278 'labelColumn' => 'name',
279 ],
280 'add' => '1.5',
281 ],
282 'membership_join_date' => [
283 'name' => 'join_date',
284 'type' => CRM_Utils_Type::T_DATE,
285 'title' => ts('Member Since'),
286 'description' => ts('Beginning of initial membership period (member since...).'),
287 'import' => TRUE,
288 'where' => 'civicrm_membership.join_date',
289 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
290 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
291 'export' => TRUE,
292 'table_name' => 'civicrm_membership',
293 'entity' => 'Membership',
294 'bao' => 'CRM_Member_BAO_Membership',
295 'localizable' => 0,
296 'html' => [
297 'type' => 'Select Date',
298 'formatType' => 'activityDate',
299 ],
300 'add' => '1.5',
301 ],
302 'membership_start_date' => [
303 'name' => 'start_date',
304 'type' => CRM_Utils_Type::T_DATE,
305 'title' => ts('Membership Start Date'),
306 'description' => ts('Beginning of current uninterrupted membership period.'),
307 'import' => TRUE,
308 'where' => 'civicrm_membership.start_date',
309 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
310 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
311 'export' => TRUE,
312 'table_name' => 'civicrm_membership',
313 'entity' => 'Membership',
314 'bao' => 'CRM_Member_BAO_Membership',
315 'localizable' => 0,
316 'html' => [
317 'type' => 'Select Date',
318 'formatType' => 'activityDate',
319 ],
320 'add' => '1.5',
321 ],
322 'membership_end_date' => [
323 'name' => 'end_date',
324 'type' => CRM_Utils_Type::T_DATE,
325 'title' => ts('Membership Expiration Date'),
326 'description' => ts('Current membership period expire date.'),
327 'import' => TRUE,
328 'where' => 'civicrm_membership.end_date',
329 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
330 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
331 'export' => TRUE,
332 'table_name' => 'civicrm_membership',
333 'entity' => 'Membership',
334 'bao' => 'CRM_Member_BAO_Membership',
335 'localizable' => 0,
336 'html' => [
337 'type' => 'Select Date',
338 'formatType' => 'activityDate',
339 ],
340 'add' => '1.5',
341 ],
342 'membership_source' => [
343 'name' => 'source',
344 'type' => CRM_Utils_Type::T_STRING,
345 'title' => ts('Source'),
346 'maxlength' => 128,
347 'size' => CRM_Utils_Type::HUGE,
348 'import' => TRUE,
349 'where' => 'civicrm_membership.source',
350 'headerPattern' => '/^(member(ship?))?source$/i',
351 'export' => TRUE,
352 'table_name' => 'civicrm_membership',
353 'entity' => 'Membership',
354 'bao' => 'CRM_Member_BAO_Membership',
355 'localizable' => 0,
356 'html' => [
357 'type' => 'Text',
358 ],
359 'add' => '1.5',
360 ],
361 'status_id' => [
362 'name' => 'status_id',
363 'type' => CRM_Utils_Type::T_INT,
364 'title' => ts('Status ID'),
365 'description' => ts('FK to Membership Status'),
366 'required' => TRUE,
367 'import' => TRUE,
368 'where' => 'civicrm_membership.status_id',
369 'headerPattern' => '/(member(ship|).)?(status)$/i',
370 'export' => FALSE,
371 'table_name' => 'civicrm_membership',
372 'entity' => 'Membership',
373 'bao' => 'CRM_Member_BAO_Membership',
374 'localizable' => 0,
375 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
376 'html' => [
377 'type' => 'Select',
378 'label' => ts("Status"),
379 ],
380 'pseudoconstant' => [
381 'table' => 'civicrm_membership_status',
382 'keyColumn' => 'id',
383 'labelColumn' => 'label',
384 ],
385 'add' => '1.5',
386 ],
387 'member_is_override' => [
388 'name' => 'is_override',
389 'type' => CRM_Utils_Type::T_BOOLEAN,
390 'title' => ts('Status Override'),
391 '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.'),
392 'import' => TRUE,
393 'where' => 'civicrm_membership.is_override',
394 'headerPattern' => '/override$/i',
395 'export' => TRUE,
396 'table_name' => 'civicrm_membership',
397 'entity' => 'Membership',
398 'bao' => 'CRM_Member_BAO_Membership',
399 'localizable' => 0,
400 'html' => [
401 'type' => 'CheckBox',
402 ],
403 'add' => '1.5',
404 ],
405 'status_override_end_date' => [
406 'name' => 'status_override_end_date',
407 'type' => CRM_Utils_Type::T_DATE,
408 'title' => ts('Status Override End Date'),
409 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
410 'import' => TRUE,
411 'where' => 'civicrm_membership.status_override_end_date',
412 'export' => TRUE,
413 'default' => NULL,
414 'table_name' => 'civicrm_membership',
415 'entity' => 'Membership',
416 'bao' => 'CRM_Member_BAO_Membership',
417 'localizable' => 0,
418 'html' => [
419 'type' => 'Select Date',
420 'formatType' => 'activityDate',
421 ],
422 'add' => '4.7',
423 ],
424 'owner_membership_id' => [
425 'name' => 'owner_membership_id',
426 'type' => CRM_Utils_Type::T_INT,
427 'title' => ts('Primary Member ID'),
428 'description' => ts('Optional FK to Parent Membership.'),
429 'where' => 'civicrm_membership.owner_membership_id',
430 'export' => TRUE,
431 'table_name' => 'civicrm_membership',
432 'entity' => 'Membership',
433 'bao' => 'CRM_Member_BAO_Membership',
434 'localizable' => 0,
435 'FKClassName' => 'CRM_Member_DAO_Membership',
436 'html' => [
437 'label' => ts("Primary Member"),
438 ],
439 'add' => '1.7',
440 ],
441 'max_related' => [
442 'name' => 'max_related',
443 'type' => CRM_Utils_Type::T_INT,
444 'title' => ts('Max Related'),
445 'description' => ts('Maximum number of related memberships (membership_type override).'),
446 'where' => 'civicrm_membership.max_related',
447 'export' => TRUE,
448 'table_name' => 'civicrm_membership',
449 'entity' => 'Membership',
450 'bao' => 'CRM_Member_BAO_Membership',
451 'localizable' => 0,
452 'html' => [
453 'type' => 'Text',
454 'label' => ts("Maximum number of related memberships"),
455 ],
456 'add' => '4.3',
457 ],
458 'member_is_test' => [
459 'name' => 'is_test',
460 'type' => CRM_Utils_Type::T_BOOLEAN,
461 'title' => ts('Test'),
462 'import' => TRUE,
463 'where' => 'civicrm_membership.is_test',
464 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
465 'export' => TRUE,
466 'default' => '0',
467 'table_name' => 'civicrm_membership',
468 'entity' => 'Membership',
469 'bao' => 'CRM_Member_BAO_Membership',
470 'localizable' => 0,
471 'html' => [
472 'type' => 'CheckBox',
473 ],
474 'add' => NULL,
475 ],
476 'member_is_pay_later' => [
477 'name' => 'is_pay_later',
478 'type' => CRM_Utils_Type::T_BOOLEAN,
479 'title' => ts('Is Pay Later'),
480 'import' => TRUE,
481 'where' => 'civicrm_membership.is_pay_later',
482 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
483 'export' => TRUE,
484 'default' => '0',
485 'table_name' => 'civicrm_membership',
486 'entity' => 'Membership',
487 'bao' => 'CRM_Member_BAO_Membership',
488 'localizable' => 0,
489 'html' => [
490 'type' => 'CheckBox',
491 ],
492 'add' => '2.1',
493 ],
494 'membership_recur_id' => [
495 'name' => 'contribution_recur_id',
496 'type' => CRM_Utils_Type::T_INT,
497 'title' => ts('Recurring Contribution ID'),
498 '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.'),
499 'where' => 'civicrm_membership.contribution_recur_id',
500 'export' => TRUE,
501 'table_name' => 'civicrm_membership',
502 'entity' => 'Membership',
503 'bao' => 'CRM_Member_BAO_Membership',
504 'localizable' => 0,
505 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
506 'html' => [
507 'label' => ts("Recurring Contribution"),
508 ],
509 'add' => '3.3',
510 ],
511 'member_campaign_id' => [
512 'name' => 'campaign_id',
513 'type' => CRM_Utils_Type::T_INT,
514 'title' => ts('Campaign ID'),
515 'description' => ts('The campaign for which this membership is attached.'),
516 'import' => TRUE,
517 'where' => 'civicrm_membership.campaign_id',
518 'export' => TRUE,
519 'table_name' => 'civicrm_membership',
520 'entity' => 'Membership',
521 'bao' => 'CRM_Member_BAO_Membership',
522 'localizable' => 0,
523 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
524 'component' => 'CiviCampaign',
525 'html' => [
526 'type' => 'EntityRef',
527 'label' => ts("Campaign"),
528 ],
529 'pseudoconstant' => [
530 'table' => 'civicrm_campaign',
531 'keyColumn' => 'id',
532 'labelColumn' => 'title',
533 'prefetch' => 'FALSE',
534 ],
535 'add' => '3.4',
536 ],
537 ];
538 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
539 }
540 return Civi::$statics[__CLASS__]['fields'];
541 }
542
543 /**
544 * Return a mapping from field-name to the corresponding key (as used in fields()).
545 *
546 * @return array
547 * Array(string $name => string $uniqueName).
548 */
549 public static function &fieldKeys() {
550 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
551 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
552 }
553 return Civi::$statics[__CLASS__]['fieldKeys'];
554 }
555
556 /**
557 * Returns the names of this table
558 *
559 * @return string
560 */
561 public static function getTableName() {
562 return self::$_tableName;
563 }
564
565 /**
566 * Returns if this table needs to be logged
567 *
568 * @return bool
569 */
570 public function getLog() {
571 return self::$_log;
572 }
573
574 /**
575 * Returns the list of fields that can be imported
576 *
577 * @param bool $prefix
578 *
579 * @return array
580 */
581 public static function &import($prefix = FALSE) {
582 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, []);
583 return $r;
584 }
585
586 /**
587 * Returns the list of fields that can be exported
588 *
589 * @param bool $prefix
590 *
591 * @return array
592 */
593 public static function &export($prefix = FALSE) {
594 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, []);
595 return $r;
596 }
597
598 /**
599 * Returns the list of indices
600 *
601 * @param bool $localize
602 *
603 * @return array
604 */
605 public static function indices($localize = TRUE) {
606 $indices = [
607 'index_owner_membership_id' => [
608 'name' => 'index_owner_membership_id',
609 'field' => [
610 0 => 'owner_membership_id',
611 ],
612 'localizable' => FALSE,
613 'sig' => 'civicrm_membership::0::owner_membership_id',
614 ],
615 ];
616 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
617 }
618
619 }