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:dc1ce9eef7433fb191d837f800a9f745)
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]',
68 * FK to Membership Type
72 public $membership_type_id;
75 * Beginning of initial membership period (member since...).
82 * Beginning of current uninterrupted membership period.
89 * Current membership period expire date.
101 * FK to Membership Status
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.
115 * Then end date of membership status override if 'Override until selected date' override type is selected.
119 public $status_override_end_date;
122 * Optional FK to Parent Membership.
126 public $owner_membership_id;
129 * Maximum number of related memberships (membership_type override).
143 public $is_pay_later;
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.
150 public $contribution_recur_id;
153 * The campaign for which this membership is attached.
162 public function __construct() {
163 $this->__table
= 'civicrm_membership';
164 parent
::__construct();
168 * Returns localized title of this entity.
170 * @param bool $plural
171 * Whether to return the plural version of the title.
173 public static function getEntityTitle($plural = FALSE) {
174 return $plural ?
ts('Memberships') : ts('Membership');
178 * Returns foreign keys and entity references.
181 * [CRM_Core_Reference_Interface]
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']);
194 return Civi
::$statics[__CLASS__
]['links'];
198 * Returns all the column names of this table
202 public static function &fields() {
203 if (!isset(Civi
::$statics[__CLASS__
]['fields'])) {
204 Civi
::$statics[__CLASS__
]['fields'] = [
207 'type' => CRM_Utils_Type
::T_INT
,
208 'title' => ts('Membership ID'),
209 'description' => ts('Membership ID'),
212 'where' => 'civicrm_membership.id',
213 'headerPattern' => '/^(m(embership\s)?id)$/i',
215 'table_name' => 'civicrm_membership',
216 'entity' => 'Membership',
217 'bao' => 'CRM_Member_BAO_Membership',
225 'membership_contact_id' => [
226 'name' => 'contact_id',
227 'type' => CRM_Utils_Type
::T_INT
,
228 'title' => ts('Contact ID'),
229 'description' => ts('FK to Contact ID'),
232 'where' => 'civicrm_membership.contact_id',
233 'headerPattern' => '/contact(.?id)?/i',
234 'dataPattern' => '/^\d+$/',
236 'table_name' => 'civicrm_membership',
237 'entity' => 'Membership',
238 'bao' => 'CRM_Member_BAO_Membership',
240 'FKClassName' => 'CRM_Contact_DAO_Contact',
242 'type' => 'EntityRef',
243 'label' => ts("Contact"),
247 'membership_type_id' => [
248 'name' => 'membership_type_id',
249 'type' => CRM_Utils_Type
::T_INT
,
250 'title' => ts('Membership Type ID'),
251 'description' => ts('FK to Membership Type'),
254 'where' => 'civicrm_membership.membership_type_id',
255 'headerPattern' => '/^(m(embership\s)?type)$/i',
257 'table_name' => 'civicrm_membership',
258 'entity' => 'Membership',
259 'bao' => 'CRM_Member_BAO_Membership',
261 'FKClassName' => 'CRM_Member_DAO_MembershipType',
264 'label' => ts("Membership Type"),
266 'pseudoconstant' => [
267 'table' => 'civicrm_membership_type',
269 'labelColumn' => 'name',
273 'membership_join_date' => [
274 'name' => 'join_date',
275 'type' => CRM_Utils_Type
::T_DATE
,
276 'title' => ts('Member Since'),
277 'description' => ts('Beginning of initial membership period (member since...).'),
279 'where' => 'civicrm_membership.join_date',
280 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
281 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
283 'table_name' => 'civicrm_membership',
284 'entity' => 'Membership',
285 'bao' => 'CRM_Member_BAO_Membership',
288 'type' => 'Select Date',
289 'formatType' => 'activityDate',
293 'membership_start_date' => [
294 'name' => 'start_date',
295 'type' => CRM_Utils_Type
::T_DATE
,
296 'title' => ts('Membership Start Date'),
297 'description' => ts('Beginning of current uninterrupted membership period.'),
299 'where' => 'civicrm_membership.start_date',
300 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
301 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
303 'table_name' => 'civicrm_membership',
304 'entity' => 'Membership',
305 'bao' => 'CRM_Member_BAO_Membership',
308 'type' => 'Select Date',
309 'formatType' => 'activityDate',
313 'membership_end_date' => [
314 'name' => 'end_date',
315 'type' => CRM_Utils_Type
::T_DATE
,
316 'title' => ts('Membership Expiration Date'),
317 'description' => ts('Current membership period expire date.'),
319 'where' => 'civicrm_membership.end_date',
320 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
321 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
323 'table_name' => 'civicrm_membership',
324 'entity' => 'Membership',
325 'bao' => 'CRM_Member_BAO_Membership',
328 'type' => 'Select Date',
329 'formatType' => 'activityDate',
333 'membership_source' => [
335 'type' => CRM_Utils_Type
::T_STRING
,
336 'title' => ts('Source'),
338 'size' => CRM_Utils_Type
::HUGE
,
340 'where' => 'civicrm_membership.source',
341 'headerPattern' => '/^(member(ship?))?source$/i',
343 'table_name' => 'civicrm_membership',
344 'entity' => 'Membership',
345 'bao' => 'CRM_Member_BAO_Membership',
353 'name' => 'status_id',
354 'type' => CRM_Utils_Type
::T_INT
,
355 'title' => ts('Status ID'),
356 'description' => ts('FK to Membership Status'),
359 'where' => 'civicrm_membership.status_id',
360 'headerPattern' => '/(member(ship|).)?(status)$/i',
362 'table_name' => 'civicrm_membership',
363 'entity' => 'Membership',
364 'bao' => 'CRM_Member_BAO_Membership',
366 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
369 'label' => ts("Status"),
371 'pseudoconstant' => [
372 'table' => 'civicrm_membership_status',
374 'labelColumn' => 'label',
378 'member_is_override' => [
379 'name' => 'is_override',
380 'type' => CRM_Utils_Type
::T_BOOLEAN
,
381 'title' => ts('Status Override'),
382 '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.'),
384 'where' => 'civicrm_membership.is_override',
385 'headerPattern' => '/override$/i',
387 'table_name' => 'civicrm_membership',
388 'entity' => 'Membership',
389 'bao' => 'CRM_Member_BAO_Membership',
392 'type' => 'CheckBox',
396 'status_override_end_date' => [
397 'name' => 'status_override_end_date',
398 'type' => CRM_Utils_Type
::T_DATE
,
399 'title' => ts('Status Override End Date'),
400 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
402 'where' => 'civicrm_membership.status_override_end_date',
405 'table_name' => 'civicrm_membership',
406 'entity' => 'Membership',
407 'bao' => 'CRM_Member_BAO_Membership',
410 'type' => 'Select Date',
411 'formatType' => 'activityDate',
415 'owner_membership_id' => [
416 'name' => 'owner_membership_id',
417 'type' => CRM_Utils_Type
::T_INT
,
418 'title' => ts('Primary Member ID'),
419 'description' => ts('Optional FK to Parent Membership.'),
420 'where' => 'civicrm_membership.owner_membership_id',
422 'table_name' => 'civicrm_membership',
423 'entity' => 'Membership',
424 'bao' => 'CRM_Member_BAO_Membership',
426 'FKClassName' => 'CRM_Member_DAO_Membership',
428 'label' => ts("Primary Member"),
433 'name' => 'max_related',
434 'type' => CRM_Utils_Type
::T_INT
,
435 'title' => ts('Max Related'),
436 'description' => ts('Maximum number of related memberships (membership_type override).'),
437 'where' => 'civicrm_membership.max_related',
439 'table_name' => 'civicrm_membership',
440 'entity' => 'Membership',
441 'bao' => 'CRM_Member_BAO_Membership',
445 'label' => ts("Maximum number of related memberships"),
449 'member_is_test' => [
451 'type' => CRM_Utils_Type
::T_BOOLEAN
,
452 'title' => ts('Test'),
454 'where' => 'civicrm_membership.is_test',
455 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
458 'table_name' => 'civicrm_membership',
459 'entity' => 'Membership',
460 'bao' => 'CRM_Member_BAO_Membership',
463 'type' => 'CheckBox',
467 'member_is_pay_later' => [
468 'name' => 'is_pay_later',
469 'type' => CRM_Utils_Type
::T_BOOLEAN
,
470 'title' => ts('Is Pay Later'),
472 'where' => 'civicrm_membership.is_pay_later',
473 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
476 'table_name' => 'civicrm_membership',
477 'entity' => 'Membership',
478 'bao' => 'CRM_Member_BAO_Membership',
481 'type' => 'CheckBox',
485 'membership_recur_id' => [
486 'name' => 'contribution_recur_id',
487 'type' => CRM_Utils_Type
::T_INT
,
488 'title' => ts('Recurring Contribution ID'),
489 '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.'),
490 'where' => 'civicrm_membership.contribution_recur_id',
492 'table_name' => 'civicrm_membership',
493 'entity' => 'Membership',
494 'bao' => 'CRM_Member_BAO_Membership',
496 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
498 'label' => ts("Recurring Contribution"),
502 'member_campaign_id' => [
503 'name' => 'campaign_id',
504 'type' => CRM_Utils_Type
::T_INT
,
505 'title' => ts('Campaign ID'),
506 'description' => ts('The campaign for which this membership is attached.'),
508 'where' => 'civicrm_membership.campaign_id',
510 'table_name' => 'civicrm_membership',
511 'entity' => 'Membership',
512 'bao' => 'CRM_Member_BAO_Membership',
514 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
515 'component' => 'CiviCampaign',
517 'type' => 'EntityRef',
518 'label' => ts("Campaign"),
523 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
525 return Civi
::$statics[__CLASS__
]['fields'];
529 * Return a mapping from field-name to the corresponding key (as used in fields()).
532 * Array(string $name => string $uniqueName).
534 public static function &fieldKeys() {
535 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
536 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
538 return Civi
::$statics[__CLASS__
]['fieldKeys'];
542 * Returns the names of this table
546 public static function getTableName() {
547 return self
::$_tableName;
551 * Returns if this table needs to be logged
555 public function getLog() {
560 * Returns the list of fields that can be imported
562 * @param bool $prefix
566 public static function &import($prefix = FALSE) {
567 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'membership', $prefix, []);
572 * Returns the list of fields that can be exported
574 * @param bool $prefix
578 public static function &export($prefix = FALSE) {
579 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'membership', $prefix, []);
584 * Returns the list of indices
586 * @param bool $localize
590 public static function indices($localize = TRUE) {
592 'index_owner_membership_id' => [
593 'name' => 'index_owner_membership_id',
595 0 => 'owner_membership_id',
597 'localizable' => FALSE,
598 'sig' => 'civicrm_membership::0::owner_membership_id',
601 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;