dolibarr  20.0.0-alpha
Public Member Functions | List of all members
ImportCsv Class Reference

Class to import CSV files. More...

Inheritance diagram for ImportCsv:
Inheritance graph
[legend]
Collaboration diagram for ImportCsv:
Collaboration graph
[legend]

Public Member Functions

 __construct ($db, $datatoimport)
 Constructor. More...
 
 write_header_example ($outputlangs)
 Output header of an example file for this format. More...
 
 write_title_example ($outputlangs, $headerlinefields)
 Output title line of an example file for this format. More...
 
 write_record_example ($outputlangs, $contentlinevalues)
 Output record of an example file for this format. More...
 
 write_footer_example ($outputlangs)
 Output footer of an example file for this format. More...
 
 import_open_file ($file)
 Open input file. More...
 
 import_get_nb_of_lines ($file)
 Return nb of records. More...
 
 import_read_header ()
 Input header line from file. More...
 
 import_read_record ()
 Return array of next record in input file. More...
 
 import_close_file ()
 Close file handle. More...
 
 import_insert ($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
 Insert a record into database. More...
 
- Public Member Functions inherited from ModeleImports
 __construct ()
 Constructor.
 
 getDriverId ()
 getDriverId More...
 
 getDriverLabel ()
 getDriverLabel More...
 
 getDriverDesc ()
 getDriverDesc More...
 
 getDriverExtension ()
 getDriverExtension More...
 
 getDriverVersion ()
 getDriverVersion More...
 
 getLibLabel ()
 getDriverLabel More...
 
 getLibVersion ()
 getLibVersion More...
 
 listOfAvailableImportFormat ($db, $maxfilenamelength=0)
 Load into memory list of available import format. More...
 
 getPictoForKey ($key)
 Return picto of import driver. More...
 
 getDriverLabelForKey ($key)
 Return label of driver import. More...
 
 getDriverDescForKey ($key)
 Return description of import drivervoi la description d'un driver import. More...
 
 getDriverVersionForKey ($key)
 Renvoi version d'un driver import. More...
 
 getLibLabelForKey ($key)
 Renvoi libelle de librairie externe du driver. More...
 
 getLibVersionForKey ($key)
 Renvoi version de librairie externe du driver. More...
 
 getElementFromTableWithPrefix ($tableNameWithPrefix)
 Get element from table name with prefix. More...
 

Detailed Description

Class to import CSV files.

Definition at line 34 of file import_csv.modules.php.

Constructor & Destructor Documentation

◆ __construct()

ImportCsv::__construct (   $db,
  $datatoimport 
)

Constructor.

Parameters
DoliDB$dbDatabase handler
string$datatoimportString code describing import set (ex: 'societe_1')

Definition at line 88 of file import_csv.modules.php.

Member Function Documentation

◆ import_close_file()

ImportCsv::import_close_file ( )

Close file handle.

Returns
integer

Definition at line 285 of file import_csv.modules.php.

◆ import_get_nb_of_lines()

ImportCsv::import_get_nb_of_lines (   $file)

Return nb of records.

File must be closed.

Parameters
string$filePath of filename
Returns
int Return integer <0 if KO, >=0 if OK

Definition at line 211 of file import_csv.modules.php.

References dol_count_nb_of_line().

◆ import_insert()

ImportCsv::import_insert (   $arrayrecord,
  $array_match_file_to_database,
  $objimport,
  $maxfields,
  $importid,
  $updatekeys 
)

Insert a record into database.

Parameters
array$arrayrecordArray of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
array$array_match_file_to_databaseArray of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]...
Object$objimportObject import (contains objimport->array_import_tables, objimport->array_import_fields, objimport->array_import_convertvalue, ...)
int$maxfieldsMax number of fields to use
string$importidImport key
array$updatekeysArray of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 305 of file import_csv.modules.php.

◆ import_open_file()

ImportCsv::import_open_file (   $file)

Open input file.

Parameters
string$filePath of filename
Returns
int Return integer <0 if KO, >=0 if OK

Definition at line 181 of file import_csv.modules.php.

◆ import_read_header()

ImportCsv::import_read_header ( )

Input header line from file.

Returns
int Return integer <0 if KO, >=0 if OK

Definition at line 224 of file import_csv.modules.php.

◆ import_read_record()

ImportCsv::import_read_record ( )

Return array of next record in input file.

Returns
array|boolean Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=not empty string)

Definition at line 237 of file import_csv.modules.php.

◆ write_footer_example()

ImportCsv::write_footer_example (   $outputlangs)

Output footer of an example file for this format.

Parameters
Translate$outputlangsOutput language
Returns
string Empty string

Definition at line 167 of file import_csv.modules.php.

◆ write_header_example()

ImportCsv::write_header_example (   $outputlangs)

Output header of an example file for this format.

Parameters
Translate$outputlangsOutput language
Returns
string Empty string

Definition at line 124 of file import_csv.modules.php.

◆ write_record_example()

ImportCsv::write_record_example (   $outputlangs,
  $contentlinevalues 
)

Output record of an example file for this format.

Parameters
Translate$outputlangsOutput language
array$contentlinevaluesArray of lines
Returns
string String output

Definition at line 153 of file import_csv.modules.php.

◆ write_title_example()

ImportCsv::write_title_example (   $outputlangs,
  $headerlinefields 
)

Output title line of an example file for this format.

Parameters
Translate$outputlangsOutput language
array$headerlinefieldsArray of fields name
Returns
string String output

Definition at line 138 of file import_csv.modules.php.


The documentation for this class was generated from the following file: