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:e364568e0284363b3a9141823215c536)
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 user-friendly description of this entity.
182 public static function getEntityDescription() {
183 return ts('Records of contacts belonging to an organization\'s membership program.');
187 * Returns foreign keys and entity references.
190 * [CRM_Core_Reference_Interface]
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']);
203 return Civi
::$statics[__CLASS__
]['links'];
207 * Returns all the column names of this table
211 public static function &fields() {
212 if (!isset(Civi
::$statics[__CLASS__
]['fields'])) {
213 Civi
::$statics[__CLASS__
]['fields'] = [
216 'type' => CRM_Utils_Type
::T_INT
,
217 'title' => ts('Membership ID'),
218 'description' => ts('Membership ID'),
221 'where' => 'civicrm_membership.id',
222 'headerPattern' => '/^(m(embership\s)?id)$/i',
224 'table_name' => 'civicrm_membership',
225 'entity' => 'Membership',
226 'bao' => 'CRM_Member_BAO_Membership',
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'),
241 'where' => 'civicrm_membership.contact_id',
242 'headerPattern' => '/contact(.?id)?/i',
243 'dataPattern' => '/^\d+$/',
245 'table_name' => 'civicrm_membership',
246 'entity' => 'Membership',
247 'bao' => 'CRM_Member_BAO_Membership',
249 'FKClassName' => 'CRM_Contact_DAO_Contact',
251 'type' => 'EntityRef',
252 'label' => ts("Contact"),
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'),
263 'where' => 'civicrm_membership.membership_type_id',
264 'headerPattern' => '/^(m(embership\s)?type)$/i',
266 'table_name' => 'civicrm_membership',
267 'entity' => 'Membership',
268 'bao' => 'CRM_Member_BAO_Membership',
270 'FKClassName' => 'CRM_Member_DAO_MembershipType',
273 'label' => ts("Membership Type"),
275 'pseudoconstant' => [
276 'table' => 'civicrm_membership_type',
278 'labelColumn' => 'name',
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...).'),
288 'where' => 'civicrm_membership.join_date',
289 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
290 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
292 'table_name' => 'civicrm_membership',
293 'entity' => 'Membership',
294 'bao' => 'CRM_Member_BAO_Membership',
297 'type' => 'Select Date',
298 'formatType' => 'activityDate',
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.'),
308 'where' => 'civicrm_membership.start_date',
309 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
310 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
312 'table_name' => 'civicrm_membership',
313 'entity' => 'Membership',
314 'bao' => 'CRM_Member_BAO_Membership',
317 'type' => 'Select Date',
318 'formatType' => 'activityDate',
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.'),
328 'where' => 'civicrm_membership.end_date',
329 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
330 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
332 'table_name' => 'civicrm_membership',
333 'entity' => 'Membership',
334 'bao' => 'CRM_Member_BAO_Membership',
337 'type' => 'Select Date',
338 'formatType' => 'activityDate',
342 'membership_source' => [
344 'type' => CRM_Utils_Type
::T_STRING
,
345 'title' => ts('Source'),
347 'size' => CRM_Utils_Type
::HUGE
,
349 'where' => 'civicrm_membership.source',
350 'headerPattern' => '/^(member(ship?))?source$/i',
352 'table_name' => 'civicrm_membership',
353 'entity' => 'Membership',
354 'bao' => 'CRM_Member_BAO_Membership',
362 'name' => 'status_id',
363 'type' => CRM_Utils_Type
::T_INT
,
364 'title' => ts('Status ID'),
365 'description' => ts('FK to Membership Status'),
368 'where' => 'civicrm_membership.status_id',
369 'headerPattern' => '/(member(ship|).)?(status)$/i',
371 'table_name' => 'civicrm_membership',
372 'entity' => 'Membership',
373 'bao' => 'CRM_Member_BAO_Membership',
375 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
378 'label' => ts("Status"),
380 'pseudoconstant' => [
381 'table' => 'civicrm_membership_status',
383 'labelColumn' => 'label',
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.'),
393 'where' => 'civicrm_membership.is_override',
394 'headerPattern' => '/override$/i',
396 'table_name' => 'civicrm_membership',
397 'entity' => 'Membership',
398 'bao' => 'CRM_Member_BAO_Membership',
401 'type' => 'CheckBox',
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.'),
411 'where' => 'civicrm_membership.status_override_end_date',
414 'table_name' => 'civicrm_membership',
415 'entity' => 'Membership',
416 'bao' => 'CRM_Member_BAO_Membership',
419 'type' => 'Select Date',
420 'formatType' => 'activityDate',
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',
431 'table_name' => 'civicrm_membership',
432 'entity' => 'Membership',
433 'bao' => 'CRM_Member_BAO_Membership',
435 'FKClassName' => 'CRM_Member_DAO_Membership',
437 'label' => ts("Primary Member"),
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',
448 'table_name' => 'civicrm_membership',
449 'entity' => 'Membership',
450 'bao' => 'CRM_Member_BAO_Membership',
454 'label' => ts("Maximum number of related memberships"),
458 'member_is_test' => [
460 'type' => CRM_Utils_Type
::T_BOOLEAN
,
461 'title' => ts('Test'),
463 'where' => 'civicrm_membership.is_test',
464 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
467 'table_name' => 'civicrm_membership',
468 'entity' => 'Membership',
469 'bao' => 'CRM_Member_BAO_Membership',
472 'type' => 'CheckBox',
476 'member_is_pay_later' => [
477 'name' => 'is_pay_later',
478 'type' => CRM_Utils_Type
::T_BOOLEAN
,
479 'title' => ts('Is Pay Later'),
481 'where' => 'civicrm_membership.is_pay_later',
482 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
485 'table_name' => 'civicrm_membership',
486 'entity' => 'Membership',
487 'bao' => 'CRM_Member_BAO_Membership',
490 'type' => 'CheckBox',
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',
501 'table_name' => 'civicrm_membership',
502 'entity' => 'Membership',
503 'bao' => 'CRM_Member_BAO_Membership',
505 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
507 'label' => ts("Recurring Contribution"),
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.'),
517 'where' => 'civicrm_membership.campaign_id',
519 'table_name' => 'civicrm_membership',
520 'entity' => 'Membership',
521 'bao' => 'CRM_Member_BAO_Membership',
523 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
524 'component' => 'CiviCampaign',
526 'type' => 'EntityRef',
527 'label' => ts("Campaign"),
532 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
534 return Civi
::$statics[__CLASS__
]['fields'];
538 * Return a mapping from field-name to the corresponding key (as used in fields()).
541 * Array(string $name => string $uniqueName).
543 public static function &fieldKeys() {
544 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
545 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
547 return Civi
::$statics[__CLASS__
]['fieldKeys'];
551 * Returns the names of this table
555 public static function getTableName() {
556 return self
::$_tableName;
560 * Returns if this table needs to be logged
564 public function getLog() {
569 * Returns the list of fields that can be imported
571 * @param bool $prefix
575 public static function &import($prefix = FALSE) {
576 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'membership', $prefix, []);
581 * Returns the list of fields that can be exported
583 * @param bool $prefix
587 public static function &export($prefix = FALSE) {
588 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'membership', $prefix, []);
593 * Returns the list of indices
595 * @param bool $localize
599 public static function indices($localize = TRUE) {
601 'index_owner_membership_id' => [
602 'name' => 'index_owner_membership_id',
604 0 => 'owner_membership_id',
606 'localizable' => FALSE,
607 'sig' => 'civicrm_membership::0::owner_membership_id',
610 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;