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