Merge pull request #9411 from seamuslee001/CRM-19509
[civicrm-core.git] / CRM / Member / DAO / Membership.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27 /**
28 * @package CRM
29 * @copyright CiviCRM LLC (c) 2004-2017
30 *
31 * Generated from xml/schema/CRM/Member/Membership.xml
32 * DO NOT EDIT. Generated by CRM_Core_CodeGen
33 * (GenCodeChecksum:c9823a62881681e2126d92c19e85876f)
34 */
35 require_once 'CRM/Core/DAO.php';
36 require_once 'CRM/Utils/Type.php';
37 class CRM_Member_DAO_Membership extends CRM_Core_DAO {
38 /**
39 * static instance to hold the table name
40 *
41 * @var string
42 */
43 static $_tableName = 'civicrm_membership';
44 /**
45 * static value to see if we should log any modifications to
46 * this table in the civicrm_log table
47 *
48 * @var boolean
49 */
50 static $_log = true;
51 /**
52 * Membership Id
53 *
54 * @var int unsigned
55 */
56 public $id;
57 /**
58 * FK to Contact ID
59 *
60 * @var int unsigned
61 */
62 public $contact_id;
63 /**
64 * FK to Membership Type
65 *
66 * @var int unsigned
67 */
68 public $membership_type_id;
69 /**
70 * Beginning of initial membership period (member since...).
71 *
72 * @var date
73 */
74 public $join_date;
75 /**
76 * Beginning of current uninterrupted membership period.
77 *
78 * @var date
79 */
80 public $start_date;
81 /**
82 * Current membership period expire date.
83 *
84 * @var date
85 */
86 public $end_date;
87 /**
88 *
89 * @var string
90 */
91 public $source;
92 /**
93 * FK to Membership Status
94 *
95 * @var int unsigned
96 */
97 public $status_id;
98 /**
99 * 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.
100 *
101 * @var boolean
102 */
103 public $is_override;
104 /**
105 * Optional FK to Parent Membership.
106 *
107 * @var int unsigned
108 */
109 public $owner_membership_id;
110 /**
111 * Maximum number of related memberships (membership_type override).
112 *
113 * @var int
114 */
115 public $max_related;
116 /**
117 *
118 * @var boolean
119 */
120 public $is_test;
121 /**
122 *
123 * @var boolean
124 */
125 public $is_pay_later;
126 /**
127 * 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.
128 *
129 * @var int unsigned
130 */
131 public $contribution_recur_id;
132 /**
133 * The campaign for which this membership is attached.
134 *
135 * @var int unsigned
136 */
137 public $campaign_id;
138 /**
139 * class constructor
140 *
141 * @return civicrm_membership
142 */
143 function __construct() {
144 $this->__table = 'civicrm_membership';
145 parent::__construct();
146 }
147 /**
148 * Returns foreign keys and entity references
149 *
150 * @return array
151 * [CRM_Core_Reference_Interface]
152 */
153 static function getReferenceColumns() {
154 if (!isset(Civi::$statics[__CLASS__]['links'])) {
155 Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
156 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
157 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'membership_type_id', 'civicrm_membership_type', 'id');
158 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'status_id', 'civicrm_membership_status', 'id');
159 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'owner_membership_id', 'civicrm_membership', 'id');
160 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
161 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'campaign_id', 'civicrm_campaign', 'id');
162 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
163 }
164 return Civi::$statics[__CLASS__]['links'];
165 }
166 /**
167 * Returns all the column names of this table
168 *
169 * @return array
170 */
171 static function &fields() {
172 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
173 Civi::$statics[__CLASS__]['fields'] = array(
174 'membership_id' => array(
175 'name' => 'id',
176 'type' => CRM_Utils_Type::T_INT,
177 'title' => ts('Membership ID') ,
178 'description' => 'Membership Id',
179 'required' => true,
180 'import' => true,
181 'where' => 'civicrm_membership.id',
182 'headerPattern' => '/^(m(embership\s)?id)$/i',
183 'dataPattern' => '',
184 'export' => true,
185 ) ,
186 'membership_contact_id' => array(
187 'name' => 'contact_id',
188 'type' => CRM_Utils_Type::T_INT,
189 'title' => ts('Contact ID') ,
190 'description' => 'FK to Contact ID',
191 'required' => true,
192 'import' => true,
193 'where' => 'civicrm_membership.contact_id',
194 'headerPattern' => '/contact(.?id)?/i',
195 'dataPattern' => '/^\d+$/',
196 'export' => true,
197 'FKClassName' => 'CRM_Contact_DAO_Contact',
198 'html' => array(
199 'type' => 'EntityRef',
200 ) ,
201 ) ,
202 'membership_type_id' => array(
203 'name' => 'membership_type_id',
204 'type' => CRM_Utils_Type::T_INT,
205 'title' => ts('Membership Type Id') ,
206 'description' => 'FK to Membership Type',
207 'required' => true,
208 'import' => true,
209 'where' => 'civicrm_membership.membership_type_id',
210 'headerPattern' => '/^(m(embership\s)?type)$/i',
211 'dataPattern' => '',
212 'export' => false,
213 'FKClassName' => 'CRM_Member_DAO_MembershipType',
214 'html' => array(
215 'type' => 'Select',
216 ) ,
217 'pseudoconstant' => array(
218 'table' => 'civicrm_membership_type',
219 'keyColumn' => 'id',
220 'labelColumn' => 'name',
221 )
222 ) ,
223 'join_date' => array(
224 'name' => 'join_date',
225 'type' => CRM_Utils_Type::T_DATE,
226 'title' => ts('Member Since') ,
227 'description' => 'Beginning of initial membership period (member since...).',
228 'import' => true,
229 'where' => 'civicrm_membership.join_date',
230 'headerPattern' => '/^join|(j(oin\s)?date)$/i',
231 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
232 'export' => true,
233 'html' => array(
234 'type' => 'Select Date',
235 ) ,
236 ) ,
237 'membership_start_date' => array(
238 'name' => 'start_date',
239 'type' => CRM_Utils_Type::T_DATE,
240 'title' => ts('Membership Start Date') ,
241 'description' => 'Beginning of current uninterrupted membership period.',
242 'import' => true,
243 'where' => 'civicrm_membership.start_date',
244 'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
245 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
246 'export' => true,
247 'html' => array(
248 'type' => 'Select Date',
249 ) ,
250 ) ,
251 'membership_end_date' => array(
252 'name' => 'end_date',
253 'type' => CRM_Utils_Type::T_DATE,
254 'title' => ts('Membership Expiration Date') ,
255 'description' => 'Current membership period expire date.',
256 'import' => true,
257 'where' => 'civicrm_membership.end_date',
258 'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
259 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
260 'export' => true,
261 'html' => array(
262 'type' => 'Select Date',
263 ) ,
264 ) ,
265 'membership_source' => array(
266 'name' => 'source',
267 'type' => CRM_Utils_Type::T_STRING,
268 'title' => ts('Source') ,
269 'maxlength' => 128,
270 'size' => CRM_Utils_Type::HUGE,
271 'import' => true,
272 'where' => 'civicrm_membership.source',
273 'headerPattern' => '/^(member(ship?))?source$/i',
274 'dataPattern' => '',
275 'export' => true,
276 'html' => array(
277 'type' => 'Text',
278 ) ,
279 ) ,
280 'status_id' => array(
281 'name' => 'status_id',
282 'type' => CRM_Utils_Type::T_INT,
283 'title' => ts('Membership Status Id') ,
284 'description' => 'FK to Membership Status',
285 'required' => true,
286 'import' => true,
287 'where' => 'civicrm_membership.status_id',
288 'headerPattern' => '/(member(ship|).)?(status)$/i',
289 'dataPattern' => '',
290 'export' => false,
291 'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
292 'html' => array(
293 'type' => 'Select',
294 ) ,
295 'pseudoconstant' => array(
296 'table' => 'civicrm_membership_status',
297 'keyColumn' => 'id',
298 'labelColumn' => 'label',
299 )
300 ) ,
301 'is_override' => array(
302 'name' => 'is_override',
303 'type' => CRM_Utils_Type::T_BOOLEAN,
304 'title' => ts('Status Override') ,
305 '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.',
306 'import' => true,
307 'where' => 'civicrm_membership.is_override',
308 'headerPattern' => '/override$/i',
309 'dataPattern' => '',
310 'export' => true,
311 'html' => array(
312 'type' => 'CheckBox',
313 ) ,
314 ) ,
315 'owner_membership_id' => array(
316 'name' => 'owner_membership_id',
317 'type' => CRM_Utils_Type::T_INT,
318 'title' => ts('Primary Member ID') ,
319 'description' => 'Optional FK to Parent Membership.',
320 'export' => true,
321 'where' => 'civicrm_membership.owner_membership_id',
322 'headerPattern' => '',
323 'dataPattern' => '',
324 'FKClassName' => 'CRM_Member_DAO_Membership',
325 ) ,
326 'max_related' => array(
327 'name' => 'max_related',
328 'type' => CRM_Utils_Type::T_INT,
329 'title' => ts('Max Related') ,
330 'description' => 'Maximum number of related memberships (membership_type override).',
331 'html' => array(
332 'type' => 'Text',
333 ) ,
334 ) ,
335 'member_is_test' => array(
336 'name' => 'is_test',
337 'type' => CRM_Utils_Type::T_BOOLEAN,
338 'title' => ts('Test') ,
339 'import' => true,
340 'where' => 'civicrm_membership.is_test',
341 'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
342 'dataPattern' => '',
343 'export' => true,
344 'html' => array(
345 'type' => 'CheckBox',
346 ) ,
347 ) ,
348 'member_is_pay_later' => array(
349 'name' => 'is_pay_later',
350 'type' => CRM_Utils_Type::T_BOOLEAN,
351 'title' => ts('Is Pay Later') ,
352 'import' => true,
353 'where' => 'civicrm_membership.is_pay_later',
354 'headerPattern' => '/(is.)?(pay(.)?later)$/i',
355 'dataPattern' => '',
356 'export' => true,
357 'html' => array(
358 'type' => 'CheckBox',
359 ) ,
360 ) ,
361 'contribution_recur_id' => array(
362 'name' => 'contribution_recur_id',
363 'type' => CRM_Utils_Type::T_INT,
364 'title' => ts('Membership Recurring Contribution') ,
365 '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.',
366 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
367 ) ,
368 'member_campaign_id' => array(
369 'name' => 'campaign_id',
370 'type' => CRM_Utils_Type::T_INT,
371 'title' => ts('Campaign') ,
372 'description' => 'The campaign for which this membership is attached.',
373 'import' => true,
374 'where' => 'civicrm_membership.campaign_id',
375 'headerPattern' => '',
376 'dataPattern' => '',
377 'export' => true,
378 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
379 'html' => array(
380 'type' => 'Select',
381 ) ,
382 'pseudoconstant' => array(
383 'table' => 'civicrm_campaign',
384 'keyColumn' => 'id',
385 'labelColumn' => 'title',
386 )
387 ) ,
388 );
389 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
390 }
391 return Civi::$statics[__CLASS__]['fields'];
392 }
393 /**
394 * Return a mapping from field-name to the corresponding key (as used in fields()).
395 *
396 * @return array
397 * Array(string $name => string $uniqueName).
398 */
399 static function &fieldKeys() {
400 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
401 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
402 }
403 return Civi::$statics[__CLASS__]['fieldKeys'];
404 }
405 /**
406 * Returns the names of this table
407 *
408 * @return string
409 */
410 static function getTableName() {
411 return self::$_tableName;
412 }
413 /**
414 * Returns if this table needs to be logged
415 *
416 * @return boolean
417 */
418 function getLog() {
419 return self::$_log;
420 }
421 /**
422 * Returns the list of fields that can be imported
423 *
424 * @param bool $prefix
425 *
426 * @return array
427 */
428 static function &import($prefix = false) {
429 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, array());
430 return $r;
431 }
432 /**
433 * Returns the list of fields that can be exported
434 *
435 * @param bool $prefix
436 *
437 * @return array
438 */
439 static function &export($prefix = false) {
440 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, array());
441 return $r;
442 }
443 }