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
17 class CRM_Member_Import_Field
{
31 * Title of the field to be used in display
43 * Is this field required
49 * Data to be carried for use by a derived class
55 * Regexp to match the CSV header of this column/field
58 public $_headerPattern;
61 * Regexp to match the pattern of data from various column/fields
76 * @param string $headerPattern
77 * @param string $dataPattern
79 public function __construct($name, $title, $type = CRM_Utils_Type
::T_INT
, $headerPattern = '//', $dataPattern = '//') {
81 $this->_title
= $title;
83 $this->_headerPattern
= $headerPattern;
84 $this->_dataPattern
= $dataPattern;
89 public function resetValue() {
94 * The value is in string format. convert the value to the type of this field
95 * and set the field value with the appropriate type
99 public function setValue($value) {
100 $this->_value
= $value;
106 public function validate() {
108 if (CRM_Utils_System
::isNull($this->_value
)) {
112 switch ($this->_name
) {
114 // note: we validate extistence of the contact in API, upon
115 // insert (it would be too costlty to do a db call here)
116 return CRM_Utils_Rule
::integer($this->_value
);
121 case 'thankyou_date':
122 return CRM_Utils_Rule
::date($this->_value
);
124 case 'non_deductible_amount':
128 return CRM_Utils_Rule
::money($this->_value
);
131 static $seenTrxnIds = [];
132 if (in_array($this->_value
, $seenTrxnIds)) {
135 elseif ($this->_value
) {
136 $seenTrxnIds[] = $this->_value
;
140 $this->_value
= NULL;
146 return CRM_Utils_Rule
::currencyCode($this->_value
);
148 case 'membership_type':
149 static $membershipTypes = NULL;
150 if (!$membershipTypes) {
151 $membershipTypes = CRM_Member_PseudoConstant
::membershipType();
153 if (in_array($this->_value
, $membershipTypes)) {
161 case 'payment_instrument':
162 static $paymentInstruments = NULL;
163 if (!$paymentInstruments) {
164 $paymentInstruments = CRM_Member_PseudoConstant
::paymentInstrument();
166 if (in_array($this->_value
, $paymentInstruments)) {
178 // check whether that's a valid custom field id
179 // and if so, check the contents' validity
180 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($this->_name
)) {
181 static $customFields = NULL;
182 if (!$customFields) {
183 $customFields = CRM_Core_BAO_CustomField
::getFields('Membership');
185 if (!array_key_exists($customFieldID, $customFields)) {
188 return CRM_Core_BAO_CustomValue
::typecheck($customFields[$customFieldID]['data_type'], $this->_value
);