xml/templates/dao.tpl - Centralize export() / import() logic
[civicrm-core.git] / CRM / Price / DAO / LineItem.php
CommitLineData
e501603b
TO
1<?php
2/*
3+--------------------------------------------------------------------+
4| CiviCRM version 4.7 |
5+--------------------------------------------------------------------+
6| Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
30 *
31 * Generated from xml/schema/CRM/Price/LineItem.xml
32 * DO NOT EDIT. Generated by CRM_Core_CodeGen
437fafcf 33 * (GenCodeChecksum:5a4cae4554717aae5dd6af5572acd572)
e501603b
TO
34 */
35require_once 'CRM/Core/DAO.php';
36require_once 'CRM/Utils/Type.php';
37class CRM_Price_DAO_LineItem extends CRM_Core_DAO {
38 /**
39 * static instance to hold the table name
40 *
41 * @var string
42 */
43 static $_tableName = 'civicrm_line_item';
44 /**
45 * static instance to hold the field values
46 *
47 * @var array
48 */
49 static $_fields = null;
50 /**
51 * static instance to hold the keys used in $_fields for each field.
52 *
53 * @var array
54 */
55 static $_fieldKeys = null;
56 /**
57 * static instance to hold the FK relationships
58 *
59 * @var string
60 */
61 static $_links = null;
62 /**
63 * static instance to hold the values that can
64 * be imported
65 *
66 * @var array
67 */
68 static $_import = null;
69 /**
70 * static instance to hold the values that can
71 * be exported
72 *
73 * @var array
74 */
75 static $_export = null;
76 /**
77 * static value to see if we should log any modifications to
78 * this table in the civicrm_log table
79 *
80 * @var boolean
81 */
82 static $_log = true;
83 /**
84 * Line Item
85 *
86 * @var int unsigned
87 */
88 public $id;
89 /**
90 * table which has the transaction
91 *
92 * @var string
93 */
94 public $entity_table;
95 /**
96 * entry in table
97 *
98 * @var int unsigned
99 */
100 public $entity_id;
101 /**
102 * FK to civicrm_contribution
103 *
104 * @var int unsigned
105 */
106 public $contribution_id;
107 /**
108 * FK to civicrm_price_field
109 *
110 * @var int unsigned
111 */
112 public $price_field_id;
113 /**
114 * descriptive label for item - from price_field_value.label
115 *
116 * @var string
117 */
118 public $label;
119 /**
120 * How many items ordered
121 *
122 * @var float
123 */
124 public $qty;
125 /**
126 * price of each item
127 *
128 * @var float
129 */
130 public $unit_price;
131 /**
132 * qty * unit_price
133 *
134 * @var float
135 */
136 public $line_total;
137 /**
138 * Participant count for field
139 *
140 * @var int unsigned
141 */
142 public $participant_count;
143 /**
144 * FK to civicrm_price_field_value
145 *
146 * @var int unsigned
147 */
148 public $price_field_value_id;
149 /**
150 * FK to Financial Type.
151 *
152 * @var int unsigned
153 */
154 public $financial_type_id;
155 /**
156 * Tax-deductible portion of the amount
157 *
158 * @var float
159 */
160 public $deductible_amount;
161 /**
162 * tax of each item
163 *
164 * @var float
165 */
166 public $tax_amount;
167 /**
168 * class constructor
169 *
170 * @return civicrm_line_item
171 */
172 function __construct() {
173 $this->__table = 'civicrm_line_item';
174 parent::__construct();
175 }
176 /**
177 * Returns foreign keys and entity references
178 *
179 * @return array
180 * [CRM_Core_Reference_Interface]
181 */
182 static function getReferenceColumns() {
183 if (!self::$_links) {
184 self::$_links = static ::createReferenceColumns(__CLASS__);
185 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'contribution_id', 'civicrm_contribution', 'id');
186 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'price_field_id', 'civicrm_price_field', 'id');
187 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'price_field_value_id', 'civicrm_price_field_value', 'id');
188 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_type_id', 'civicrm_financial_type', 'id');
189 self::$_links[] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
190 }
191 return self::$_links;
192 }
193 /**
194 * Returns all the column names of this table
195 *
196 * @return array
197 */
198 static function &fields() {
199 if (!(self::$_fields)) {
200 self::$_fields = array(
201 'id' => array(
202 'name' => 'id',
203 'type' => CRM_Utils_Type::T_INT,
204 'title' => ts('Line Item ID') ,
205 'description' => 'Line Item',
206 'required' => true,
207 ) ,
208 'entity_table' => array(
209 'name' => 'entity_table',
210 'type' => CRM_Utils_Type::T_STRING,
211 'title' => ts('Line Item Entity Type') ,
212 'description' => 'table which has the transaction',
213 'required' => true,
214 'maxlength' => 64,
215 'size' => CRM_Utils_Type::BIG,
216 ) ,
217 'entity_id' => array(
218 'name' => 'entity_id',
219 'type' => CRM_Utils_Type::T_INT,
220 'title' => ts('Line Item Entity') ,
221 'description' => 'entry in table',
222 'required' => true,
223 ) ,
224 'contribution_id' => array(
225 'name' => 'contribution_id',
226 'type' => CRM_Utils_Type::T_INT,
227 'title' => ts('Line Item Contribution') ,
228 'description' => 'FK to civicrm_contribution',
229 'FKClassName' => 'CRM_Contribute_DAO_Contribution',
230 ) ,
231 'price_field_id' => array(
232 'name' => 'price_field_id',
233 'type' => CRM_Utils_Type::T_INT,
234 'title' => ts('Line Item Price Field') ,
235 'description' => 'FK to civicrm_price_field',
236 'FKClassName' => 'CRM_Price_DAO_PriceField',
237 ) ,
238 'label' => array(
239 'name' => 'label',
240 'type' => CRM_Utils_Type::T_STRING,
241 'title' => ts('Line Item Label') ,
242 'description' => 'descriptive label for item - from price_field_value.label',
243 'maxlength' => 255,
244 'size' => CRM_Utils_Type::HUGE,
245 'default' => 'NULL',
246 'html' => array(
247 'type' => 'Text',
248 ) ,
249 ) ,
250 'qty' => array(
251 'name' => 'qty',
252 'type' => CRM_Utils_Type::T_MONEY,
253 'title' => ts('Line Item Quantity') ,
254 'description' => 'How many items ordered',
255 'required' => true,
256 'precision' => array(
257 20,
258 2
259 ) ,
260 'html' => array(
261 'type' => 'Text',
262 ) ,
263 ) ,
264 'unit_price' => array(
265 'name' => 'unit_price',
266 'type' => CRM_Utils_Type::T_MONEY,
267 'title' => ts('Unit Price') ,
268 'description' => 'price of each item',
269 'required' => true,
270 'precision' => array(
271 20,
272 2
273 ) ,
274 'html' => array(
275 'type' => 'Text',
276 ) ,
277 ) ,
278 'line_total' => array(
279 'name' => 'line_total',
280 'type' => CRM_Utils_Type::T_MONEY,
281 'title' => ts('Line Item Total') ,
282 'description' => 'qty * unit_price',
283 'required' => true,
284 'precision' => array(
285 20,
286 2
287 ) ,
288 ) ,
289 'participant_count' => array(
290 'name' => 'participant_count',
291 'type' => CRM_Utils_Type::T_INT,
292 'title' => ts('Line Item Participant Count') ,
293 'description' => 'Participant count for field',
294 'default' => 'NULL',
295 'html' => array(
296 'type' => 'Text',
297 ) ,
298 ) ,
299 'price_field_value_id' => array(
300 'name' => 'price_field_value_id',
301 'type' => CRM_Utils_Type::T_INT,
302 'title' => ts('Line Item Option') ,
303 'description' => 'FK to civicrm_price_field_value',
304 'default' => 'NULL',
305 'FKClassName' => 'CRM_Price_DAO_PriceFieldValue',
306 ) ,
307 'financial_type_id' => array(
308 'name' => 'financial_type_id',
309 'type' => CRM_Utils_Type::T_INT,
310 'title' => ts('Financial Type') ,
311 'description' => 'FK to Financial Type.',
312 'default' => 'NULL',
313 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
314 'html' => array(
315 'type' => 'Select',
316 ) ,
317 'pseudoconstant' => array(
318 'table' => 'civicrm_financial_type',
319 'keyColumn' => 'id',
320 'labelColumn' => 'name',
321 )
322 ) ,
323 'deductible_amount' => array(
324 'name' => 'deductible_amount',
325 'type' => CRM_Utils_Type::T_MONEY,
326 'title' => ts('Deductible Amount') ,
327 'description' => 'Tax-deductible portion of the amount',
328 'required' => true,
329 'precision' => array(
330 20,
331 2
332 ) ,
333 'default' => '0.0',
334 'html' => array(
335 'type' => 'Text',
336 ) ,
337 ) ,
338 'tax_amount' => array(
339 'name' => 'tax_amount',
340 'type' => CRM_Utils_Type::T_MONEY,
341 'title' => ts('Tax Amount') ,
342 'description' => 'tax of each item',
343 'precision' => array(
344 20,
345 2
346 ) ,
347 'import' => true,
348 'where' => 'civicrm_line_item.tax_amount',
349 'headerPattern' => '/tax(.?am(ou)?nt)?/i',
350 'dataPattern' => '/^\d+(\.\d{2})?$/',
351 'export' => true,
352 'html' => array(
353 'type' => 'Text',
354 ) ,
355 ) ,
356 );
357 }
358 return self::$_fields;
359 }
360 /**
361 * Returns an array containing, for each field, the arary key used for that
362 * field in self::$_fields.
363 *
364 * @return array
365 */
366 static function &fieldKeys() {
367 if (!(self::$_fieldKeys)) {
368 self::$_fieldKeys = array(
369 'id' => 'id',
370 'entity_table' => 'entity_table',
371 'entity_id' => 'entity_id',
372 'contribution_id' => 'contribution_id',
373 'price_field_id' => 'price_field_id',
374 'label' => 'label',
375 'qty' => 'qty',
376 'unit_price' => 'unit_price',
377 'line_total' => 'line_total',
378 'participant_count' => 'participant_count',
379 'price_field_value_id' => 'price_field_value_id',
380 'financial_type_id' => 'financial_type_id',
381 'deductible_amount' => 'deductible_amount',
382 'tax_amount' => 'tax_amount',
383 );
384 }
385 return self::$_fieldKeys;
386 }
387 /**
388 * Returns the names of this table
389 *
390 * @return string
391 */
392 static function getTableName() {
393 return self::$_tableName;
394 }
395 /**
396 * Returns if this table needs to be logged
397 *
398 * @return boolean
399 */
400 function getLog() {
401 return self::$_log;
402 }
403 /**
404 * Returns the list of fields that can be imported
405 *
406 * @param bool $prefix
407 *
408 * @return array
409 */
410 static function &import($prefix = false) {
411 if (!(self::$_import)) {
412 self::$_import = array();
413 $fields = self::fields();
414 foreach($fields as $name => $field) {
415 if (CRM_Utils_Array::value('import', $field)) {
416 if ($prefix) {
417 self::$_import['line_item'] = & $fields[$name];
418 } else {
419 self::$_import[$name] = & $fields[$name];
420 }
421 }
422 }
423 }
424 return self::$_import;
425 }
426 /**
427 * Returns the list of fields that can be exported
428 *
429 * @param bool $prefix
430 *
431 * @return array
432 */
433 static function &export($prefix = false) {
434 if (!(self::$_export)) {
435 self::$_export = array();
436 $fields = self::fields();
437 foreach($fields as $name => $field) {
438 if (CRM_Utils_Array::value('export', $field)) {
439 if ($prefix) {
440 self::$_export['line_item'] = & $fields[$name];
441 } else {
442 self::$_export[$name] = & $fields[$name];
443 }
444 }
445 }
446 }
447 return self::$_export;
448 }
449}