On renomme le service Export en Exporter car il rentre en conflit avec le controller
This commit is contained in:
parent
f59d786d64
commit
31c6c7daaf
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
require_once 'WsScore/WsScore.php';
|
||||
require_once realpath(dirname(__FILE__)).'/Types.php';
|
||||
|
||||
class Export extends WsScore
|
||||
{
|
||||
protected $elements = array(
|
||||
'naf' => 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
1
library/WsScore/Exporter/v0.1/Exporter.ini
Normal file
1
library/WsScore/Exporter/v0.1/Exporter.ini
Normal file
@ -0,0 +1 @@
|
||||
Type[] = "Elements"
|
103
library/WsScore/Exporter/v0.1/Exporter.php
Normal file
103
library/WsScore/Exporter/v0.1/Exporter.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
require_once 'WsScore/WsScore.php';
|
||||
require_once realpath(dirname(__FILE__)).'/Types.php';
|
||||
|
||||
class Exporter extends WsScore
|
||||
{
|
||||
protected $elements = array(
|
||||
'naf' => 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -13,6 +13,6 @@ idClient = 1;
|
||||
actif = true;
|
||||
idClient = 1;
|
||||
|
||||
[export]
|
||||
[exporter]
|
||||
actif = true;
|
||||
idClient = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user