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_Contribute_Import_Field
{
31 * Title of the field to be used in display
43 * Is this field required.
50 * Data to be carried for use by a derived class
56 * Regexp to match the CSV header of this column/field
59 public $_headerPattern;
62 * Regexp to match the pattern of data from various column/fields
74 * This is soft credit field
77 public $_softCreditField;
83 * @param string $headerPattern
84 * @param string $dataPattern
85 * @param null $softCreditField
87 public function __construct($name, $title, $type = CRM_Utils_Type
::T_INT
, $headerPattern = '//', $dataPattern = '//', $softCreditField = NULL) {
89 $this->_title
= $title;
91 $this->_headerPattern
= $headerPattern;
92 $this->_dataPattern
= $dataPattern;
93 $this->_softCreditField
= $softCreditField;
97 public function resetValue() {
104 * The value is in string format. Convert the value to the type of this field
105 * and set the field value with the appropriate type
109 public function setValue($value) {
110 $this->_value
= $value;
118 public function validate() {
120 if (CRM_Utils_System
::isNull($this->_value
)) {
124 switch ($this->_name
) {
126 // note: we validate existence of the contact in API, upon
127 // insert (it would be too costly to do a db call here)
128 return CRM_Utils_Rule
::integer($this->_value
);
133 case 'thankyou_date':
134 return CRM_Utils_Rule
::date($this->_value
);
136 case 'non_deductible_amount':
140 return CRM_Utils_Rule
::money($this->_value
);
143 static $seenTrxnIds = [];
144 if (in_array($this->_value
, $seenTrxnIds)) {
147 elseif ($this->_value
) {
148 $seenTrxnIds[] = $this->_value
;
152 $this->_value
= NULL;
158 return CRM_Utils_Rule
::currencyCode($this->_value
);
160 case 'financial_type':
161 static $contributionTypes = NULL;
162 if (!$contributionTypes) {
163 $contributionTypes = CRM_Contribute_PseudoConstant
::financialType();
165 if (in_array($this->_value
, $contributionTypes)) {
173 case 'payment_instrument':
174 static $paymentInstruments = NULL;
175 if (!$paymentInstruments) {
176 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
178 if (in_array($this->_value
, $paymentInstruments)) {
190 // check whether that's a valid custom field id
191 // and if so, check the contents' validity
192 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($this->_name
)) {
193 static $customFields = NULL;
194 if (!$customFields) {
195 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution');
197 if (!array_key_exists($customFieldID, $customFields)) {
200 return CRM_Core_BAO_CustomValue
::typecheck($customFields[$customFieldID]['data_type'], $this->_value
);