3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 class CRM_Member_Import_Field
{
33 * Title of the field to be used in display
45 * Is this field required
51 * Data to be carried for use by a derived class
57 * Regexp to match the CSV header of this column/field
60 public $_headerPattern;
63 * Regexp to match the pattern of data from various column/fields
78 * @param string $headerPattern
79 * @param string $dataPattern
81 public function __construct($name, $title, $type = CRM_Utils_Type
::T_INT
, $headerPattern = '//', $dataPattern = '//') {
83 $this->_title
= $title;
85 $this->_headerPattern
= $headerPattern;
86 $this->_dataPattern
= $dataPattern;
91 public function resetValue() {
96 * The value is in string format. convert the value to the type of this field
97 * and set the field value with the appropriate type
101 public function setValue($value) {
102 $this->_value
= $value;
108 public function validate() {
110 if (CRM_Utils_System
::isNull($this->_value
)) {
114 switch ($this->_name
) {
116 // note: we validate extistence of the contact in API, upon
117 // insert (it would be too costlty to do a db call here)
118 return CRM_Utils_Rule
::integer($this->_value
);
123 case 'thankyou_date':
124 return CRM_Utils_Rule
::date($this->_value
);
126 case 'non_deductible_amount':
130 return CRM_Utils_Rule
::money($this->_value
);
133 static $seenTrxnIds = [];
134 if (in_array($this->_value
, $seenTrxnIds)) {
137 elseif ($this->_value
) {
138 $seenTrxnIds[] = $this->_value
;
142 $this->_value
= NULL;
148 return CRM_Utils_Rule
::currencyCode($this->_value
);
150 case 'membership_type':
151 static $membershipTypes = NULL;
152 if (!$membershipTypes) {
153 $membershipTypes = CRM_Member_PseudoConstant
::membershipType();
155 if (in_array($this->_value
, $membershipTypes)) {
163 case 'payment_instrument':
164 static $paymentInstruments = NULL;
165 if (!$paymentInstruments) {
166 $paymentInstruments = CRM_Member_PseudoConstant
::paymentInstrument();
168 if (in_array($this->_value
, $paymentInstruments)) {
180 // check whether that's a valid custom field id
181 // and if so, check the contents' validity
182 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($this->_name
)) {
183 static $customFields = NULL;
184 if (!$customFields) {
185 $customFields = CRM_Core_BAO_CustomField
::getFields('Membership');
187 if (!array_key_exists($customFieldID, $customFields)) {
190 return CRM_Core_BAO_CustomValue
::typecheck($customFields[$customFieldID]['data_type'], $this->_value
);