Fix metadata on member export
[civicrm-core.git] / CRM / Member / DAO / Membership.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC (c) 2004-2019
6 *
7 * Generated from xml/schema/CRM/Member/Membership.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:40f3b0813c1e13fab544ae1f8fa2ebb3)
10 */
11
12 /**
13 * Database access object for the Membership entity.
14 */
15 class CRM_Member_DAO_Membership extends CRM_Core_DAO {
16
17 /**
18 * Static instance to hold the table name.
19 *
20 * @var string
21 */
22 public static $_tableName = 'civicrm_membership';
23
24 /**
25 * Should CiviCRM log any modifications to this table in the civicrm_log table.
26 *
27 * @var bool
28 */
29 public static $_log = TRUE;
30
31 /**
32 * Membership Id
33 *
34 * @var int
35 */
36 public $id;
37
38 /**
39 * FK to Contact ID
40 *
41 * @var int
42 */
43 public $contact_id;
44
45 /**
46 * FK to Membership Type
47 *
48 * @var int
49 */
50 public $membership_type_id;
51
52 /**
53 * Beginning of initial membership period (member since...).
54 *
55 * @var date
56 */
57 public $join_date;
58
59 /**
60 * Beginning of current uninterrupted membership period.
61 *
62 * @var date
63 */
64 public $start_date;
65
66 /**
67 * Current membership period expire date.
68 *
69 * @var date
70 */
71 public $end_date;
72
73 /**
74 * @var string
75 */
76 public $source;
77
78 /**
79 * FK to Membership Status
80 *
81 * @var int
82 */
83 public $status_id;
84
85 /**
86 * 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.
87 *
88 * @var bool
89 */
90 public $is_override;
91
92 /**
93 * Then end date of membership status override if 'Override until selected date' override type is selected.
94 *
95 * @var date
96 */
97 public $status_override_end_date;
98
99 /**
100 * Optional FK to Parent Membership.
101 *
102 * @var int
103 */
104 public $owner_membership_id;
105
106 /**
107 * Maximum number of related memberships (membership_type override).
108 *
109 * @var int
110 */
111 public $max_related;
112
113 /**
114 * @var bool
115 */
116 public $is_test;
117
118 /**
119 * @var bool
120 */
121 public $is_pay_later;
122
123 /**
124 * 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.
125 *
126 * @var int
127 */
128 public $contribution_recur_id;
129
130 /**
131 * The campaign for which this membership is attached.
132 *
133 * @var int
134 */
135 public $campaign_id;
136
137 /**
138 * Class constructor.
139 */
140 public function __construct() {
141 $this->__table = 'civicrm_membership';
142 parent::__construct();
143 }
144
145 /**
146 * Returns foreign keys and entity references.
147 *
148 * @return array
149 * [CRM_Core_Reference_Interface]
150 */
151 public static function getReferenceColumns() {
152 if (!isset(Civi::$statics[__CLASS__]['links'])) {
153 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
154 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
155 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'membership_type_id', 'civicrm_membership_type', 'id');
156 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'status_id', 'civicrm_membership_status', 'id');
157 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'owner_membership_id', 'civicrm_membership', 'id');
158 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
159 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
160 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
161 }
162 return Civi::$statics[__CLASS__]['links'];
163 }
164
165 /**
166 * Returns all the column names of this table
167 *
168 * @return array
169 */
170 public static function &fields() {
171 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
172 Civi::$statics[__CLASS__]['fields'] = [
173 'membership_id' => [
174 'name' => 'id',
175 'type' => CRM_Utils_Type::T_INT,
176 'title' => ts('Membership ID'),
177 'description' => ts('Membership Id'),
178 'required' => TRUE,
179 'import' => TRUE,
180 'where' => 'civicrm_membership.id',
181 'headerPattern' => '/^(m(embership\s)?id)$/i',
182 'export' => TRUE,
183 'table_name' => 'civicrm_membership',
184 'entity' => 'Membership',
185 'bao' => 'CRM_Member_BAO_Membership',
186 'localizable' => 0,
187 ],
188 'membership_contact_id' => [
189 'name' => 'contact_id',
190 'type' => CRM_Utils_Type::T_INT,
191 'title' => ts('Contact ID'),
192 'description' => ts('FK to Contact ID'),
193 'required' => TRUE,
194 'import' => TRUE,
195 'where' => 'civicrm_membership.contact_id',
196 'headerPattern' => '/contact(.?id)?/i',
197 'dataPattern' => '/^\d+$/',
198 'export' => TRUE,
199 'table_name' => 'civicrm_membership',
200 'entity' => 'Membership',
201 'bao' => 'CRM_Member_BAO_Membership',
202 'localizable' => 0,
203 'FKClassName' => 'CRM_Contact_DAO_Contact',
204 'html' => [
205 'type' => 'EntityRef',
206 ],
207 ],
208 'membership_type_id' => [
209 'name' => 'membership_type_id',
210 'type' => CRM_Utils_Type::T_INT,
211 'title' => ts('Membership Type Id'),
212 'description' => ts('FK to Membership Type'),
213 'required' => TRUE,
214 'import' => TRUE,
215 'where' => 'civicrm_membership.membership_type_id',
216 'headerPattern' => '/^(m(embership\s)?type)$/i',
217 'export' => FALSE,
218 'table_name' => 'civicrm_membership',
219 'entity' => 'Membership',
220 'bao' => 'CRM_Member_BAO_Membership',
221 'localizable' => 0,
222 'FKClassName' => 'CRM_Member_DAO_MembershipType',
223 'html' => [
224 'type' => 'Select',
225 ],
226 'pseudoconstant' => [
227 'table' => 'civicrm_membership_type',
228 'keyColumn' => 'id',
229 'labelColumn' => 'name',
230 ],
231 ],
232 'join_date' => [
233 'name' => 'join_date',
234 'type' => CRM_Utils_Type::T_DATE,
235 'title' => ts('Member Since'),
236 'description' => ts('Beginning of initial membership period (member since...).'),
237 'import' => TRUE,
238 'where' => 'civicrm_membership.join_date',
239 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
240 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
241 'export' => TRUE,
242 'table_name' => 'civicrm_membership',
243 'entity' => 'Membership',
244 'bao' => 'CRM_Member_BAO_Membership',
245 'localizable' => 0,
246 'html' => [
247 'type' => 'Select Date',
248 'formatType' => 'activityDate',
249 ],
250 ],
251 'membership_start_date' => [
252 'name' => 'start_date',
253 'type' => CRM_Utils_Type::T_DATE,
254 'title' => ts('Membership Start Date'),
255 'description' => ts('Beginning of current uninterrupted membership period.'),
256 'import' => TRUE,
257 'where' => 'civicrm_membership.start_date',
258 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
259 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
260 'export' => TRUE,
261 'table_name' => 'civicrm_membership',
262 'entity' => 'Membership',
263 'bao' => 'CRM_Member_BAO_Membership',
264 'localizable' => 0,
265 'html' => [
266 'type' => 'Select Date',
267 'formatType' => 'activityDate',
268 ],
269 ],
270 'membership_end_date' => [
271 'name' => 'end_date',
272 'type' => CRM_Utils_Type::T_DATE,
273 'title' => ts('Membership Expiration Date'),
274 'description' => ts('Current membership period expire date.'),
275 'import' => TRUE,
276 'where' => 'civicrm_membership.end_date',
277 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
278 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
279 'export' => TRUE,
280 'table_name' => 'civicrm_membership',
281 'entity' => 'Membership',
282 'bao' => 'CRM_Member_BAO_Membership',
283 'localizable' => 0,
284 'html' => [
285 'type' => 'Select Date',
286 'formatType' => 'activityDate',
287 ],
288 ],
289 'membership_source' => [
290 'name' => 'source',
291 'type' => CRM_Utils_Type::T_STRING,
292 'title' => ts('Source'),
293 'maxlength' => 128,
294 'size' => CRM_Utils_Type::HUGE,
295 'import' => TRUE,
296 'where' => 'civicrm_membership.source',
297 'headerPattern' => '/^(member(ship?))?source$/i',
298 'export' => TRUE,
299 'table_name' => 'civicrm_membership',
300 'entity' => 'Membership',
301 'bao' => 'CRM_Member_BAO_Membership',
302 'localizable' => 0,
303 'html' => [
304 'type' => 'Text',
305 ],
306 ],
307 'status_id' => [
308 'name' => 'status_id',
309 'type' => CRM_Utils_Type::T_INT,
310 'title' => ts('Membership Status Id'),
311 'description' => ts('FK to Membership Status'),
312 'required' => TRUE,
313 'import' => TRUE,
314 'where' => 'civicrm_membership.status_id',
315 'headerPattern' => '/(member(ship|).)?(status)$/i',
316 'export' => FALSE,
317 'table_name' => 'civicrm_membership',
318 'entity' => 'Membership',
319 'bao' => 'CRM_Member_BAO_Membership',
320 'localizable' => 0,
321 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
322 'html' => [
323 'type' => 'Select',
324 ],
325 'pseudoconstant' => [
326 'table' => 'civicrm_membership_status',
327 'keyColumn' => 'id',
328 'labelColumn' => 'label',
329 ],
330 ],
331 'member_is_override' => [
332 'name' => 'is_override',
333 'type' => CRM_Utils_Type::T_BOOLEAN,
334 'title' => ts('Status Override'),
335 '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.'),
336 'import' => TRUE,
337 'where' => 'civicrm_membership.is_override',
338 'headerPattern' => '/override$/i',
339 'export' => TRUE,
340 'table_name' => 'civicrm_membership',
341 'entity' => 'Membership',
342 'bao' => 'CRM_Member_BAO_Membership',
343 'localizable' => 0,
344 'html' => [
345 'type' => 'CheckBox',
346 ],
347 ],
348 'status_override_end_date' => [
349 'name' => 'status_override_end_date',
350 'type' => CRM_Utils_Type::T_DATE,
351 'title' => ts('Status Override End Date'),
352 'description' => ts('Then end date of membership status override if \'Override until selected date\' override type is selected.'),
353 'import' => TRUE,
354 'where' => 'civicrm_membership.status_override_end_date',
355 'export' => TRUE,
356 'default' => 'NULL',
357 'table_name' => 'civicrm_membership',
358 'entity' => 'Membership',
359 'bao' => 'CRM_Member_BAO_Membership',
360 'localizable' => 0,
361 'html' => [
362 'type' => 'Select Date',
363 ],
364 ],
365 'owner_membership_id' => [
366 'name' => 'owner_membership_id',
367 'type' => CRM_Utils_Type::T_INT,
368 'title' => ts('Primary Member ID'),
369 'description' => ts('Optional FK to Parent Membership.'),
370 'where' => 'civicrm_membership.owner_membership_id',
371 'export' => TRUE,
372 'table_name' => 'civicrm_membership',
373 'entity' => 'Membership',
374 'bao' => 'CRM_Member_BAO_Membership',
375 'localizable' => 0,
376 'FKClassName' => 'CRM_Member_DAO_Membership',
377 ],
378 'max_related' => [
379 'name' => 'max_related',
380 'type' => CRM_Utils_Type::T_INT,
381 'title' => ts('Max Related'),
382 'description' => ts('Maximum number of related memberships (membership_type override).'),
383 'where' => 'civicrm_membership.max_related',
384 'export' => TRUE,
385 'table_name' => 'civicrm_membership',
386 'entity' => 'Membership',
387 'bao' => 'CRM_Member_BAO_Membership',
388 'localizable' => 0,
389 'html' => [
390 'type' => 'Text',
391 ],
392 ],
393 'member_is_test' => [
394 'name' => 'is_test',
395 'type' => CRM_Utils_Type::T_BOOLEAN,
396 'title' => ts('Test'),
397 'import' => TRUE,
398 'where' => 'civicrm_membership.is_test',
399 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
400 'export' => TRUE,
401 'default' => '0',
402 'table_name' => 'civicrm_membership',
403 'entity' => 'Membership',
404 'bao' => 'CRM_Member_BAO_Membership',
405 'localizable' => 0,
406 'html' => [
407 'type' => 'CheckBox',
408 ],
409 ],
410 'member_is_pay_later' => [
411 'name' => 'is_pay_later',
412 'type' => CRM_Utils_Type::T_BOOLEAN,
413 'title' => ts('Is Pay Later'),
414 'import' => TRUE,
415 'where' => 'civicrm_membership.is_pay_later',
416 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
417 'export' => TRUE,
418 'default' => '0',
419 'table_name' => 'civicrm_membership',
420 'entity' => 'Membership',
421 'bao' => 'CRM_Member_BAO_Membership',
422 'localizable' => 0,
423 'html' => [
424 'type' => 'CheckBox',
425 ],
426 ],
427 'membership_recur_id' => [
428 'name' => 'contribution_recur_id',
429 'type' => CRM_Utils_Type::T_INT,
430 'title' => ts('Membership Recurring Contribution'),
431 '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.'),
432 'where' => 'civicrm_membership.contribution_recur_id',
433 'export' => TRUE,
434 'table_name' => 'civicrm_membership',
435 'entity' => 'Membership',
436 'bao' => 'CRM_Member_BAO_Membership',
437 'localizable' => 0,
438 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
439 ],
440 'member_campaign_id' => [
441 'name' => 'campaign_id',
442 'type' => CRM_Utils_Type::T_INT,
443 'title' => ts('Campaign'),
444 'description' => ts('The campaign for which this membership is attached.'),
445 'import' => TRUE,
446 'where' => 'civicrm_membership.campaign_id',
447 'export' => TRUE,
448 'table_name' => 'civicrm_membership',
449 'entity' => 'Membership',
450 'bao' => 'CRM_Member_BAO_Membership',
451 'localizable' => 0,
452 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
453 'html' => [
454 'type' => 'Select',
455 ],
456 'pseudoconstant' => [
457 'table' => 'civicrm_campaign',
458 'keyColumn' => 'id',
459 'labelColumn' => 'title',
460 ],
461 ],
462 ];
463 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
464 }
465 return Civi::$statics[__CLASS__]['fields'];
466 }
467
468 /**
469 * Return a mapping from field-name to the corresponding key (as used in fields()).
470 *
471 * @return array
472 * Array(string $name => string $uniqueName).
473 */
474 public static function &fieldKeys() {
475 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
476 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
477 }
478 return Civi::$statics[__CLASS__]['fieldKeys'];
479 }
480
481 /**
482 * Returns the names of this table
483 *
484 * @return string
485 */
486 public static function getTableName() {
487 return self::$_tableName;
488 }
489
490 /**
491 * Returns if this table needs to be logged
492 *
493 * @return bool
494 */
495 public function getLog() {
496 return self::$_log;
497 }
498
499 /**
500 * Returns the list of fields that can be imported
501 *
502 * @param bool $prefix
503 *
504 * @return array
505 */
506 public static function &import($prefix = FALSE) {
507 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, []);
508 return $r;
509 }
510
511 /**
512 * Returns the list of fields that can be exported
513 *
514 * @param bool $prefix
515 *
516 * @return array
517 */
518 public static function &export($prefix = FALSE) {
519 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, []);
520 return $r;
521 }
522
523 /**
524 * Returns the list of indices
525 *
526 * @param bool $localize
527 *
528 * @return array
529 */
530 public static function indices($localize = TRUE) {
531 $indices = [
532 'index_owner_membership_id' => [
533 'name' => 'index_owner_membership_id',
534 'field' => [
535 0 => 'owner_membership_id',
536 ],
537 'localizable' => FALSE,
538 'sig' => 'civicrm_membership::0::owner_membership_id',
539 ],
540 ];
541 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
542 }
543
544 }