dolibarr 19.0.4
modules_import.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
25require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
26
27
32{
36 public $db;
37
38 public $datatoimport;
39
43 public $error = '';
44
48 public $errors = array();
49
53 public $warnings = array();
54
58 public $id;
59
63 public $label;
64
65 public $extension; // Extension of files imported by driver
66
71 public $version = 'dolibarr';
72
73 public $label_lib; // Label of external lib used by driver
74
75 public $version_lib; // Version of external lib used by driver
76
77 // Array of all drivers
78 public $driverlabel = array();
79
80 public $driverdesc = array();
81
82 public $driverversion = array();
83
84 public $liblabel = array();
85
86 public $libversion = array();
87
91 public $charset;
92
96 public $picto;
97
101 public $desc;
102
106 public $escape;
107
111 public $enclosure;
112
116 public $thirdpartyobject;
117
121 public static $mapTableToElement = array(
122 'actioncomm' => 'agenda',
123 'adherent' => 'member',
124 'adherent_type' => 'member_type',
125 //'bank_account' => 'bank_account',
126 'categorie' => 'category',
127 //'commande' => 'commande',
128 //'commande_fournisseur' => 'commande_fournisseur',
129 'contrat' => 'contract',
130 'entrepot' => 'stock',
131 //'expensereport' => 'expensereport',
132 'facture' => 'invoice',
133 //'facture_fourn' => 'facture_fourn',
134 'fichinter' => 'intervention',
135 //'holiday' => 'holiday',
136 //'product' => 'product',
137 'product_price' => 'productprice',
138 'product_fournisseur_price' => 'productsupplierprice',
139 'projet' => 'project',
140 //'propal' => 'propal',
141 //'societe' => 'societe',
142 'socpeople' => 'contact',
143 //'supplier_proposal' => 'supplier_proposal',
144 //'ticket' => 'ticket',
145 );
146
150 public function __construct()
151 {
152 global $hookmanager;
153
154 if (is_object($hookmanager)) {
155 $hookmanager->initHooks(array('import'));
156 $parameters = array();
157 $reshook = $hookmanager->executeHooks('constructModeleImports', $parameters, $this);
158 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
159 foreach ($hookmanager->resArray as $mapList) {
160 self::$mapTableToElement[$mapList['table']] = $mapList['element'];
161 }
162 }
163 }
164 }
165
171 public function getDriverId()
172 {
173 return $this->id;
174 }
175
181 public function getDriverLabel()
182 {
183 return $this->label;
184 }
185
191 public function getDriverDesc()
192 {
193 return $this->desc;
194 }
195
201 public function getDriverExtension()
202 {
203 return $this->extension;
204 }
205
211 public function getDriverVersion()
212 {
213 return $this->version;
214 }
215
221 public function getLibLabel()
222 {
223 return $this->label_lib;
224 }
225
231 public function getLibVersion()
232 {
233 return $this->version_lib;
234 }
235
236
244 public function listOfAvailableImportFormat($db, $maxfilenamelength = 0)
245 {
246 dol_syslog(get_class($this)."::listOfAvailableImportFormat");
247
248 $dir = DOL_DOCUMENT_ROOT."/core/modules/import/";
249 $handle = opendir($dir);
250
251 // Recherche des fichiers drivers imports disponibles
252 $i = 0;
253 if (is_resource($handle)) {
254 while (($file = readdir($handle)) !== false) {
255 if (preg_match("/^import_(.*)\.modules\.php/i", $file, $reg)) {
256 $moduleid = $reg[1];
257
258 // Loading Class
259 $file = $dir."/import_".$moduleid.".modules.php";
260 $classname = "Import".ucfirst($moduleid);
261
262 require_once $file;
263 $module = new $classname($db, '');
264
265 // Picto
266 $this->picto[$module->id] = $module->picto;
267 // Driver properties
268 $this->driverlabel[$module->id] = $module->getDriverLabel('');
269 $this->driverdesc[$module->id] = $module->getDriverDesc('');
270 $this->driverversion[$module->id] = $module->getDriverVersion('');
271 // If use an external lib
272 $this->liblabel[$module->id] = $module->getLibLabel('');
273 $this->libversion[$module->id] = $module->getLibVersion('');
274
275 $i++;
276 }
277 }
278 }
279
280 return array_keys($this->driverlabel);
281 }
282
283
290 public function getPictoForKey($key)
291 {
292 return $this->picto[$key];
293 }
294
301 public function getDriverLabelForKey($key)
302 {
303 return $this->driverlabel[$key];
304 }
305
312 public function getDriverDescForKey($key)
313 {
314 return $this->driverdesc[$key];
315 }
316
323 public function getDriverVersionForKey($key)
324 {
325 return $this->driverversion[$key];
326 }
327
334 public function getLibLabelForKey($key)
335 {
336 return $this->liblabel[$key];
337 }
338
345 public function getLibVersionForKey($key)
346 {
347 return $this->libversion[$key];
348 }
349
356 public function getElementFromTableWithPrefix($tableNameWithPrefix)
357 {
358 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tableNameWithPrefix);
359 $element = $tableElement;
360
361 if (isset(self::$mapTableToElement[$tableElement])) {
362 $element = self::$mapTableToElement[$tableElement];
363 }
364
365 return $element;
366 }
367}
Parent class for import file readers.
getLibVersionForKey($key)
Renvoi version de librairie externe du driver.
getDriverDescForKey($key)
Return description of import drivervoi la description d'un driver import.
getElementFromTableWithPrefix($tableNameWithPrefix)
Get element from table name with prefix.
getDriverLabelForKey($key)
Return label of driver import.
getLibLabel()
getDriverLabel
getDriverVersionForKey($key)
Renvoi version d'un driver import.
getDriverLabel()
getDriverLabel
getPictoForKey($key)
Return picto of import driver.
getDriverId()
getDriverId
getLibLabelForKey($key)
Renvoi libelle de librairie externe du driver.
getDriverVersion()
getDriverVersion
listOfAvailableImportFormat($db, $maxfilenamelength=0)
Load into memory list of available import format.
getDriverExtension()
getDriverExtension
getLibVersion()
getLibVersion
__construct()
Constructor.
getDriverDesc()
getDriverDesc
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.