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