Merge pull request #14087 from seamuslee001/npm_version_update
[civicrm-core.git] / CRM / Contact / Import / Field.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 /**
29 * Class CRM_Contact_Import_Field
30 */
31 class CRM_Contact_Import_Field {
32
33 /**
34 * #@+
35 * @var string
36 */
37
38 /**
39 * Name of the field
40 * @var string
41 */
42 public $_name;
43
44 /**
45 * Title of the field to be used in display
46 * @var string
47 */
48 public $_title;
49
50 /**
51 * Type of field
52 * @var enum
53 */
54 public $_type;
55
56 /**
57 * Is this field required
58 * @var bool
59 */
60 public $_required;
61
62 /**
63 * Data to be carried for use by a derived class
64 * @var object
65 */
66 public $_payload;
67
68 /**
69 * Regexp to match the CSV header of this column/field
70 * @var string
71 */
72 public $_columnPattern;
73
74 /**
75 * Regexp to match the pattern of data from various column/fields
76 * @var string
77 */
78 public $_dataPattern;
79
80 /**
81 * Regexp to match the pattern of header from various column/fields
82 * @var string
83 */
84 public $_headerPattern;
85
86 /**
87 * Location type
88 * @var int
89 */
90 public $_hasLocationType;
91
92 /**
93 * Does this field have a phone type
94 * @var string
95 */
96 public $_phoneType;
97
98 /**
99 * Value of this field
100 * @var object
101 */
102 public $_value;
103
104 /**
105 * Does this field have a relationship info
106 * @var string
107 */
108 public $_related;
109
110 /**
111 * Does this field have a relationship Contact Type
112 * @var string
113 */
114 public $_relatedContactType;
115
116 /**
117 * Does this field have a relationship Contact Details
118 * @var string
119 */
120 public $_relatedContactDetails;
121
122 /**
123 * Does this field have a related Contact info of Location Type
124 * @var int
125 */
126 public $_relatedContactLocType;
127
128 /**
129 * Does this field have a related Contact info of Phone Type
130 * @var string
131 */
132 public $_relatedContactPhoneType;
133
134 /**
135 * @param string $name
136 * @param $title
137 * @param int $type
138 * @param string $columnPattern
139 * @param string $dataPattern
140 * @param null $hasLocationType
141 * @param null $phoneType
142 * @param null $related
143 * @param null $relatedContactType
144 * @param null $relatedContactDetails
145 * @param null $relatedContactLocType
146 * @param null $relatedContactPhoneType
147 */
148 public function __construct($name, $title, $type = CRM_Utils_Type::T_INT, $columnPattern = '//', $dataPattern = '//', $hasLocationType = NULL, $phoneType = NULL, $related = NULL, $relatedContactType = NULL, $relatedContactDetails = NULL, $relatedContactLocType = NULL, $relatedContactPhoneType = NULL) {
149 $this->_name = $name;
150 $this->_title = $title;
151 $this->_type = $type;
152 $this->_columnPattern = $columnPattern;
153 $this->_dataPattern = $dataPattern;
154 $this->_hasLocationType = $hasLocationType;
155 $this->_phoneType = $phoneType;
156 $this->_related = $related;
157 $this->_relatedContactType = $relatedContactType;
158 $this->_relatedContactDetails = $relatedContactDetails;
159 $this->_relatedContactLocType = $relatedContactLocType;
160 $this->_relatedContactPhoneType = $relatedContactPhoneType;
161
162 $this->_value = NULL;
163 }
164
165 public function resetValue() {
166 $this->_value = NULL;
167 }
168
169 /**
170 * The value is in string format.
171 *
172 * Convert the value to the type of this field
173 * and set the field value with the appropriate type
174 *
175 * @param mixed $value
176 */
177 public function setValue($value) {
178 $this->_value = $value;
179 }
180
181 /**
182 * Validate something we didn't document.
183 *
184 * @return bool
185 */
186 public function validate() {
187 // echo $this->_value."===========<br>";
188 $message = '';
189
190 if ($this->_value === NULL) {
191 return TRUE;
192 }
193
194 // Commented due to bug CRM-150, internationalization/wew.
195 // if ( $this->_name == 'phone' ) {
196 // return CRM_Utils_Rule::phone( $this->_value );
197 // }
198
199 if ($this->_name == 'email') {
200 return CRM_Utils_Rule::email($this->_value);
201 }
202 }
203
204 }