League/Csv
This commit is contained in:
parent
c0a9f811fa
commit
4e0f417d4d
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
use League\Csv\Writer;
|
||||
|
||||
class RefController extends Zend_Controller_Action
|
||||
{
|
||||
public function indexAction ()
|
||||
public function indexAction()
|
||||
{
|
||||
//Ne fait rien...
|
||||
}
|
||||
@ -9,7 +11,7 @@ class RefController extends Zend_Controller_Action
|
||||
/**
|
||||
* Donne accès au fichier
|
||||
*/
|
||||
public function fichierAction ()
|
||||
public function fichierAction()
|
||||
{
|
||||
//Lecture du nom du fichier
|
||||
$fichier = $this->_getParam('q','');
|
||||
@ -54,7 +56,7 @@ class RefController extends Zend_Controller_Action
|
||||
/**
|
||||
* Donne accès aux données contenues dans une table de base de données
|
||||
*/
|
||||
public function tableAction ()
|
||||
public function tableAction()
|
||||
{
|
||||
$requetesql = $this->_getParam('q','');
|
||||
$fichierCsv = $requetesql.'.csv';
|
||||
@ -64,33 +66,27 @@ class RefController extends Zend_Controller_Action
|
||||
$c = Zend_Registry::get('config');
|
||||
$path = $c->profil->path->shared . '/files/fichiers/';
|
||||
if (!is_dir($path)) { mkdir($path); }
|
||||
if (!empty($requetesql))
|
||||
{
|
||||
if (!file_exists($path . $fichierCsv))
|
||||
{
|
||||
if (file_exists('assets/sql/'.$fichierSql))
|
||||
{
|
||||
if (!empty($requetesql)) {
|
||||
if (!file_exists($path . $fichierCsv)) {
|
||||
if (file_exists('assets/sql/'.$fichierSql)) {
|
||||
//Connexion mysql
|
||||
$sql = file_get_contents('assets/sql/'.$fichierSql);
|
||||
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
||||
$rows = $db->fetchAll($sql);
|
||||
if (count($rows) > 0) {
|
||||
$fp = fopen($path . $fichierCsv.'.tmp', 'w');
|
||||
//Write header
|
||||
$headers = array_keys($rows[0]);
|
||||
fputcsv($fp, $headers, ',', '"');
|
||||
//Write content
|
||||
$csv = Writer::createFromPath($path . $fichierCsv.'.tmp', 'w');
|
||||
$csv->setNewline("\r\n");
|
||||
$csv->insertOne($headers);
|
||||
foreach($rows as $fields) {
|
||||
fputcsv($fp, $fields, ',', '"');
|
||||
$csv->insertOne($fields);
|
||||
}
|
||||
fclose($fp);
|
||||
rename($path . $fichierCsv.'.tmp', $path . $fichierCsv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($path . $fichierCsv))
|
||||
{
|
||||
if (file_exists($path . $fichierCsv)) {
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
//Distribution du fichier sur la sortie standard
|
||||
|
@ -3,7 +3,8 @@
|
||||
"description": "Webservice API",
|
||||
"require": {
|
||||
"zendframework/zendframework1": "^1.12",
|
||||
"geshi/geshi": "dev-master"
|
||||
"geshi/geshi": "dev-master",
|
||||
"league/csv": "^8.0"
|
||||
},
|
||||
"include-path": ["library/"],
|
||||
"autoload": {
|
||||
|
61
composer.lock
generated
61
composer.lock
generated
@ -4,8 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "9dfabcd79bf953c5c15bfbcae71c1b8a",
|
||||
"content-hash": "afcae0beeea0527e5823708ba9a42a31",
|
||||
"hash": "f049bb3d4ca56a71c533c0436e592793",
|
||||
"content-hash": "42e509fca9c9b79fd71b701521d202e1",
|
||||
"packages": [
|
||||
{
|
||||
"name": "geshi/geshi",
|
||||
@ -44,6 +44,63 @@
|
||||
"homepage": "http://qbnz.com/highlighter/",
|
||||
"time": "2016-02-01 23:14:34"
|
||||
},
|
||||
{
|
||||
"name": "league/csv",
|
||||
"version": "8.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/csv.git",
|
||||
"reference": "63f2fc3598a4dbbc906c9db9d6f04bc7f72b0645"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/csv/zipball/63f2fc3598a4dbbc906c9db9d6f04bc7f72b0645",
|
||||
"reference": "63f2fc3598a4dbbc906c9db9d6f04bc7f72b0645",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"fabpot/php-cs-fixer": "^1.9",
|
||||
"phpunit/phpunit": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "8.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\Csv\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ignace Nyamagana Butera",
|
||||
"email": "nyamsprod@gmail.com",
|
||||
"homepage": "https://github.com/nyamsprod/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Csv data manipulation made easy in PHP",
|
||||
"homepage": "http://csv.thephpleague.com",
|
||||
"keywords": [
|
||||
"csv",
|
||||
"export",
|
||||
"filter",
|
||||
"import",
|
||||
"read",
|
||||
"write"
|
||||
],
|
||||
"time": "2016-05-30 09:35:50"
|
||||
},
|
||||
{
|
||||
"name": "zendframework/zendframework1",
|
||||
"version": "1.12.19",
|
||||
|
Loading…
Reference in New Issue
Block a user