extranet/includes/export/ExportCSV.php
Michael RICOIS a5a71a3cb1 exportcsv
2011-12-02 14:52:05 +00:00

71 lines
1.4 KiB
PHP

<?php
class ExportCSV
{
protected $entete = array();
protected $enteteKey = array();
protected $data = array();
protected $type = '';
protected $list = array();
public function __construct($data = array(), $type = '')
{
$this->data = $data;
$this->type = $type;
$this->structure();
$this->prepareData();
}
protected function prepareData()
{
$row = 0;
foreach($this->data as $itemKey => $itemVal)
{
foreach($this->enteteKey as $key){
$val = html_entity_decode($itemVal[$key]);
$this->list[$row][] = $val;
}
$row++;
}
}
protected function structure()
{
switch($this->type) {
case 'rechercheEntreprise':
$structure = array(
'Siren' => 'Siren',
'Nom' => 'Nom',
'Nom2' => 'Nom2',
'Enseigne' => 'Enseigne',
'Adresse' => 'Adresse',
'Adresse2' => 'Adresse2',
'CP' => 'CP',
'Sigle' => 'Sigle',
'Siege' => 'Siege',
'Actif' => 'Actif',
'FJ' => 'FJ',
'FJLib' => 'FJLib',
'NafEnt' => 'NafEntLib',
);
break;
default:
break;
}
$this->entete = array_values($structure);
$this->enteteKey = array_keys($structure);
}
public function writeFile($filename)
{
$fp = fopen($filename, 'w');
if (count($this->entete)>0){
fputcsv($fp, $this->entete);
}
foreach ($this->list as $fields) {
$fields = array_map('htmlspecialchars_decode', $fields);
fputcsv($fp, $fields);
}
fclose($fp);
}
}