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