This commit is contained in:
Laurent Destailleur 2011-09-10 12:21:41 +00:00
parent b4c1cfa5bd
commit 5fac7191cf
6 changed files with 173 additions and 112 deletions

View File

@ -48,8 +48,9 @@ class Export
/** /**
* \brief Constructeur de la classe * Constructor
* \param DB Handler acces base de donnees *
* @param DoliDB $DB Database handler
*/ */
function Export($DB) function Export($DB)
{ {
@ -58,9 +59,11 @@ class Export
/** /**
* \brief Load an exportable dataset * Load an exportable dataset
* \param user Object user making export *
* \param filter Load a particular dataset only * @param User $user Object user making export
* @param string $filter Load a particular dataset only
* @return int <0 if KO, >0 if OK
*/ */
function load_arrays($user,$filter='') function load_arrays($user,$filter='')
{ {
@ -70,13 +73,13 @@ class Export
$var=true; $var=true;
$i=0; $i=0;
foreach ($conf->file->dol_document_root as $type => $dirroot) foreach ($conf->file->dol_document_root as $type => $dirroot)
{ {
$modulesdir[] = $dirroot . "/includes/modules/"; $modulesdir[] = $dirroot . "/includes/modules/";
if ($type == 'alt') if ($type == 'alt')
{ {
$handle=@opendir($dirroot); $handle=@opendir($dirroot);
if (is_resource($handle)) if (is_resource($handle))
{ {
@ -185,7 +188,7 @@ class Export
$this->array_export_sql_end[$i]=$module->export_sql_end[$r]; $this->array_export_sql_end[$i]=$module->export_sql_end[$r];
//$this->array_export_sql[$i]=$module->export_sql[$r]; //$this->array_export_sql[$i]=$module->export_sql[$r];
dol_syslog("Export loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".sizeof($module->export_fields_code[$r])); dol_syslog("Export loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".count($module->export_fields_code[$r]));
$i++; $i++;
// } // }
} }
@ -196,15 +199,18 @@ class Export
closedir($handle); closedir($handle);
} }
} }
return 1;
} }
/** /**
* \brief Build the sql export request * Build the sql export request.
* \param indice Indice of export * Arrays this->array_export_xxx are already loaded for required datatoexport
* \param array_selected Filter on array of fields to export *
* \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport * @param int $indice Indice of export
* aussi le parametre datatoexport est inutilise * @param array $array_selected Filter on array of fields to export
* @return string SQL String. Example "select s.rowid as r_rowid, s.status as s_status from ..."
*/ */
function build_sql($indice,$array_selected) function build_sql($indice,$array_selected)
{ {
@ -228,14 +234,16 @@ class Export
} }
/** /**
* \brief Build export file * Build export file.
* \param user User that export * File is built into directory $conf->export->dir_temp.'/'.$user->id
* \param model Export format * Arrays this->array_export_xxx are already loaded for required datatoexport
* \param datatoexport Name of dataset to export *
* \param array_selected Filter on array of fields to export * @param User $user User that export
* \param sqlquery = '' if set, transmit a sql query instead of building it from arrays * @param string $model Export format
* \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport * @param string $datatoexport Name of dataset to export
* aussi le parametre datatoexport est inutilise * @param array $array_selected Filter on array of fields to export
* @param string $sqlquery If set, transmit a sql query instead of building it from arrays
* @return int <0 if KO, >0 if OK
*/ */
function build_file($user, $model, $datatoexport, $array_selected, $sqlquery = '') function build_file($user, $model, $datatoexport, $array_selected, $sqlquery = '')
{ {
@ -317,6 +325,7 @@ class Export
// Close file // Close file
$objmodel->close_file(); $objmodel->close_file();
return 1;
} }
else else
{ {
@ -334,8 +343,10 @@ class Export
} }
/** /**
* \brief Save an export model in database * Save an export model in database
* \param user Object user that save *
* @param User $user Object user that save
* @return int <0 if KO, >0 if OK
*/ */
function create($user) function create($user)
{ {
@ -367,8 +378,10 @@ class Export
} }
/** /**
* \brief Load an export profil from database * Load an export profil from database
* \param rowid id of profil to load *
* @param int $id Id of profil to load
* @return int <0 if KO, >0 if OK
*/ */
function fetch($id) function fetch($id)
{ {
@ -377,7 +390,7 @@ class Export
$sql.= ' WHERE em.rowid = '.$id; $sql.= ' WHERE em.rowid = '.$id;
dol_syslog("Export::fetch sql=".$sql, LOG_DEBUG); dol_syslog("Export::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql) ; $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
@ -405,10 +418,11 @@ class Export
/** /**
* \brief Delete object in database * Delete object in database
* \param user User that delete *
* \param notrigger 0=launch triggers after, 1=disable triggers * @param User $user User that delete
* \return int <0 if KO, >0 if OK * @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/ */
function delete($user, $notrigger=0) function delete($user, $notrigger=0)
{ {

View File

@ -798,9 +798,10 @@ llxFooter();
/** /**
* \brief Return table name of an alias. For this, we look for the "tablename as alias" in sql string. * Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
* \param code Alias.Fieldname *
* \param sqlmaxforexport SQL request to parse * @param code Alias.Fieldname
* @param sqlmaxforexport SQL request to parse
*/ */
function getablenamefromfield($code,$sqlmaxforexport) function getablenamefromfield($code,$sqlmaxforexport)
{ {

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -41,8 +41,9 @@ class Import
/** /**
* \brief Constructor * Constructor
* \param DB Database handler *
* @param DoliDB $DB Database handler
*/ */
function Import($DB) function Import($DB)
{ {
@ -51,9 +52,11 @@ class Import
/** /**
* Load description of an importable dataset * Load description of an importable dataset
* @param user Object user making import *
* @param filter Load a particular dataset only * @param User $user Object user making import
* @param string $filter Load a particular dataset only
* @return int <0 if KO, >0 if OK
*/ */
function load_arrays($user,$filter='') function load_arrays($user,$filter='')
{ {
@ -152,7 +155,7 @@ class Import
// Tableau des regles de conversion d'une valeur depuis une autre source (cle=champ, valeur=tableau des regles) // Tableau des regles de conversion d'une valeur depuis une autre source (cle=champ, valeur=tableau des regles)
$this->array_import_convertvalue[$i]=$module->import_convertvalue_array[$r]; $this->array_import_convertvalue[$i]=$module->import_convertvalue_array[$r];
dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->import_code[$r].", nb of fields=".sizeof($module->import_fields_code[$r])); dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->import_code[$r].", nb of fields=".count($module->import_fields_code[$r]));
$i++; $i++;
// } // }
} }
@ -163,18 +166,20 @@ class Import
} }
} }
closedir($handle); closedir($handle);
return 1;
} }
/** /**
* \brief Lance la generation du fichier example * Build an import example file.
* \param user User qui exporte * Arrays this->array_export_xxx are already loaded for required datatoexport
* \param model Modele d'export *
* \param $headerlinefields Array of values for first line of example file * @param User $user User qui exporte
* \param $contentlinevalues Array of values for content line of example file * @param string $model Modele d'export
* \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport * @param string $headerlinefields Array of values for first line of example file
* aussi le parametre datatoexport est inutilise * @param string $contentlinevalues Array of values for content line of example file
* @return string <0 if KO, >0 if OK
*/ */
function build_example_file($user, $model, $headerlinefields, $contentlinevalues) function build_example_file($user, $model, $headerlinefields, $contentlinevalues)
{ {
@ -210,8 +215,10 @@ class Import
} }
/** /**
* \brief Save an export model in database * Save an export model in database
* \param user Object user that save *
* @param User $user Object user that save
* @return int <0 if KO, >0 if OK
*/ */
function create($user) function create($user)
{ {
@ -248,8 +255,10 @@ class Import
} }
/** /**
* \brief Load an import profil from database * Load an import profil from database
* \param rowid id of profil to load *
* @param int $id Id of profil to load
* @return int <0 if KO, >0 if OK
*/ */
function fetch($id) function fetch($id)
{ {
@ -285,10 +294,11 @@ class Import
} }
/** /**
* \brief Delete object in database * Delete object in database
* \param user User that delete *
* \param notrigger 0=launch triggers after, 1=disable triggers * @param User $user User that delete
* \return int <0 if KO, >0 if OK * @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/ */
function delete($user, $notrigger=0) function delete($user, $notrigger=0)
{ {

View File

@ -45,8 +45,9 @@ class ExportCsv extends ModeleExports
/** /**
* \brief Constructeur * Constructor
* \param db Handler acces base de donnee *
* @param DoliDB $db Database handler
*/ */
function ExportCsv($db) function ExportCsv($db)
{ {
@ -108,9 +109,11 @@ class ExportCsv extends ModeleExports
/** /**
* \brief Open output file * Open output file
* \param file Path of filename *
* \return int <0 if KO, >=0 if OK * @param string $file Path of filename to generate
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >=0 if OK
*/ */
function open_file($file,$outputlangs) function open_file($file,$outputlangs)
{ {
@ -133,8 +136,10 @@ class ExportCsv extends ModeleExports
} }
/** /**
* \brief Output header into file * Output header into file
* \param langs Output language *
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/ */
function write_header($outputlangs) function write_header($outputlangs)
{ {
@ -143,10 +148,12 @@ class ExportCsv extends ModeleExports
/** /**
* Output title line into file * Output title line into file
* @param array_export_fields_label Array with list of label of fields *
* @param array_selected_sorted Array with list of field to export * @param array $array_export_fields_label Array with list of label of fields
* @param outputlangs Object lang to translate values * @param array $array_selected_sorted Array with list of field to export
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/ */
function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs) function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs)
{ {
@ -174,10 +181,12 @@ class ExportCsv extends ModeleExports
/** /**
* Output record line into file * Output record line into file
* @param array_selected_sorted Array with list of field to export *
* @param objp A record from a fetch with all fields from select * @param array $array_selected_sorted Array with list of field to export
* @param outputlangs Object lang to translate values * @param resource $objp A record from a fetch with all fields from select
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/ */
function write_record($array_selected_sorted,$objp,$outputlangs) function write_record($array_selected_sorted,$objp,$outputlangs)
{ {
@ -197,6 +206,7 @@ class ExportCsv extends ModeleExports
{ {
$alias=str_replace(array('.','-'),'_',$code); $alias=str_replace(array('.','-'),'_',$code);
if (empty($alias)) dol_print_error('','Bad value for field with key='.$code.'. Try to redefine export.'); if (empty($alias)) dol_print_error('','Bad value for field with key='.$code.'. Try to redefine export.');
$newvalue=$outputlangs->convToOutputCharset($objp->$alias); $newvalue=$outputlangs->convToOutputCharset($objp->$alias);
// Translation newvalue // Translation newvalue
@ -216,8 +226,10 @@ class ExportCsv extends ModeleExports
} }
/** /**
* \brief Output footer into file * Output footer into file
* \param outputlangs Output language *
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/ */
function write_footer($outputlangs) function write_footer($outputlangs)
{ {
@ -225,7 +237,9 @@ class ExportCsv extends ModeleExports
} }
/** /**
* \brief Close file handle * Close file handle
*
* @return int <0 if KO, >0 if OK
*/ */
function close_file() function close_file()
{ {
@ -235,8 +249,9 @@ class ExportCsv extends ModeleExports
/** /**
* Clean a cell to respect rules of CSV file cells * Clean a cell to respect rules of CSV file cells
* @param newvalue String to clean *
* @return string Value cleaned * @param string $newvalue String to clean
* @return string Value cleaned
*/ */
function csv_clean($newvalue) function csv_clean($newvalue)
{ {

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -49,7 +49,7 @@ class ExportExcel extends ModeleExports
/** /**
* Constructor * Constructor
* *
* @param db databse handler * @param DoliDB $db Database handler
*/ */
function ExportExcel($db) function ExportExcel($db)
{ {
@ -109,8 +109,9 @@ class ExportExcel extends ModeleExports
/** /**
* Open output file * Open output file
* *
* @param file Path of filename * @param string $file File name to generate
* @return int <0 if KO, >=0 if OK * @param Translate $outputlangs Output language object
* @return int <0 if KO, >=0 if OK
*/ */
function open_file($file,$outputlangs) function open_file($file,$outputlangs)
{ {
@ -158,7 +159,8 @@ class ExportExcel extends ModeleExports
/** /**
* Write header * Write header
* *
* @param outputlangs Object lang to translate values * @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/ */
function write_header($outputlangs) function write_header($outputlangs)
{ {
@ -169,11 +171,12 @@ class ExportExcel extends ModeleExports
/** /**
* Output title line into file * Output title line into file
* *
* @param array_export_fields_label Array with list of label of fields * @param array $array_export_fields_label Array with list of label of fields
* @param array_selected_sorted Array with list of field to export * @param array $array_selected_sorted Array with list of field to export
* @param outputlangs Object lang to translate values * @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/ */
function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs) function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs)
{ {
@ -216,11 +219,12 @@ class ExportExcel extends ModeleExports
} }
/** /**
* Output record line into file * Output record line into file
* *
* @param array_selected_sorted Array with list of field to export * @param array $array_selected_sorted Array with list of field to export
* @param objp A record from a fetch with all fields from select * @param resource $objp A record from a fetch with all fields from select
* @param outputlangs Object lang to translate values * @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/ */
function write_record($array_selected_sorted,$objp,$outputlangs) function write_record($array_selected_sorted,$objp,$outputlangs)
{ {
@ -312,7 +316,8 @@ class ExportExcel extends ModeleExports
/** /**
* Write footer * Write footer
* *
* @param outputlangs Object lang to translate values * @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/ */
function write_footer($outputlangs) function write_footer($outputlangs)
{ {
@ -322,6 +327,8 @@ class ExportExcel extends ModeleExports
/** /**
* Close Excel file * Close Excel file
*
* @return int <0 if KO, >0 if OK
*/ */
function close_file() function close_file()
{ {
@ -344,8 +351,8 @@ class ExportExcel extends ModeleExports
/** /**
* Clean a cell to respect rules of Excel file cells * Clean a cell to respect rules of Excel file cells
* *
* @param newvalue String to clean * @param string $newvalue String to clean
* @return string Value cleaned * @return string Value cleaned
*/ */
function excel_clean($newvalue) function excel_clean($newvalue)
{ {

View File

@ -45,8 +45,9 @@ class ExportTsv extends ModeleExports
/** /**
* \brief Constructeur * Constructor
* \param db Database handler *
* @param DoliDB $db Database handler
*/ */
function ExportTsv($db) function ExportTsv($db)
{ {
@ -102,9 +103,11 @@ class ExportTsv extends ModeleExports
/** /**
* \brief Open output file * Open output file
* \param file Path of filename *
* \return int <0 if KO, >=0 if OK * @param string $file Path of filename to generate
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >=0 if OK
*/ */
function open_file($file,$outputlangs) function open_file($file,$outputlangs)
{ {
@ -127,8 +130,10 @@ class ExportTsv extends ModeleExports
} }
/** /**
* \brief Output header into file * Output header into file
* \param langs Output language *
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/ */
function write_header($outputlangs) function write_header($outputlangs)
{ {
@ -137,10 +142,12 @@ class ExportTsv extends ModeleExports
/** /**
* Output title line into file * Output title line into file
* @param array_export_fields_label Array with list of label of fields *
* @param array_selected_sorted Array with list of field to export * @param array $array_export_fields_label Array with list of label of fields
* @param outputlangs Object lang to translate values * @param array $array_selected_sorted Array with list of field to export
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/ */
function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs) function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs)
{ {
@ -157,10 +164,12 @@ class ExportTsv extends ModeleExports
/** /**
* Output record line into file * Output record line into file
* @param array_selected_sorted Array with list of field to export *
* @param objp A record from a fetch with all fields from select * @param array $array_selected_sorted Array with list of field to export
* @param outputlangs Object lang to translate values * @param resource $objp A record from a fetch with all fields from select
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/ */
function write_record($array_selected_sorted,$objp,$outputlangs) function write_record($array_selected_sorted,$objp,$outputlangs)
{ {
@ -187,8 +196,10 @@ class ExportTsv extends ModeleExports
} }
/** /**
* \brief Output footer into file * Output footer into file
* \param outputlangs Output language *
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/ */
function write_footer($outputlangs) function write_footer($outputlangs)
{ {
@ -196,7 +207,9 @@ class ExportTsv extends ModeleExports
} }
/** /**
* \brief Close file handle * Close file handle
*
* @return int <0 if KO, >0 if OK
*/ */
function close_file() function close_file()
{ {
@ -206,8 +219,9 @@ class ExportTsv extends ModeleExports
/** /**
* Clean a cell to respect rules of TSV file cells * Clean a cell to respect rules of TSV file cells
* @param newvalue String to clean *
* @return string Value cleaned * @param string $newvalue String to clean
* @return string Value cleaned
*/ */
function tsv_clean($newvalue) function tsv_clean($newvalue)
{ {