Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
86538308 EM |
27 | |
28 | /** | |
29 | * Class CRM_Contact_Import_Field | |
30 | */ | |
719a6fec | 31 | class CRM_Contact_Import_Field { |
6a488035 TO |
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 | */ | |
03e04002 | 130 | public $_relatedContactPhoneType; |
6a488035 | 131 | |
86538308 EM |
132 | /** |
133 | * @param $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 | */ | |
6a488035 TO |
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 | ||
86538308 EM |
175 | /** |
176 | * @return bool | |
177 | */ | |
6a488035 TO |
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 |