Commit da71e393 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Ajout des formats CSV/Excel pour l'export des projets

parent b6c7ae32
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ class ProjectController extends AbstractOscarController
                $format = $this->params()->fromQuery('f');
            }

            $allowedFormat = [OscarFormatterConst::FORMAT_IO_CSV, OscarFormatterConst::FORMAT_IO_JSON];
            $allowedFormat = [OscarFormatterConst::FORMAT_IO_CSV, OscarFormatterConst::FORMAT_IO_JSON, OscarFormatterConst::FORMAT_IO_EXCEL];

            if (!in_array($format, $allowedFormat)) {
                return $this->getResponseInternalError(sprintf(_("Format '%s' inconnue"), $format));
@@ -146,7 +146,7 @@ class ProjectController extends AbstractOscarController

            // Récupération des projets
            $projects = $this->getProjectService()->getProjectsByIds($projectIds);
            $formatter = $this->getProjectService()->getFormatter($format);
            $formatter = $this->getProjectService()->getFormatter($format == OscarFormatterConst::FORMAT_IO_JSON ?: OscarFormatterConst::FORMAT_IO_CSV);

            // Fichier temporaire
            $filename = uniqid('oscar_export_project_') . '.csv';
@@ -166,7 +166,11 @@ class ProjectController extends AbstractOscarController
            fclose($handler);

            $downloader = new CSVDownloader();
            if( $format == OscarFormatterConst::FORMAT_IO_CSV ){
                $downloader->downloadCSV($filePath);
            } else {
                $downloader->downloadCSVToExcel($filePath);
            }
            unlink($filePath);
            die();
        } catch (\Exception $e) {
@@ -174,6 +178,15 @@ class ProjectController extends AbstractOscarController
        }
    }

    public function emptyAction()
    {
        $projects = $this->getProjectService()->getEmptyProject();
        return array(
            'projects' => $projects,
            'search' => '',
        );
    }

    /**
     * Fiche projet.
     *
+6 −1
Original line number Diff line number Diff line
@@ -638,9 +638,14 @@
            <?php if($projectview == 'on' && count($projectsIds) > 0): ?>
                <form action="<?= $this->url('project/export-many') ?>" method="post">
                    <input type="hidden" value="<?= implode(',', $projectsIds) ?>" name="ids" />
                    Exporter les projets :
                    <button type="submit" class="btn btn-primary" name="format" value="csv">
                        <i class="icon-download"></i>
                        Exporter les projets (CSV)
                        CSV
                    </button>
                    <button type="submit" class="btn btn-primary" name="format" value="excel">
                        <i class="icon-download"></i>
                        Excel
                    </button>
                </form>
            <?php endif; ?>