Commit 7d8eaba2 authored by Stéphane Bouvry's avatar Stéphane Bouvry
Browse files

Export JSON, un bouton Export JSON permet maintenant d'exporter les données au format JSON

parent 28d1de3d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -618,7 +618,7 @@ contract:
        exportjson:
            type: segment
            options:
                route: /export-json/:id
                route: /export-json[/:id]
                defaults:
                    action: exportJSON

+31 −4
Original line number Diff line number Diff line
@@ -264,11 +264,37 @@ class ProjectGrantController extends AbstractOscarController


    public function exportJSONAction(){

        $id = $this->params()->fromRoute('id', null);
        $ids = $this->params()->fromPost('ids', null);

        if( $id == null && $ids == null ){
            return $this->getResponseInternalError("Données d'exportation incomplètes.");
        }

        $json = [];

        if( $id ){
            $activity = $this->getActivityFromRoute();
        $json = $this->getActivityService()->exportJson($activity);
            $json[] = $this->getActivityService()->exportJson($activity);
        }

        if( $ids ){
            $ids = explode(',', $ids);
            $result = $this->getEntityManager()->createQueryBuilder()->select('a')
                ->from(Activity::class, 'a')
                ->where('a.id IN(:ids)')
                ->setParameter('ids', $ids)
                ->getQuery()
                ->getResult();
            foreach ($result as $activity) {
                $json[] = $this->getActivityService()->exportJson($activity);
            }
        }

//        header('Content-Disposition: attachment; filename=activity-'.$activity->getOscarNum().'.json');
//        header('Content-Length: ' . filesize('/tmp/' . $filename));
        $filename = 'activity-json.json';

        header('Content-Disposition: attachment; filename='.$filename);
        header('Content-type: application/json');
        die(json_encode($json));
    }
@@ -378,6 +404,7 @@ class ProjectGrantController extends AbstractOscarController
        die(file_get_contents('/tmp/' . $filename));
    }


    /** Export les données en CSV. */
    public function csvAction()
    {
+2 −2
Original line number Diff line number Diff line
@@ -433,11 +433,11 @@
                </button>
            </form>

            <form action="<?= $this->url('contract/csv') ?>" class=" export-selection-area" style="display: none" method="post">
            <form action="<?= $this->url('contract/exportjson') ?>" class=" export-selection-area" method="post">
                <input type="hidden" name="ids" value="<?= $exportIds ?>">
                <button type="submit" href="#" class="btn btn-primary">
                    <i class="icon-cube"></i>
                    Exporter les <span class="total">X</span> activité(s) selectionée(s)
                    Export JSON
                </button>
            </form>
            <hr />
+1 −1

File changed.

Contains only whitespace changes.