diff --git a/library/WsScore/Export/v0.1/Export.ini b/library/WsScore/Export/v0.1/Export.ini deleted file mode 100644 index e69de29b..00000000 diff --git a/library/WsScore/Export/v0.1/Export.php b/library/WsScore/Export/v0.1/Export.php deleted file mode 100644 index 94cbc2d7..00000000 --- a/library/WsScore/Export/v0.1/Export.php +++ /dev/null @@ -1,34 +0,0 @@ - array( - 'entete' => array("codNaf", "libNaf"), - 'sql' => "SELECT codNaf5 AS codNaf, libNaf5 AS libNaf FROM jo.tabNaf5 UNION SELECT codNaf700 AS codNaf, libNaf700 AS libNaf FROM jo.tabNaf4 ORDER BY codNaf", - ), - ); - - /** - * Retourne la liste des élements disponible - * @return Elements[] - */ - public function getElements() - { - - } - - /** - * Enter description here ... - * @param string $key - * @return string - */ - public function getDataCSV($key) - { - - } - - -} \ No newline at end of file diff --git a/library/WsScore/Export/Versions.ini b/library/WsScore/Exporter/Versions.ini similarity index 100% rename from library/WsScore/Export/Versions.ini rename to library/WsScore/Exporter/Versions.ini diff --git a/library/WsScore/Exporter/v0.1/Exporter.ini b/library/WsScore/Exporter/v0.1/Exporter.ini new file mode 100644 index 00000000..746ac9a2 --- /dev/null +++ b/library/WsScore/Exporter/v0.1/Exporter.ini @@ -0,0 +1 @@ +Type[] = "Elements" \ No newline at end of file diff --git a/library/WsScore/Exporter/v0.1/Exporter.php b/library/WsScore/Exporter/v0.1/Exporter.php new file mode 100644 index 00000000..5fbf9961 --- /dev/null +++ b/library/WsScore/Exporter/v0.1/Exporter.php @@ -0,0 +1,103 @@ + array( + 'desc' => "Codes NAF", + 'entete' => array("codNaf", "libNaf"), + 'sql' => "SELECT codNaf5 AS codNaf, libNaf5 AS libNaf FROM jo.tabNaf5 UNION SELECT codNaf700 AS codNaf, libNaf700 AS libNaf FROM jo.tabNaf4 ORDER BY codNaf", + ), + ); + + /** + * Retourne la liste des élements disponible + * @return Elements[] + */ + public function getElements() + { + $tabElements = array(); + if (count($this->elements)>0){ + foreach($this->elements as $item => $value) + { + $elements = new Elements(); + $elements->cle = $item; + $elements->desc = $value['desc']; + $tabElements[] = $elements; + } + } + return $tabElements; + } + + /** + * Enter description here ... + * @param string $key + * @return string + */ + public function getDataCSV($key) + { + //Vérification + + + //Définition des valeurs + $sql = $this->elements[$key]['sql']; + $entete = $this->elements['entete']; + + //Executer la requete SQL + $dbConfig = array( + 'host' => MYSQL_HOST, + 'username' => MYSQL_USER, + 'password' => MYSQL_PASS, + 'dbname' => MYSQL_DEFAULT_DB, + 'driver_options' => array(MYSQLI_INIT_COMMAND => "SET NAMES utf8"), + ); + $db = Zend_Db::factory('Pdo_Mysql', $dbConfig); + $result = $db->fetchAll($sql); + + $filename = 'export/'.$key.'.csv'; + + //Ecriture dans un fichier + $this->export($filename, $result); + + if (file_exists($filename)){ + return $filename; + } + return false; + } + + + /** + * Enter description here ... + * @param unknown_type $filename + * @param unknown_type $data + * @param unknown_type $entete + */ + protected function export($filename, $data = array(), $entete = array()) + { + if (count($entete)>0){ + $export = array_merge(array(0 => $entete), $data); + } else { + $export = $data; + } + $this->exportCSV($export, $filename); + } + + /** + * Enter description here ... + * @param unknown_type $list + * @param unknown_type $filename + * @param unknown_type $delimiter + */ + protected function exportCSV($list, $filename, $delimiter=',') + { + $fp = fopen($filename, 'w'); + foreach($list as $fields){ + fputcsv($fp, $fields, $delimiter); + } + fclose($fp); + } + + +} \ No newline at end of file diff --git a/library/WsScore/Export/v0.1/Types.php b/library/WsScore/Exporter/v0.1/Types.php similarity index 100% rename from library/WsScore/Export/v0.1/Types.php rename to library/WsScore/Exporter/v0.1/Types.php diff --git a/library/WsScore/Services.ini b/library/WsScore/Services.ini index 9648c1ca..32f725ba 100644 --- a/library/WsScore/Services.ini +++ b/library/WsScore/Services.ini @@ -13,6 +13,6 @@ idClient = 1; actif = true; idClient = 1; -[export] +[exporter] actif = true; idClient = 1;