Commit 5e5c8e9c authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge branch 'master' of git.unicaen.fr:dsi/sygal

parents cceae35a 6d89c63c
Loading
Loading
Loading
Loading
+3 −3
Changes for module/Application/config/others/export.config.php: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
<?php

use Application\Controller\ExportController;
use Application\Controller\Factory\ExportControllerFactory;
use Application\Provider\Privilege\ThesePrivileges;
use UnicaenAuth\Guard\PrivilegeController;

@@ -50,8 +50,8 @@ return [
        ],
    ],
    'controllers'     => [
        'invokables' => [
            'Application\Controller\Export' => ExportController::class,
        'factories' => [
            'Application\Controller\Export' => ExportControllerFactory::class,
        ],
    ],
];
 No newline at end of file
+100 −90
Changes for module/Application/src/Application/Controller/ExportController.php: 100 added lines, 90 removed lines.
Original line number Diff line number Diff line
@@ -2,17 +2,19 @@

namespace Application\Controller;

use Application\Entity\Db\NatureFichier;
use Application\Entity\Db\These;
use Application\Service\Fichier\FichierServiceAwareInterface;
use Application\Service\Fichier\FichierServiceAwareTrait;
use Application\Service\These\TheseServiceAwareInterface;
use Application\Service\These\TheseServiceAwareTrait;
use Application\View\Helper\Sortable;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\View\Model\CsvModel;
use Zend\View\Model\ViewModel;

class ExportController extends AbstractController implements TheseServiceAwareInterface
class ExportController extends AbstractController implements TheseServiceAwareInterface, FichierServiceAwareInterface
{
    use TheseServiceAwareTrait;
    use FichierServiceAwareTrait;

    public function csvAction()
    {
@@ -26,59 +28,74 @@ class ExportController extends AbstractController implements TheseServiceAwareIn

        //TODO compléter avec les infos demandées
        $headers = [
            'Civilité'                              => function ($these) { return $these->getDoctorant()->getIndividu()->getCivilite(); },
            'Nom usuel'                             => function ($these) { return $these->getDoctorant()->getIndividu()->getNomUsuel(); },
            'Prenom'                                => function ($these) { return $these->getDoctorant()->getIndividu()->getPrenom(); },
            'Nom patronymique'                      => function ($these) { return $these->getDoctorant()->getIndividu()->getNomPatronymique(); },
            'Date de naissance'                     => function ($these) { return $these->getDoctorant()->getIndividu()->getDateNaissance(); },
            'Mail'                                  => function ($these) { return $these->getDoctorant()->getIndividu()->getEmail(); },
            'Numéro étudiant'                       => function ($these) { return $these->getDoctorant()->getSourceCode(); },
            'Titre'                                 => function ($these) { return $these->getTitre(); },
            'Identifiant de la thèse'               => function ($these) { return $these->getSourceCode(); },
            'Date de première inscription'          => function ($these) { return $these->getDatePremiereInscription(); },
            'Date de prévisionnel de soutenance'    => function ($these) { return $these->getDatePrevisionSoutenance(); },
            'Date de soutenance'                    => function ($these) { return $these->getDateSoutenance(); },
            //'Date d\'autorisation à soutenir'       => function ($these) { return $these->getDateAutSoutenance(); },
            // Doctorant
            'Civilité'                              => function (These $these) { return $these->getDoctorant()->getIndividu()->getCivilite(); },
            'Nom usuel'                             => function (These $these) { return $these->getDoctorant()->getIndividu()->getNomUsuel(); },
            'Prenom'                                => function (These $these) { return $these->getDoctorant()->getIndividu()->getPrenom(); },
            'Nom patronymique'                      => function (These $these) { return $these->getDoctorant()->getIndividu()->getNomPatronymique(); },
            'Date de naissance'                     => function (These $these) { return $these->getDoctorant()->getIndividu()->getDateNaissance(); },
            'Mail'                                  => function (These $these) { return $these->getDoctorant()->getIndividu()->getEmail(); },
            'Numéro étudiant'                       => function (These $these) { return $these->getDoctorant()->getSourceCode(); },
            //These
            'Identifiant de la thèse'               => function (These $these) { return $these->getSourceCode(); },
            'Titre'                                 => function (These $these) { return $these->getTitre(); },
            'Discipline'                            => function (These $these) { return $these->getLibelleDiscipline(); },
            //Structures
            'Etablissement'                         => function (These $these) { return $these->getEtablissement()->getLibelle(); },
            'Ecole Doctorale Code'                  => function (These $these) { if($these->getEcoleDoctorale() !== null)return $these->getEcoleDoctorale()->getSourceCode(); else return null; },
            'Ecole Doctorale'                       => function (These $these) { if($these->getEcoleDoctorale() !== null)return $these->getEcoleDoctorale()->getLibelle(); else return null; },
            'Unité de Recherche Code'               => function (These $these) { if($these->getUniteRecherche() !== null) return $these->getUniteRecherche()->getSourceCode(); else return null; },
            'Unité de Recherche'                    => function (These $these) { if($these->getUniteRecherche() !== null) return $these->getUniteRecherche()->getLibelle(); else return null; },
            'Etablissement Co-Tutelle'              => function (These $these) { return $these->getLibelleEtabCotutelle(); },
            'Pays Co-Tutelle'                       => function (These $these) { return $these->getLibellePaysCotutelle(); },
            //Dates
            'Date de première inscription'          => function (These $these) { return $these->getDatePremiereInscription(); },
            'Date de prévisionnel de soutenance'    => function (These $these) { return $these->getDatePrevisionSoutenance(); },
            'Date de soutenance'                    => function (These $these) { return $these->getDateSoutenance(); },
            'Date de fin de confientialité'         => function (These $these) { return $these->getDateFinConfidentialite(); },
            'Date de dépôt'                         => function (These $these) { $file = $this->fichierService->getRepository()->fetchFichiers($these, NatureFichier::CODE_THESE_PDF)[0]; if ($file !== null) return $file->getHistoCreation()->format('d/m/Y'); },
            //Flags
            'Etat de la thèse'                      => function (These $these) { return $these->getEtatTheseToString();},
            'Autorisation à soutenir'               => function (These $these) { return $these->getSoutenanceAutorisee();},
            'Est confidentielle'                    => function (These $these) { $now = new \DateTime(); $end= $these->getDateFinConfidentialite(); if ($now > $end) return "N"; else return "O"; },
            'Résultat'                              => function (These $these) { return $these->getResultat();},
            'Corrections'                           => function (These $these) { return $these->getCorrectionAutorisee();},
            'Thèse format PDF'                      => function (These $these) { if (!empty($this->fichierService->getRepository()->fetchFichiers($these, NatureFichier::CODE_THESE_PDF))) return 'O'; else return 'N'; },
            'Annexe non PDF'                        => function (These $these) { if (!empty($this->fichierService->getRepository()->fetchFichiers($these, NatureFichier::CODE_FICHIER_NON_PDF))) return 'O'; else return 'N'; },

        ];
        $etatThese = $this->params()->fromQuery('etatThese');
        $sort = $this->params()->fromQuery('sort');
        //$sort = $this->params()->fromQuery('sort');
        $text = $this->params()->fromQuery('text');
        $dir  = $this->params()->fromQuery('direction', Sortable::ASC);
        $sort = $this->params()->fromQuery('sort');

//        var_dump($etatThese);
//        var_dump($sort);
//        var_dump($text);
//        var_dump($dir);

        $repoThese = $this->theseService->getEntityManager()->getRepository(These::class);
        $qb = $repoThese->createQueryBuilder("t")
//            ->where("t.ecoleDoctorale = 41")
            ->andWhere("t.etatThese = :etatThese")
            ->orderBy($sort,$dir);
        $qb->setParameter("etatThese", $etatThese);
//        $qb->setParameter("dir", $sort);
        //$qb->setParameter("attrib", $sort);
        $query = $qb->getQuery();
//        var_dump($query);
//        $repoThese = $this->theseService->getEntityManager()->getRepository(These::class);
//        $qb = $repoThese->createQueryBuilder("t")
//            ->where("t.ecoleDoctorale = 3")
//            ->andWhere("t.etatThese = :etatThese")
//        ;
//        $qb->setParameter("etatThese", $etatThese);
//        $query = $qb->getQuery();
        $query = $this->createQueryBuilder()->getQuery();

            //Execution de la requete
        $theses = $query->execute();

        $records = [];
        //echo "~~~~~~~~~ {".count($theses)." thèse(s) à exporter} ~~~~~~~~~<br/>";
        for ($i = 0 ; $i < count($theses) ; $i++) {
            $these = $theses[$i];
            $record = [];
            foreach($headers as $key => $fct) {
                $record[] = $fct($these);
            }
            //var_dump($record);

            $records[] = $record;
        }
        //echo "Préparation accomplie<br/>";



        $result = new CsvModel();
        $result->setDelimiter(';');
@@ -88,64 +105,57 @@ class ExportController extends AbstractController implements TheseServiceAwareIn
        $result->setFilename('export_theses.csv');

        return $result;
    }

    //TODO FACTORISER AVEC INDEX DES THESES ...
    private function createQueryBuilder() {
        $etatThese = $this->params()->fromQuery($name = 'etatThese');
        $sort = $this->params()->fromQuery('sort');
        $text = $this->params()->fromQuery('text');
        $dir  = $this->params()->fromQuery('direction', Sortable::ASC);

        $cols = [
//////////////CSV                                          => SQL
//            'CIVILITE'                                      => 'CIVILITE',
//            'NOM_USUEL'                                     => 'NOM_USUEL',
//            'PRENOM'                                        => 'PRENOM',
//            'NOM_PATRONYMIQUE'                              => 'NOM_PATRONYMIQUE',
//            'DATE_NAISSANCE'                                => "to_char(DATE_NAISSANCE, 'DD/MM/YYYY')",
//            'EMAIL'                                         => 'EMAIL',
//            'NUMERO_ETUDIANT'                               => 'NUMERO_ETUDIANT',
//            'TITRE_APOGEE'                                  => 'TITRE_APOGEE',
//            'NUMERO_APOGEE'                                 => 'NUMERO_APOGEE',
            'DATE_FIN_CONFID'                               => "to_char(DATE_FIN_CONFID, 'DD/MM/YYYY')",
//            'DATE_PREMIERE_INSCR'                           => "to_char(DATE_PREM_INSC, 'DD/MM/YYYY')",
//            'DATE_SOUTENANCE'                               => "to_char(DATE_SOUTENANCE, 'DD/MM/YYYY')",
            'SOUTENANCE_AUTORIS'                            => 'SOUTENANCE_AUTORIS',
            'TEM_AVENANT_COTUT'                             => 'TEM_AVENANT_COTUT',
            'ETAT_THESE'                                    => 'ETAT_THESE',
            'LIB_DISC'                                      => 'LIB_DISC',
            'RESULTAT'                                      => 'RESULTAT',
            'DATE_PREV_SOUTENANCE'                          => "to_char(DATE_PREV_SOUTENANCE, 'DD/MM/YYYY')",
            'CORREC_AUTORISEE'                              => 'CORREC_AUTORISEE',
            'LANGUE'                                        => 'LANGUE',
            'RESUME'                                        => 'RESUME',
            'RESUME_ANGLAIS'                                => 'RESUME_ANGLAIS',
            'MOTS_CLES_LIBRES_FR'                           => 'MOTS_CLES_LIBRES_FR',
            'TITRE_AUTRE_LANGUE'                            => 'TITRE_AUTRE_LANGUE',
            'MOTS_CLES_LIBRES_ANG'                          => 'MOTS_CLES_LIBRES_ANG',
            'AUTORIS_MEL'                                   => 'AUTORIS_MEL',
            'AUTORIS_MEL_MOTIF'                             => 'AUTORIS_MEL_MOTIF',
            'EMBARGO_DUREE'                                 => 'EMBARGO_DUREE',
            'COORD_DOCTORANT'                               => 'COORD_DOCTORANT',
            'DISPO_DOCTORANT'                               => 'DISPO_DOCTORANT',
            'MOTS_CLES_RAMEAU'                              => 'MOTS_CLES_RAMEAU',
            'CONVENTION_MEL_SIGNEE'                         => 'CONVENTION_MEL_SIGNEE',
            'EXEMPL_PAPIER_FOURNI'                          => 'EXEMPL_PAPIER_FOURNI',
            'DIRECTEURS_THESE'                              => 'DIRECTEURS_THESE',
            'MEMBRES_JURY'                                  => 'MEMBRES_JURY',
            'LIBELLE_ED'                                    => 'LIBELLE_ED',
            'SIGLE_ED'                                      => 'SIGLE_ED',
            'CODE_ED'                                       => 'CODE_ED',
            'LIBELLE_UR'                                    => 'LIBELLE_UR',
            'SIGLE_UR'                                      => 'SIGLE_UR',
            'ETAB_SUPPORT_UR'                               => 'ETAB_SUPPORT_UR',
            'AUTRES_ETAB_SUPPORT_UR'                        => 'AUTRES_ETAB_SUPPORT_UR',
            'CODE_UR'                                       => 'CODE_UR',
            'VERSION_ORIGINALE_ARCHIVABLE'                  => 'VERSION_ORIG_ARCHIVABLE',
            'VERSION_ARCHIVAGE_ARCHIVABLE'                  => 'VERSION_ARCHI_ARCHIVABLE',
            'VERSION_ARCHIVAGE_RETRAITEMENT'                => 'VERSION_ARCHI_RETRAIT',
            'VERSION_ORIGINALE_CORRIGEE_ARCHIVABLE'         => 'VERSION_ORIG_CORR_ARCHIVABLE',
            'VERSION_ARCHIVAGE_CORRIGEE_ARCHIVABLE'         => 'VERSION_ARCHI_CORR_ARCHIVABLE',
            'VERSION_ARCHIVAGE_CORRIGEE_RETRAITEMENT'       => 'VERSION_ARCHI_CORR_RETRAIT',
            'VALIDATION_BU'                                 => 'VALIDATION_BU',
            'PV_SOUTENANCE_DEPOSE'                          => 'PV_SOUTENANCE_DEPOSE',
            'RAPPORT_SOUTENANCE_DEPOSE'                     => 'RAPPORT_SOUTENANCE_DEPOSE',

            'DATE_EXTRACTION'                               => 'DATE_EXTRACTION',
        ];
        $qb = $this->theseService->getRepository()->createQueryBuilder('t')
            ->addSelect('di')->leftJoin('th.individu', 'di')
            ->addSelect('ed')->leftJoin('t.ecoleDoctorale', 'ed')
            ->addSelect('ur')->leftJoin('t.uniteRecherche', 'ur')
            ->addSelect('a')->leftJoin('t.acteurs', 'a')
            ->addSelect('i')->leftJoin('a.individu', 'i')
            ->addSelect('r')->leftJoin('a.role', 'r')
            ->andWhere('1 = pasHistorise(t)');

        if ($etatThese) {
            $qb->andWhere('t.etatThese = :etat')->setParameter('etat', $etatThese);
        }
        $sortProps = $sort ? explode('+', $sort) : [];
        foreach ($sortProps as $sortProp) {
            if ($sortProp === 't.titre') {
                // trim et suppression des guillemets
                $sortProp = "TRIM(REPLACE($sortProp, CHR(34), ''))"; // CHR(34) <=> "
            }
            $qb->addOrderBy($sortProp, $dir);
        }

        /**
         * Filtres découlant du rôle de l'utilisateur.
         */
        $this->theseService->decorateQbFromUserContext($qb, $this->userContextService);

        /**
         * Prise en compte du champ de recherche textuelle.
         */
        if (strlen($text) > 1) {
            $results = $this->theseService->rechercherThese($text);
            $sourceCodes = array_unique(array_keys($results));
            if ($sourceCodes) {
                $qb
                    ->andWhere($qb->expr()->in('t.sourceCode', ':sourceCodes'))
                    ->setParameter('sourceCodes', $sourceCodes);
            }
            else {
                $qb->andWhere("0 = 1"); // i.e. aucune thèse trouvée
            }
        }

        return $qb;
    }
}
 No newline at end of file
+29
Changes for module/Application/src/Application/Controller/Factory/ExportControllerFactory.php: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller\Factory;

use Application\Controller\ExportController;
use Application\Service\Fichier\FichierService;
use Zend\Mvc\Controller\ControllerManager;
use Zend\ServiceManager\ServiceLocatorInterface;

class ExportControllerFactory
{
    /**
     * Create service
     *
     * @param ControllerManager $controllerManager
     * @return ExportController
     */
    public function __invoke(ControllerManager $controllerManager)
    {
        $parentLocator = $controllerManager->getServiceLocator();
        /** @var FichierService $fs */
        $fs = $parentLocator->get('FichierService');
        $service = new ExportController();
        $service->setFichierService($fs);


        return $service;
    }
}
 No newline at end of file