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