3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Member_Import_Field
{
48 * title of the field to be used in display
59 * is this field required
65 * data to be carried for use by a derived class
71 * regexp to match the CSV header of this column/field
74 public $_headerPattern;
77 * regexp to match the pattern of data from various column/fields
88 function __construct($name, $title, $type = CRM_Utils_Type
::T_INT
, $headerPattern = '//', $dataPattern = '//') {
90 $this->_title
= $title;
92 $this->_headerPattern
= $headerPattern;
93 $this->_dataPattern
= $dataPattern;
98 function resetValue() {
103 * the value is in string format. convert the value to the type of this field
104 * and set the field value with the appropriate type
106 function setValue($value) {
107 $this->_value
= $value;
110 function validate() {
112 if (CRM_Utils_System
::isNull($this->_value
)) {
116 switch ($this->_name
) {
118 // note: we validate extistence of the contact in API, upon
119 // insert (it would be too costlty to do a db call here)
120 return CRM_Utils_Rule
::integer($this->_value
);
125 case 'thankyou_date':
126 return CRM_Utils_Rule
::date($this->_value
);
128 case 'non_deductible_amount':
132 return CRM_Utils_Rule
::money($this->_value
);
135 static $seenTrxnIds = array();
136 if (in_array($this->_value
, $seenTrxnIds)) {
139 elseif ($this->_value
) {
140 $seenTrxnIds[] = $this->_value
;
144 $this->_value
= NULL;
150 return CRM_Utils_Rule
::currencyCode($this->_value
);
152 case 'membership_type':
153 static $membershipTypes = NULL;
154 if (!$membershipTypes) {
155 $membershipTypes = CRM_Member_PseudoConstant
::membershipType();
157 if (in_array($this->_value
, $membershipTypes)) {
165 case 'payment_instrument':
166 static $paymentInstruments = NULL;
167 if (!$paymentInstruments) {
168 $paymentInstruments = CRM_Member_PseudoConstant
::paymentInstrument();
170 if (in_array($this->_value
, $paymentInstruments)) {
182 // check whether that's a valid custom field id
183 // and if so, check the contents' validity
184 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($this->_name
)) {
185 static $customFields = NULL;
186 if (!$customFields) {
187 $customFields = CRM_Core_BAO_CustomField
::getFields('Membership');
189 if (!array_key_exists($customFieldID, $customFields)) {
192 return CRM_Core_BAO_CustomValue
::typecheck($customFields[$customFieldID]['data_type'], $this->_value
);