(NFC) Update CRM/Contact to match new coder style
[civicrm-core.git] / CRM / Contact / Import / Field.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
86538308
EM
27
28/**
29 * Class CRM_Contact_Import_Field
30 */
719a6fec 31class CRM_Contact_Import_Field {
6a488035 32
69078420
SL
33 /**
34 * #@+
6a488035
TO
35 * @var string
36 */
37
38 /**
100fef9d 39 * Name of the field
69078420 40 * @var string
6a488035
TO
41 */
42 public $_name;
43
44 /**
100fef9d 45 * Title of the field to be used in display
69078420 46 * @var string
6a488035
TO
47 */
48 public $_title;
49
50 /**
100fef9d 51 * Type of field
6a488035
TO
52 * @var enum
53 */
54 public $_type;
55
56 /**
100fef9d 57 * Is this field required
6a488035
TO
58 * @var boolean
59 */
60 public $_required;
61
62 /**
100fef9d 63 * Data to be carried for use by a derived class
6a488035
TO
64 * @var object
65 */
66 public $_payload;
67
68 /**
100fef9d 69 * Regexp to match the CSV header of this column/field
6a488035
TO
70 * @var string
71 */
72 public $_columnPattern;
73
74 /**
100fef9d 75 * Regexp to match the pattern of data from various column/fields
6a488035
TO
76 * @var string
77 */
78 public $_dataPattern;
79
80 /**
100fef9d 81 * Regexp to match the pattern of header from various column/fields
6a488035
TO
82 * @var string
83 */
84 public $_headerPattern;
85
86 /**
100fef9d 87 * Location type
6a488035
TO
88 * @var int
89 */
90 public $_hasLocationType;
91
92 /**
100fef9d 93 * Does this field have a phone type
6a488035
TO
94 * @var string
95 */
96 public $_phoneType;
97
98 /**
100fef9d 99 * Value of this field
6a488035
TO
100 * @var object
101 */
102 public $_value;
103
104 /**
100fef9d 105 * Does this field have a relationship info
6a488035
TO
106 * @var string
107 */
108 public $_related;
109
110 /**
100fef9d 111 * Does this field have a relationship Contact Type
6a488035
TO
112 * @var string
113 */
114 public $_relatedContactType;
115
116 /**
100fef9d 117 * Does this field have a relationship Contact Details
6a488035
TO
118 * @var string
119 */
120 public $_relatedContactDetails;
121
122 /**
100fef9d 123 * Does this field have a related Contact info of Location Type
6a488035
TO
124 * @var int
125 */
126 public $_relatedContactLocType;
127
128 /**
100fef9d 129 * Does this field have a related Contact info of Phone Type
6a488035
TO
130 * @var string
131 */
03e04002 132 public $_relatedContactPhoneType;
6a488035 133
86538308 134 /**
100fef9d 135 * @param string $name
86538308
EM
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 */
00be9182 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) {
6a488035
TO
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
00be9182 165 public function resetValue() {
6a488035
TO
166 $this->_value = NULL;
167 }
168
169 /**
ea3ddccf 170 * The value is in string format.
171 *
172 * Convert the value to the type of this field
6a488035 173 * and set the field value with the appropriate type
ea3ddccf 174 *
175 * @param mixed $value
6a488035 176 */
00be9182 177 public function setValue($value) {
6a488035
TO
178 $this->_value = $value;
179 }
180
86538308 181 /**
ea3ddccf 182 * Validate something we didn't document.
183 *
86538308
EM
184 * @return bool
185 */
00be9182 186 public function validate() {
6a488035
TO
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 }
96025800 203
6a488035 204}