60,6 → 60,8 |
'date_fin' => 'date_fin', |
'taxon' => 'taxon' |
); |
|
private $format = 'csv'; |
|
/** |
* Méthode appelée avec une requête de type GET. |
67,6 → 69,7 |
public function getElement($params = array()) { |
|
$criteres = $this->traiterParametres($_GET); |
|
// Seulement les observation publiques |
$criteres['transmission'] = 1; |
$chercheur_observations = new RechercheObservation($this->config); |
78,12 → 81,23 |
unset($criteres['debut']); |
|
$observations = $chercheur_observations->rechercherObservations(null, $criteres, $numero_page, $limite); |
$csv = $this->convertirEnCsv($observations); |
$this->envoyerCsv($csv); |
|
switch($this->format) { |
case 'csv': |
$csv = $this->convertirEnCsv($observations); |
$this->envoyerCsv($csv); |
break; |
case 'xls': |
$xls = $this->convertirEnXls($observations); |
$this->envoyerXls($xls); |
break; |
default: |
} |
} |
|
protected function traiterParametres(Array $parametres) { |
$parametres_traites = array(); |
$this->format = (isset($parametres['format']) && $parametres['format'] != '') ? $parametres['format'] : $this->format; |
foreach($parametres as $cle => $valeur) { |
if(trim($valeur) != '' && isset($this->parametres_autorises[$cle])) { |
$parametres_traites[$this->parametres_autorises[$cle]] = $valeur; |
99,6 → 113,11 |
exit; |
} |
|
private function envoyerXls($workbook) { |
$workbook->close(); |
exit; |
} |
|
private function convertirEnCsv($data) |
{ |
$chemin_temp = "php://temp"; |
118,6 → 137,37 |
return $csv; |
} |
|
private function convertirEnXls($data) { |
$this->extendSpreadsheetProductor = new SpreadsheetProductor(); |
$this->extendSpreadsheetProductor->initSpreadsheet(); |
|
$workbook = new Spreadsheet_Excel_Writer(); |
|
$worksheet = $workbook->addWorksheet('Liste'); |
$workbook->send($this->nom_fichier_export); |
|
$nb_lignes = 1; |
|
foreach($data as $ligne) { |
$ligne = array_diff_key($ligne, $this->champs_a_exclure); |
if(empty($intitule_champs)) { |
$intitule_champs = $this->creerEntetesChamps($ligne); |
$indice = 0; |
foreach ($intitule_champs as $intitule) { |
$worksheet->write(0,$indice,$intitule_champs[$indice]); |
$indice++; |
} |
} |
$indice = 0; |
foreach($ligne as $champ) { |
$worksheet->write($nb_lignes,$indice,$champ); |
$indice++; |
} |
$nb_lignes++; |
} |
return $workbook; |
} |
|
private function creerEntetesChamps($noms_colonnes) { |
$champs_presents = array_intersect_key($this->correspondance_champs, $noms_colonnes); |
return array_values($champs_presents); |