| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
| 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 | * @var string |
| 35 | */ |
| 36 | |
| 37 | /** |
| 38 | * Name of the field |
| 39 | */ |
| 40 | public $_name; |
| 41 | |
| 42 | /** |
| 43 | * Title of the field to be used in display |
| 44 | */ |
| 45 | public $_title; |
| 46 | |
| 47 | /** |
| 48 | * Type of field |
| 49 | * @var enum |
| 50 | */ |
| 51 | public $_type; |
| 52 | |
| 53 | /** |
| 54 | * Is this field required |
| 55 | * @var boolean |
| 56 | */ |
| 57 | public $_required; |
| 58 | |
| 59 | /** |
| 60 | * Data to be carried for use by a derived class |
| 61 | * @var object |
| 62 | */ |
| 63 | public $_payload; |
| 64 | |
| 65 | /** |
| 66 | * Regexp to match the CSV header of this column/field |
| 67 | * @var string |
| 68 | */ |
| 69 | public $_columnPattern; |
| 70 | |
| 71 | /** |
| 72 | * Regexp to match the pattern of data from various column/fields |
| 73 | * @var string |
| 74 | */ |
| 75 | public $_dataPattern; |
| 76 | |
| 77 | /** |
| 78 | * Regexp to match the pattern of header from various column/fields |
| 79 | * @var string |
| 80 | */ |
| 81 | public $_headerPattern; |
| 82 | |
| 83 | /** |
| 84 | * Location type |
| 85 | * @var int |
| 86 | */ |
| 87 | public $_hasLocationType; |
| 88 | |
| 89 | /** |
| 90 | * Does this field have a phone type |
| 91 | * @var string |
| 92 | */ |
| 93 | public $_phoneType; |
| 94 | |
| 95 | /** |
| 96 | * Value of this field |
| 97 | * @var object |
| 98 | */ |
| 99 | public $_value; |
| 100 | |
| 101 | /** |
| 102 | * Does this field have a relationship info |
| 103 | * @var string |
| 104 | */ |
| 105 | public $_related; |
| 106 | |
| 107 | /** |
| 108 | * Does this field have a relationship Contact Type |
| 109 | * @var string |
| 110 | */ |
| 111 | public $_relatedContactType; |
| 112 | |
| 113 | /** |
| 114 | * Does this field have a relationship Contact Details |
| 115 | * @var string |
| 116 | */ |
| 117 | public $_relatedContactDetails; |
| 118 | |
| 119 | /** |
| 120 | * Does this field have a related Contact info of Location Type |
| 121 | * @var int |
| 122 | */ |
| 123 | public $_relatedContactLocType; |
| 124 | |
| 125 | /** |
| 126 | * Does this field have a related Contact info of Phone Type |
| 127 | * @var string |
| 128 | */ |
| 129 | public $_relatedContactPhoneType; |
| 130 | |
| 131 | /** |
| 132 | * @param string $name |
| 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 | */ |
| 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) { |
| 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 | |
| 162 | public function resetValue() { |
| 163 | $this->_value = NULL; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * The value is in string format. |
| 168 | * |
| 169 | * Convert the value to the type of this field |
| 170 | * and set the field value with the appropriate type |
| 171 | * |
| 172 | * @param mixed $value |
| 173 | */ |
| 174 | public function setValue($value) { |
| 175 | $this->_value = $value; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Validate something we didn't document. |
| 180 | * |
| 181 | * @return bool |
| 182 | */ |
| 183 | public function validate() { |
| 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 | } |
| 200 | |
| 201 | } |