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