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