Rajout de l'export CSV
authorSébastien CHAZALLET <s.chazallet@gmail.com>
Tue, 27 Nov 2012 15:15:23 +0000 (16:15 +0100)
committerSébastien CHAZALLET <s.chazallet@gmail.com>
Tue, 27 Nov 2012 15:15:23 +0000 (16:15 +0100)
data/jeu_essai.db
data/scripts/schema.sql
module/Galerie/config/module.config.php
module/Galerie/src/Galerie/Controller/IndexController.php
module/Galerie/src/Galerie/Model/GalerieInfo.php
module/Galerie/src/Galerie/Model/GalerieInfoTable.php

index 6954bf8..cdb9c11 100644 (file)
Binary files a/data/jeu_essai.db and b/data/jeu_essai.db differ
index 14a9f1f..ebf8a4b 100644 (file)
@@ -215,3 +215,10 @@ BEGIN
     END;
 END;
 
+CREATE VIEW gallery_info AS
+    SELECT gallery.id, gallery.name, gallery.description, user.firstname || ' ' || user.lastname AS username, count(photo.id) as nb
+    INNER JOIN user ON gallery.id_user = user.id
+    LEFT JOIN photo ON gallery.id = photo.id_gallery
+    GROUP BY user.lastname, user.firstname, gallery.name
+    ORDER BY user.lastname, user.firstname, gallery.name
+;
index 5c06d9c..5f96569 100644 (file)
@@ -117,7 +117,18 @@ return array(
                             ),
                         ),
                         'verb' => 'get',
-                    ),/*
+                    ),
+                    'csv' => array(
+                        'type'    => 'Literal',
+                        'options' => array(
+                            'route'    => '/csv',
+                            'defaults' => array(
+                                'action' => 'csv',
+                            ),
+                        ),
+                        'verb' => 'get',
+                    ),
+/*
                     'default' => array(
                         'type'    => 'Segment',
                         'options' => array(
index fefa823..1f358f3 100644 (file)
@@ -61,6 +61,30 @@ class IndexController extends AbstractActionController
         return new ViewModel($this->MessageGetter());
     } 
 
+    public function csvAction() {
+        // Récupération des informations brutes
+        $modelManager = $this->_getGalerieInfoTable();
+        $datas = $modelManager->all();
+
+        // Mise en forme des résultats
+        $content = array($modelManager->csvHeader());
+        foreach($datas as $d) {
+            $content[] = $d->csvFormat();
+        }
+
+        // Création de la réponse
+        $response = $this->getResponse();
+        $response->setStatusCode(200);
+
+        $headers = $this->getResponse()->getHeaders();
+        $headers->addHeaderLine('Content-Type', 'text/csv; charset=utf-8');
+        $headers->addHeaderLine('Content-Disposition', 'attachment; filename="export_galerie.csv"');
+
+
+        $response->setContent(implode("\r\n", $content));
+        return $response;
+    }
+
     public function listAction() 
     { 
         // Récupération de l'objet requête
index 2abe6ca..954ee71 100644 (file)
@@ -27,4 +27,13 @@ class GalerieInfo extends Entity
     protected $primary_columns = array(
     );
 
+    public function csvFormat()
+    {
+        return $this->id
+            . ';' . $this->name
+            . ';' . $this->description
+            . ';' . $this->username
+            . ';' . $this->nb;
+    }
+
 }
index 3d5890b..939f8b3 100644 (file)
@@ -157,6 +157,10 @@ class GalerieInfoTable implements TableGatewayInterface
     }
 
 
+    public function csvHeader()
+    {
+        return "Id;Nom;Description;Propriétaire;Nombre";
+    }
 
 
 }