Commit 959bf5d8 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Export CSV pour les EDs des coencadrants

parent 1cb1f81d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ return [
                        'historique',
                        'rechercher-co-encadrant',
                        'generer-justificatif-coencadrements',
                        'generer-export-csv',
                    ],
                    'privileges' => [
                        CoEncadrantPrivileges::COENCADRANT_AFFICHER,
@@ -76,6 +77,16 @@ return [
                            ],
                        ],
                    ],
                    'generer-export-csv' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/generer-export-csv/:structure-type/:structure-id',
                            'defaults' => [
                                'controller'    => CoEncadrantController::class,
                                'action'        => 'generer-export-csv',
                            ],
                        ],
                    ],
                    'rechercher-co-encadrant' => [
                        'type'          => Literal::class,
                        'options'       => [
+44 −0
Original line number Diff line number Diff line
@@ -3,15 +3,21 @@
namespace Application\Controller;

use Application\Entity\Db\Acteur;
use Application\Entity\Db\EcoleDoctorale;
use Application\Entity\Db\Individu;
use Application\Entity\Db\These;
use Application\Entity\Db\UniteRecherche;
use Application\Form\RechercherCoEncadrantFormAwareTrait;
use Application\Service\Acteur\ActeurServiceAwareTrait;
use Application\Service\CoEncadrant\CoEncadrantServiceAwareTrait;
use Application\Service\CoEncadrant\Exporter\JustificatifCoencadrements\JustificatifCoencadrementPdfExporter;
use Application\Service\EcoleDoctorale\EcoleDoctoraleServiceAwareTrait;
use Application\Service\File\FileServiceAwareTrait;
use Application\Service\Individu\IndividuServiceAwareTrait;
use Application\Service\These\TheseServiceAwareTrait;
use Application\Service\UniteRecherche\UniteRechercheServiceAwareTrait;
use DateTime;
use UnicaenApp\View\Model\CsvModel;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
@@ -24,6 +30,9 @@ class CoEncadrantController extends AbstractActionController {
    use FileServiceAwareTrait;
    use TheseServiceAwareTrait;
    use RechercherCoEncadrantFormAwareTrait;
    use EcoleDoctoraleServiceAwareTrait;
    use UniteRechercheServiceAwareTrait;


    /** @var PhpRenderer */
    private $renderer;
@@ -160,4 +169,39 @@ class CoEncadrantController extends AbstractActionController {
        ]);
        $export->export('justificatif_coencadrement_' . $coencadrant->getIndividu()->getId() . ".pdf");
    }

    public function genererExportCsvAction()
    {
        $structureType = $this->params()->fromRoute('structure-type');
        $structureId = $this->params()->fromRoute('structure-id');

        /** @var EcoleDoctorale|UniteRecherche $structure */
        $structure = null;
        if ($structureType === 'ecole-doctorale') $structure = $this->getEcoleDoctoraleService()->getRepository()->find($structureId);
        if ($structureType === 'unite-recherche') $structure = $this->getUniteRechercheService()->getRepository()->find($structureId);

        $listing = $this->getCoEncadrantService()->getCoEncadrantsByStructureConcrete($structure);

        //export
        $headers = ['Co-endrants', 'Nombre d\'encadrements actuels', 'Listing'];
        $records = [];
        foreach ($listing as $item) {
            $entry = [];
            $entry['Co-endrants'] = $item['co-encadrant']->getIndividu()->getPrenom1() . " " . $item['co-encadrant']->getIndividu()->getNomUsuel();
            $entry['Nombre d\'encadrements actuels'] = count($item['theses']);
            $entry['Listing'] = implode(';',
                array_map(function(These $t) {return $t->getDoctorant()->getIndividu()->getPrenom1() . " " . $t->getDoctorant()->getIndividu()->getNomUsuel();}, $item['theses'])
            );
            $records[] = $entry;
        }
        $filename = (new DateTime())->format('Ymd-His') . '_coencadrants-' . $structure->getSigle() . 'csv';
        $CSV = new CsvModel();
        $CSV->setDelimiter(';');
        $CSV->setEnclosure('"');
        $CSV->setHeader($headers);
        $CSV->setData($records);
        $CSV->setFilename($filename);

        return $CSV;
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ class EcoleDoctoraleController extends StructureConcreteController
    {
        $id = $this->params()->fromRoute('structure');
        $structureConcrete = $this->getStructureConcreteService()->getRepository()->findByStructureId($id);
        $coencadrants = $this->getCoEncadrantService()->getCoEncadrantsByEcodeDoctorale($structureConcrete);
        $coencadrants = $this->getCoEncadrantService()->getCoEncadrantsByStructureConcrete($structureConcrete);

        $viewModel = parent::informationAction();

+8 −0
Original line number Diff line number Diff line
@@ -6,9 +6,11 @@ use Application\Controller\CoEncadrantController;
use Application\Form\RechercherCoEncadrantForm;
use Application\Service\Acteur\ActeurService;
use Application\Service\CoEncadrant\CoEncadrantService;
use Application\Service\EcoleDoctorale\EcoleDoctoraleService;
use Application\Service\File\FileService;
use Application\Service\Individu\IndividuService;
use Application\Service\These\TheseService;
use Application\Service\UniteRecherche\UniteRechercheService;
use Interop\Container\ContainerInterface;
use Zend\View\Renderer\PhpRenderer;

@@ -23,15 +25,19 @@ class CoEncadrantControllerFactory {
        /**
         * @var ActeurService $acteurService
         * @var CoEncadrantService $coEncadrantService
         * @var EcoleDoctoraleService $ecoleDoctoraleService
         * @var IndividuService $individuService
         * @var FileService $fileService
         * @var TheseService $theseService
         * @var UniteRechercheService $uniteRechercheService
         */
        $acteurService = $container->get(ActeurService::class);
        $coEncadrantService = $container->get(CoEncadrantService::class);
        $ecoleDoctoraleService = $container->get(EcoleDoctoraleService::class);
        $individuService = $container->get('IndividuService');
        $fileService = $container->get(FileService::class);
        $theseService = $container->get('TheseService');
        $uniteRechercheService = $container->get(UniteRechercheService::class);

        /**
         * @var RechercherCoEncadrantForm $rechercheCoEncadrantForm
@@ -44,9 +50,11 @@ class CoEncadrantControllerFactory {
        $controller = new CoEncadrantController();
        $controller->setActeurService($acteurService);
        $controller->setCoEncadrantService($coEncadrantService);
        $controller->setEcoleDoctoraleService($ecoleDoctoraleService);
        $controller->setIndividuService($individuService);
        $controller->setFileService($fileService);
        $controller->setTheseService($theseService);
        $controller->setUniteRechercheService($uniteRechercheService);
        $controller->setRechercherCoEncadrantForm($rechercheCoEncadrantForm);
        $controller->setRenderer($renderer);
        return $controller;
+17 −33
Original line number Diff line number Diff line
@@ -73,49 +73,33 @@ class CoEncadrantService {
    }

    /**
     * @param EcoleDoctorale $ecole
     * @param boolean $encours
     * @return Acteur[]
     * @param EcoleDoctorale|UniteRecherche $structure
     * @param bool $encours
     * @return array
     */
    public function getCoEncadrantsByEcodeDoctorale(EcoleDoctorale $ecole, $encours = true)
    public function getCoEncadrantsByStructureConcrete($structure, $encours = true)
    {
        $qb = $this->createQueryBuilder()
            ->addSelect('these')->join('acteur.these', 'these')
            ->andWhere('these.ecoleDoctorale = :ecole')
            ->setParameter('ecole', $ecole)
            ->andWhere('1 = pasHistorise(these)')
            ->andWhere('1 = pasHistorise(acteur)')
        ;
        if ($encours) {
            $qb = $qb->andWhere('these.etatThese = :encours')
                ->setParameter('encours', These::ETAT_EN_COURS)
            ;
        }
        $result = $qb->getQuery()->getResult();

        //todo integer dans la requete
        $grouped = [];
        foreach ($result as $acteur) {
            $grouped[$acteur->getIndividu()->getId()]['co-encadrant'] = $acteur;
            $grouped[$acteur->getIndividu()->getId()]['count']++;
        $structureOk = false;
        if ($structure instanceof EcoleDoctorale) {
            $qb = $qb->andWhere('these.ecoleDoctorale = :structure');
            $structureOk = true;
        }
        return $grouped;
        if ($structure instanceof UniteRecherche) {
            $qb = $qb->andWhere('these.uniteRecherche = :structure');
            $structureOk = true;
        }

    /**
     * @param UniteRecherche $unite
     * @param boolean $encours
     * @return Acteur[]
     */
    public function getCoEncadrantsByUniteRecherche(UniteRecherche $unite, $encours = true)
    {
        $qb = $this->createQueryBuilder()
            ->addSelect('these')->join('acteur.these', 'these')
            ->andWhere('these.uniteRecherche = :unite')
            ->setParameter('unite', $unite)
            ->andWhere('1 = pasHistorise(these)')
            ->andWhere('1 = pasHistorise(acteur)')
        ;
        if ($structureOk === false OR $structure === null) {
            throw new RuntimeException('Pas de structure concrete de trouvée');
        }
        $qb = $qb->setParameter('structure', $structure);

        if ($encours) {
            $qb = $qb->andWhere('these.etatThese = :encours')
                ->setParameter('encours', These::ETAT_EN_COURS)
@@ -127,7 +111,7 @@ class CoEncadrantService {
        $grouped = [];
        foreach ($result as $acteur) {
            $grouped[$acteur->getIndividu()->getId()]['co-encadrant'] = $acteur;
            $grouped[$acteur->getIndividu()->getId()]['count']++;
            $grouped[$acteur->getIndividu()->getId()]['theses'][] = $acteur->getThese();
        }
        return $grouped;
    }
Loading