dolibarr 18.0.6
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 $id;
49
53 public $label;
54
55 public $extension; // Extension of files imported by driver
56
61 public $version = 'dolibarr';
62
63 public $label_lib; // Label of external lib used by driver
64
65 public $version_lib; // Version of external lib used by driver
66
67 // Array of all drivers
68 public $driverlabel = array();
69
70 public $driverdesc = array();
71
72 public $driverversion = array();
73
74 public $liblabel = array();
75
76 public $libversion = array();
77
78 public $charset;
79
80
84 public static $mapTableToElement = array(
85 'actioncomm' => 'agenda',
86 'adherent' => 'member',
87 'adherent_type' => 'member_type',
88 //'bank_account' => 'bank_account',
89 'categorie' => 'category',
90 //'commande' => 'commande',
91 //'commande_fournisseur' => 'commande_fournisseur',
92 'contrat' => 'contract',
93 'entrepot' => 'stock',
94 //'expensereport' => 'expensereport',
95 'facture' => 'invoice',
96 //'facture_fourn' => 'facture_fourn',
97 'fichinter' => 'intervention',
98 //'holiday' => 'holiday',
99 //'product' => 'product',
100 'product_price' => 'productprice',
101 'product_fournisseur_price' => 'productsupplierprice',
102 'projet' => 'project',
103 //'propal' => 'propal',
104 //'societe' => 'societe',
105 'socpeople' => 'contact',
106 //'supplier_proposal' => 'supplier_proposal',
107 //'ticket' => 'ticket',
108 );
109
113 public function __construct()
114 {
115 global $hookmanager;
116
117 if (is_object($hookmanager)) {
118 $hookmanager->initHooks(array('import'));
119 $parameters = array();
120 $reshook = $hookmanager->executeHooks('constructModeleImports', $parameters, $this);
121 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
122 foreach ($hookmanager->resArray as $mapList) {
123 self::$mapTableToElement[$mapList['table']] = $mapList['element'];
124 }
125 }
126 }
127 }
128
134 public function getDriverId()
135 {
136 return $this->id;
137 }
138
144 public function getDriverLabel()
145 {
146 return $this->label;
147 }
148
154 public function getDriverDesc()
155 {
156 return $this->desc;
157 }
158
164 public function getDriverExtension()
165 {
166 return $this->extension;
167 }
168
174 public function getDriverVersion()
175 {
176 return $this->version;
177 }
178
184 public function getLibLabel()
185 {
186 return $this->label_lib;
187 }
188
194 public function getLibVersion()
195 {
196 return $this->version_lib;
197 }
198
199
207 public function listOfAvailableImportFormat($db, $maxfilenamelength = 0)
208 {
209 dol_syslog(get_class($this)."::listOfAvailableImportFormat");
210
211 $dir = DOL_DOCUMENT_ROOT."/core/modules/import/";
212 $handle = opendir($dir);
213
214 // Recherche des fichiers drivers imports disponibles
215 $i = 0;
216 if (is_resource($handle)) {
217 while (($file = readdir($handle)) !== false) {
218 if (preg_match("/^import_(.*)\.modules\.php/i", $file, $reg)) {
219 $moduleid = $reg[1];
220
221 // Loading Class
222 $file = $dir."/import_".$moduleid.".modules.php";
223 $classname = "Import".ucfirst($moduleid);
224
225 require_once $file;
226 $module = new $classname($db, '');
227
228 // Picto
229 $this->picto[$module->id] = $module->picto;
230 // Driver properties
231 $this->driverlabel[$module->id] = $module->getDriverLabel('');
232 $this->driverdesc[$module->id] = $module->getDriverDesc('');
233 $this->driverversion[$module->id] = $module->getDriverVersion('');
234 // If use an external lib
235 $this->liblabel[$module->id] = $module->getLibLabel('');
236 $this->libversion[$module->id] = $module->getLibVersion('');
237
238 $i++;
239 }
240 }
241 }
242
243 return array_keys($this->driverlabel);
244 }
245
246
253 public function getPictoForKey($key)
254 {
255 return $this->picto[$key];
256 }
257
264 public function getDriverLabelForKey($key)
265 {
266 return $this->driverlabel[$key];
267 }
268
275 public function getDriverDescForKey($key)
276 {
277 return $this->driverdesc[$key];
278 }
279
286 public function getDriverVersionForKey($key)
287 {
288 return $this->driverversion[$key];
289 }
290
297 public function getLibLabelForKey($key)
298 {
299 return $this->liblabel[$key];
300 }
301
308 public function getLibVersionForKey($key)
309 {
310 return $this->libversion[$key];
311 }
312
319 public function getElementFromTableWithPrefix($tableNameWithPrefix)
320 {
321 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tableNameWithPrefix);
322 $element = $tableElement;
323
324 if (isset(self::$mapTableToElement[$tableElement])) {
325 $element = self::$mapTableToElement[$tableElement];
326 }
327
328 return $element;
329 }
330}
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.