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