5 * @copyright CiviCRM LLC https://civicrm.org/licensing
7 * Generated from xml/schema/CRM/Member/Membership.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:1668d4d8a9f2e1686bf9f5b6ea1c55dc)
13 * Database access object for the Membership entity.
15 class CRM_Member_DAO_Membership
extends CRM_Core_DAO
{
16 const EXT
= 'civicrm';
17 const TABLE_ADDED
= '1.5';
18 const COMPONENT
= 'CiviMember';
21 * Static instance to hold the table name.
25 public static $_tableName = 'civicrm_membership';
28 * Icon associated with this entity.
32 public static $_icon = 'fa-id-badge';
35 * Should CiviCRM log any modifications to this table in the civicrm_log table.
39 public static $_log = TRUE;
42 * Paths for accessing this entity in the UI.
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]',
56 * @var int|string|null
57 * (SQL type: int unsigned)
58 * Note that values will be retrieved from the database as a string.
66 * (SQL type: int unsigned)
67 * Note that values will be retrieved from the database as a string.
72 * FK to Membership Type
75 * (SQL type: int unsigned)
76 * Note that values will be retrieved from the database as a string.
78 public $membership_type_id;
81 * Beginning of initial membership period (member since...).
85 * Note that values will be retrieved from the database as a string.
90 * Beginning of current uninterrupted membership period.
94 * Note that values will be retrieved from the database as a string.
99 * Current membership period expire date.
103 * Note that values will be retrieved from the database as a string.
109 * (SQL type: varchar(128))
110 * Note that values will be retrieved from the database as a string.
115 * FK to Membership Status
118 * (SQL type: int unsigned)
119 * Note that values will be retrieved from the database as a string.
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.
127 * (SQL type: tinyint)
128 * Note that values will be retrieved from the database as a string.
133 * Then end date of membership status override if 'Override until selected date' override type is selected.
137 * Note that values will be retrieved from the database as a string.
139 public $status_override_end_date;
142 * Optional FK to Parent Membership.
144 * @var int|string|null
145 * (SQL type: int unsigned)
146 * Note that values will be retrieved from the database as a string.
148 public $owner_membership_id;
151 * Maximum number of related memberships (membership_type override).
153 * @var int|string|null
155 * Note that values will be retrieved from the database as a string.
161 * (SQL type: tinyint)
162 * Note that values will be retrieved from the database as a string.
168 * (SQL type: tinyint)
169 * Note that values will be retrieved from the database as a string.
171 public $is_pay_later;
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.
176 * @var int|string|null
177 * (SQL type: int unsigned)
178 * Note that values will be retrieved from the database as a string.
180 public $contribution_recur_id;
183 * The campaign for which this membership is attached.
185 * @var int|string|null
186 * (SQL type: int unsigned)
187 * Note that values will be retrieved from the database as a string.
194 public function __construct() {
195 $this->__table
= 'civicrm_membership';
196 parent
::__construct();
200 * Returns localized title of this entity.
202 * @param bool $plural
203 * Whether to return the plural version of the title.
205 public static function getEntityTitle($plural = FALSE) {
206 return $plural ?
ts('Memberships') : ts('Membership');
210 * Returns user-friendly description of this entity.
214 public static function getEntityDescription() {
215 return ts('Records of contacts belonging to an organization\'s membership program.');
219 * Returns foreign keys and entity references.
222 * [CRM_Core_Reference_Interface]
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']);
235 return Civi
::$statics[__CLASS__
]['links'];
239 * Returns all the column names of this table
243 public static function &fields() {
244 if (!isset(Civi
::$statics[__CLASS__
]['fields'])) {
245 Civi
::$statics[__CLASS__
]['fields'] = [
248 'type' => CRM_Utils_Type
::T_INT
,
249 'title' => ts('Membership ID'),
250 'description' => ts('Membership ID'),
253 'where' => 'civicrm_membership.id',
254 'headerPattern' => '/^(m(embership\s)?id)$/i',
256 'table_name' => 'civicrm_membership',
257 'entity' => 'Membership',
258 'bao' => 'CRM_Member_BAO_Membership',
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'),
273 'where' => 'civicrm_membership.contact_id',
274 'headerPattern' => '/contact(.?id)?/i',
275 'dataPattern' => '/^\d+$/',
277 'table_name' => 'civicrm_membership',
278 'entity' => 'Membership',
279 'bao' => 'CRM_Member_BAO_Membership',
281 'FKClassName' => 'CRM_Contact_DAO_Contact',
283 'type' => 'EntityRef',
284 'label' => ts("Contact"),
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'),
295 'where' => 'civicrm_membership.membership_type_id',
296 'headerPattern' => '/^(m(embership\s)?type)$/i',
298 'table_name' => 'civicrm_membership',
299 'entity' => 'Membership',
300 'bao' => 'CRM_Member_BAO_Membership',
302 'FKClassName' => 'CRM_Member_DAO_MembershipType',
305 'label' => ts("Membership Type"),
307 'pseudoconstant' => [
308 'table' => 'civicrm_membership_type',
310 'labelColumn' => 'name',
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...).'),
320 'where' => 'civicrm_membership.join_date',
321 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
322 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
324 'table_name' => 'civicrm_membership',
325 'entity' => 'Membership',
326 'bao' => 'CRM_Member_BAO_Membership',
329 'type' => 'Select Date',
330 'formatType' => 'activityDate',
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.'),
340 'where' => 'civicrm_membership.start_date',
341 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
342 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
344 'table_name' => 'civicrm_membership',
345 'entity' => 'Membership',
346 'bao' => 'CRM_Member_BAO_Membership',
349 'type' => 'Select Date',
350 'formatType' => 'activityDate',
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.'),
360 'where' => 'civicrm_membership.end_date',
361 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
362 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
364 'table_name' => 'civicrm_membership',
365 'entity' => 'Membership',
366 'bao' => 'CRM_Member_BAO_Membership',
369 'type' => 'Select Date',
370 'formatType' => 'activityDate',
374 'membership_source' => [
376 'type' => CRM_Utils_Type
::T_STRING
,
377 'title' => ts('Source'),
379 'size' => CRM_Utils_Type
::HUGE
,
381 'where' => 'civicrm_membership.source',
382 'headerPattern' => '/^(member(ship?))?source$/i',
384 'table_name' => 'civicrm_membership',
385 'entity' => 'Membership',
386 'bao' => 'CRM_Member_BAO_Membership',
394 'name' => 'status_id',
395 'type' => CRM_Utils_Type
::T_INT
,
396 'title' => ts('Status ID'),
397 'description' => ts('FK to Membership Status'),
400 'where' => 'civicrm_membership.status_id',
401 'headerPattern' => '/(member(ship|).)?(status)$/i',
403 'table_name' => 'civicrm_membership',
404 'entity' => 'Membership',
405 'bao' => 'CRM_Member_BAO_Membership',
407 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
410 'label' => ts("Status"),
412 'pseudoconstant' => [
413 'table' => 'civicrm_membership_status',
415 'labelColumn' => 'label',
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.'),
426 'where' => 'civicrm_membership.is_override',
427 'headerPattern' => '/override$/i',
430 'table_name' => 'civicrm_membership',
431 'entity' => 'Membership',
432 'bao' => 'CRM_Member_BAO_Membership',
435 'type' => 'CheckBox',
439 'status_override_end_date' => [
440 'name' => 'status_override_end_date',
441 'type' => CRM_Utils_Type
::T_DATE
,
442 'title' => ts('Status Override End Date'),
443 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
445 'where' => 'civicrm_membership.status_override_end_date',
448 'table_name' => 'civicrm_membership',
449 'entity' => 'Membership',
450 'bao' => 'CRM_Member_BAO_Membership',
453 'type' => 'Select Date',
454 'formatType' => 'activityDate',
458 'owner_membership_id' => [
459 'name' => 'owner_membership_id',
460 'type' => CRM_Utils_Type
::T_INT
,
461 'title' => ts('Primary Member ID'),
462 'description' => ts('Optional FK to Parent Membership.'),
463 'where' => 'civicrm_membership.owner_membership_id',
465 'table_name' => 'civicrm_membership',
466 'entity' => 'Membership',
467 'bao' => 'CRM_Member_BAO_Membership',
469 'FKClassName' => 'CRM_Member_DAO_Membership',
471 'label' => ts("Primary Member"),
476 'name' => 'max_related',
477 'type' => CRM_Utils_Type
::T_INT
,
478 'title' => ts('Max Related'),
479 'description' => ts('Maximum number of related memberships (membership_type override).'),
480 'where' => 'civicrm_membership.max_related',
482 'table_name' => 'civicrm_membership',
483 'entity' => 'Membership',
484 'bao' => 'CRM_Member_BAO_Membership',
488 'label' => ts("Maximum number of related memberships"),
492 'member_is_test' => [
494 'type' => CRM_Utils_Type
::T_BOOLEAN
,
495 'title' => ts('Test'),
498 'where' => 'civicrm_membership.is_test',
499 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
502 'table_name' => 'civicrm_membership',
503 'entity' => 'Membership',
504 'bao' => 'CRM_Member_BAO_Membership',
507 'type' => 'CheckBox',
511 'member_is_pay_later' => [
512 'name' => 'is_pay_later',
513 'type' => CRM_Utils_Type
::T_BOOLEAN
,
514 'title' => ts('Is Pay Later'),
517 'where' => 'civicrm_membership.is_pay_later',
518 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
521 'table_name' => 'civicrm_membership',
522 'entity' => 'Membership',
523 'bao' => 'CRM_Member_BAO_Membership',
526 'type' => 'CheckBox',
530 'membership_recur_id' => [
531 'name' => 'contribution_recur_id',
532 'type' => CRM_Utils_Type
::T_INT
,
533 'title' => ts('Recurring Contribution ID'),
534 '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.'),
535 'where' => 'civicrm_membership.contribution_recur_id',
537 'table_name' => 'civicrm_membership',
538 'entity' => 'Membership',
539 'bao' => 'CRM_Member_BAO_Membership',
541 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
543 'label' => ts("Recurring Contribution"),
547 'member_campaign_id' => [
548 'name' => 'campaign_id',
549 'type' => CRM_Utils_Type
::T_INT
,
550 'title' => ts('Campaign ID'),
551 'description' => ts('The campaign for which this membership is attached.'),
553 'where' => 'civicrm_membership.campaign_id',
555 'table_name' => 'civicrm_membership',
556 'entity' => 'Membership',
557 'bao' => 'CRM_Member_BAO_Membership',
559 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
560 'component' => 'CiviCampaign',
562 'type' => 'EntityRef',
563 'label' => ts("Campaign"),
565 'pseudoconstant' => [
566 'table' => 'civicrm_campaign',
568 'labelColumn' => 'title',
569 'prefetch' => 'FALSE',
574 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
576 return Civi
::$statics[__CLASS__
]['fields'];
580 * Return a mapping from field-name to the corresponding key (as used in fields()).
583 * Array(string $name => string $uniqueName).
585 public static function &fieldKeys() {
586 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
587 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
589 return Civi
::$statics[__CLASS__
]['fieldKeys'];
593 * Returns the names of this table
597 public static function getTableName() {
598 return self
::$_tableName;
602 * Returns if this table needs to be logged
606 public function getLog() {
611 * Returns the list of fields that can be imported
613 * @param bool $prefix
617 public static function &import($prefix = FALSE) {
618 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'membership', $prefix, []);
623 * Returns the list of fields that can be exported
625 * @param bool $prefix
629 public static function &export($prefix = FALSE) {
630 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'membership', $prefix, []);
635 * Returns the list of indices
637 * @param bool $localize
641 public static function indices($localize = TRUE) {
643 'index_owner_membership_id' => [
644 'name' => 'index_owner_membership_id',
646 0 => 'owner_membership_id',
648 'localizable' => FALSE,
649 'sig' => 'civicrm_membership::0::owner_membership_id',
652 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;