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:614dc19edb8e63eb4a8a4c3523454511)
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',
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'),
228 'where' => 'civicrm_membership.contact_id',
229 'headerPattern' => '/contact(.?id)?/i',
230 'dataPattern' => '/^\d+$/',
232 'table_name' => 'civicrm_membership',
233 'entity' => 'Membership',
234 'bao' => 'CRM_Member_BAO_Membership',
236 'FKClassName' => 'CRM_Contact_DAO_Contact',
238 'type' => 'EntityRef',
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'),
249 'where' => 'civicrm_membership.membership_type_id',
250 'headerPattern' => '/^(m(embership\s)?type)$/i',
252 'table_name' => 'civicrm_membership',
253 'entity' => 'Membership',
254 'bao' => 'CRM_Member_BAO_Membership',
256 'FKClassName' => 'CRM_Member_DAO_MembershipType',
259 'label' => ts("Membership Type"),
261 'pseudoconstant' => [
262 'table' => 'civicrm_membership_type',
264 'labelColumn' => 'name',
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...).'),
274 'where' => 'civicrm_membership.join_date',
275 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
276 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
278 'table_name' => 'civicrm_membership',
279 'entity' => 'Membership',
280 'bao' => 'CRM_Member_BAO_Membership',
283 'type' => 'Select Date',
284 'formatType' => 'activityDate',
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.'),
294 'where' => 'civicrm_membership.start_date',
295 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
296 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
298 'table_name' => 'civicrm_membership',
299 'entity' => 'Membership',
300 'bao' => 'CRM_Member_BAO_Membership',
303 'type' => 'Select Date',
304 'formatType' => 'activityDate',
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.'),
314 'where' => 'civicrm_membership.end_date',
315 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
316 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
318 'table_name' => 'civicrm_membership',
319 'entity' => 'Membership',
320 'bao' => 'CRM_Member_BAO_Membership',
323 'type' => 'Select Date',
324 'formatType' => 'activityDate',
328 'membership_source' => [
330 'type' => CRM_Utils_Type
::T_STRING
,
331 'title' => ts('Source'),
333 'size' => CRM_Utils_Type
::HUGE
,
335 'where' => 'civicrm_membership.source',
336 'headerPattern' => '/^(member(ship?))?source$/i',
338 'table_name' => 'civicrm_membership',
339 'entity' => 'Membership',
340 'bao' => 'CRM_Member_BAO_Membership',
348 'name' => 'status_id',
349 'type' => CRM_Utils_Type
::T_INT
,
350 'title' => ts('Membership Status Id'),
351 'description' => ts('FK to Membership Status'),
354 'where' => 'civicrm_membership.status_id',
355 'headerPattern' => '/(member(ship|).)?(status)$/i',
357 'table_name' => 'civicrm_membership',
358 'entity' => 'Membership',
359 'bao' => 'CRM_Member_BAO_Membership',
361 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
365 'pseudoconstant' => [
366 'table' => 'civicrm_membership_status',
368 'labelColumn' => 'label',
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.'),
378 'where' => 'civicrm_membership.is_override',
379 'headerPattern' => '/override$/i',
381 'table_name' => 'civicrm_membership',
382 'entity' => 'Membership',
383 'bao' => 'CRM_Member_BAO_Membership',
386 'type' => 'CheckBox',
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.'),
396 'where' => 'civicrm_membership.status_override_end_date',
399 'table_name' => 'civicrm_membership',
400 'entity' => 'Membership',
401 'bao' => 'CRM_Member_BAO_Membership',
404 'type' => 'Select Date',
405 'formatType' => 'activityDate',
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',
416 'table_name' => 'civicrm_membership',
417 'entity' => 'Membership',
418 'bao' => 'CRM_Member_BAO_Membership',
420 'FKClassName' => 'CRM_Member_DAO_Membership',
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',
430 'table_name' => 'civicrm_membership',
431 'entity' => 'Membership',
432 'bao' => 'CRM_Member_BAO_Membership',
439 'member_is_test' => [
441 'type' => CRM_Utils_Type
::T_BOOLEAN
,
442 'title' => ts('Test'),
444 'where' => 'civicrm_membership.is_test',
445 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
448 'table_name' => 'civicrm_membership',
449 'entity' => 'Membership',
450 'bao' => 'CRM_Member_BAO_Membership',
453 'type' => 'CheckBox',
457 'member_is_pay_later' => [
458 'name' => 'is_pay_later',
459 'type' => CRM_Utils_Type
::T_BOOLEAN
,
460 'title' => ts('Is Pay Later'),
462 'where' => 'civicrm_membership.is_pay_later',
463 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
466 'table_name' => 'civicrm_membership',
467 'entity' => 'Membership',
468 'bao' => 'CRM_Member_BAO_Membership',
471 'type' => 'CheckBox',
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',
482 'table_name' => 'civicrm_membership',
483 'entity' => 'Membership',
484 'bao' => 'CRM_Member_BAO_Membership',
486 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
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.'),
495 'where' => 'civicrm_membership.campaign_id',
497 'table_name' => 'civicrm_membership',
498 'entity' => 'Membership',
499 'bao' => 'CRM_Member_BAO_Membership',
501 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
508 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
510 return Civi
::$statics[__CLASS__
]['fields'];
514 * Return a mapping from field-name to the corresponding key (as used in fields()).
517 * Array(string $name => string $uniqueName).
519 public static function &fieldKeys() {
520 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
521 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
523 return Civi
::$statics[__CLASS__
]['fieldKeys'];
527 * Returns the names of this table
531 public static function getTableName() {
532 return self
::$_tableName;
536 * Returns if this table needs to be logged
540 public function getLog() {
545 * Returns the list of fields that can be imported
547 * @param bool $prefix
551 public static function &import($prefix = FALSE) {
552 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'membership', $prefix, []);
557 * Returns the list of fields that can be exported
559 * @param bool $prefix
563 public static function &export($prefix = FALSE) {
564 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'membership', $prefix, []);
569 * Returns the list of indices
571 * @param bool $localize
575 public static function indices($localize = TRUE) {
577 'index_owner_membership_id' => [
578 'name' => 'index_owner_membership_id',
580 0 => 'owner_membership_id',
582 'localizable' => FALSE,
583 'sig' => 'civicrm_membership::0::owner_membership_id',
586 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;