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

Ajout de l'index des UR oublié

parent 3d85e338
Loading
Loading
Loading
Loading
+2 −31
Changes for module/Application/src/Application/Controller/UniteRechercheController.php: 2 added lines, 31 removed lines.
Original line number Diff line number Diff line
@@ -35,32 +35,12 @@ class UniteRechercheController extends AbstractController
     */
    public function indexAction()
    {
        $selected = $this->params()->fromQuery('selected');

        $roles = null;
        $effectifs = null;
        $structure = null;
        if ($selected) {
            /**
             * @var StructureConcreteInterface $structure
             * @var Role[] $roles
             */
            $selectedStructure  = $this->getUniteRechercheService()->getRepository()->findByStructureId($selected);
            $roles = $selectedStructure->getStructure()->getStructureDependantRoles();

            $effectifs = [];
            foreach ($roles as $role) {
                $individus = $this->individuService->getRepository()->findByRole($role);
                $effectifs[$role->getLibelle()] = $individus;
            }
        }

        $structuresAll = $this->getUniteRechercheService()->getRepository()->findAll();

        /** retrait des structures substituées */
        //TODO faire cela dans le service ???
        $structuresSub = array_filter($structuresAll, function (StructureConcreteInterface $structure) { return count($structure->getStructure()->getStructuresSubstituees())!=0; });
        $toRemove = [];
        /** @var UniteRecherche $structure */
        foreach($structuresSub as $structure) {
            foreach ($structure->getStructure()->getStructuresSubstituees() as $sub) {
                $toRemove[] = $sub;
@@ -74,18 +54,9 @@ class UniteRechercheController extends AbstractController
            }
            if (!$found) $structures[] = $structure;
        }
        $rattachements = null;
        if ($selectedStructure !== null) $rattachements = $this->getUniteRechercheService()->findEtablissementRattachement($selectedStructure);
        $domaines = null;
        if ($selectedStructure !== null) $domaines = $selectedStructure->getDomaines();

        return new ViewModel([
            'structuresPrincipales'          => $structures,
            'selected'                       => $selected,
            'roles'                          => $roles,
            'effectifs'                      => $effectifs,
            'rattachements'                  => $rattachements,
            'domaines'                       => $domaines,
            'unites'                         => $structures,
        ]);
    }

+24 −233
Changes for module/Application/view/application/unite-recherche/index.phtml: 24 added lines, 233 removed lines.
Original line number Diff line number Diff line
<?php

use Application\Entity\Db\DomaineScientifique;
use Application\Entity\Db\EtablissementRattachement;
use Application\Entity\Db\StructureConcreteInterface;
use Application\Filter\EtablissementPrefixFilter;
use Application\Entity\Db\UniteRecherche;
use Application\Provider\Privilege\UniteRecherchePrivileges;
use Application\View\Renderer\PhpRenderer;
use UnicaenApp\Form\Element\SearchAndSelect;

/**
 * @see \Application\Controller\EcoleDoctoraleController::indexAction()
 * @var PhpRenderer $this
 * @var StructureConcreteInterface[] $structuresPrincipales
 * @var string      $selected
 * @var array|null  $etablissementIndividus
 * @var UniteRecherche[] $unites
 */

$canModifier = $this->isAllowed(UniteRecherchePrivileges::getResourceId(UniteRecherchePrivileges::UNITE_RECH_MODIFICATION));

?>


<?php $this->headTitle($this->translate("Unités de recherche")) ?>

<h1 class="page-header first">
    <?php echo $this->translate("Unités de recherche") ?>
    <span class="badge"><?php echo count($structuresPrincipales); ?></span>
    <span class="badge"><?php echo count($unites); ?></span>
</h1>

<?php echo $this->messenger()->addCurrentMessagesFromFlashMessenger() ?>
<?php echo $this->messenger()->addMessagesFromFlashMessengerWithNoNamespace() ?>

<?php if ($canModifier): ?>

    <a href="<?php echo $this->url('unite-recherche/ajouter', [], [], true) ?>"
       class="btn btn-default btn-sm"
       class="btn btn-primary"
       title="<?php echo $this->translate("Créer une nouvelle unité de recherche");?>">
        <span class="glyphicon glyphicon-plus"></span>
        <?php echo $this->translate("Ajouter une nouvelle unité de recherche");?>
@@ -49,258 +46,52 @@ $canModifier = $this->isAllowed(UniteRecherchePrivileges::getResourceId(UniteRec
        </tr>
        </thead>
        <tbody>
        <?php foreach($structuresPrincipales as $structure): ?>
        <?php foreach($unites as $unite): ?>

            <?php
            $historisee = (!$structure->estNonHistorise());
            $hasSousStructure = !($structure->getStructure()->getStructuresSubstituees()->isEmpty());
            $historisee = (!$unite->estNonHistorise());
            $hasSousStructure = !($unite->getStructure()->getStructuresSubstituees()->isEmpty());
            ?>
            <tr <?php if($selected == $structure->getStructure()->getId()) echo 'class="ecole-doctorale selected" style="color:black;"';?> >

            <tr>
                <td>
                    <a name="<?php echo $structure->getStructure()->getId();?>">
                    <a href="<?php echo $this->url('unite-recherche', [], ['query' => ['selected' => $structure->getStructure()->getId()], "fragment" => "".$structure->getStructure()->getId()], true); ?>">
                        <?php echo $structure->getLibelle(); ?>
                    <a href="<?php echo $this->url('unite-recherche/information', ['uniteRecherche' => $unite->getStructure()->getId()], [], true); ?>">
                        <?php echo $unite->getLibelle(); ?>
                    </a>
                </td>
                <td> <?php echo explode("::",$structure->getSource()->getCode())[0]; ?></td>
                <td>
                    <?php
                        $result = $structure->getCode();
                        try {
                            $filter = new EtablissementPrefixFilter();
                            $result = $filter->removePrefixFrom($result);
                        } catch (LogicException $e) {}
                        echo $result;
                    ?>
                    <?php echo explode("::",$unite->getSource()->getCode())[0]; ?>
                </td>
                <td> <?php echo $structure->getSigle(); ?></td>
                <td>
                    <?php echo $unite->getCode(); ?>
                </td>
                <td> <?php echo $unite->getSigle(); ?> </td>
                <td>
                    <?php if ($canModifier && !$historisee) : ?>
                        <a href="<?php echo $this->url('unite-recherche/modifier', ["uniteRecherche" => $structure->getStructure()->getId()], [], true); ?>"
                           title="Modifier l'établissement">
                            <span class="glyphicon glyphicon-pencil"></span>
                        </a>
                    <?php endif; ?>

                    <?php if ($canModifier && !$historisee) : ?>
                        <a href="<?php echo $this->url('unite-recherche/supprimer', ["uniteRecherche" => $structure->getStructure()->getId()], [], true); ?>"
                        <a href="<?php echo $this->url('unite-recherche/supprimer', ["uniteRecherche" => $unite->getStructure()->getId()], [], true); ?>"
                           title="Historiser l'établissement">
                            <span class="glyphicon glyphicon-trash"></span>
                        </a>
                    <?php endif; ?>

                    <?php if ($canModifier && !$historisee && $hasSousStructure) : ?>
                        <a href="<?php echo $this->url('substitution-modifier', ['cible' => $structure->getStructure()->getId(), [], true]); ?>"
                        <a href="<?php echo $this->url('substitution-modifier', ['cible' => $unite->getStructure()->getId(), [], true]); ?>"
                           title="Historiser l'établissement">
                            <span class="glyphicon glyphicon-link" title="Éditer la substitution"></span>
                        </a>
                    <?php endif; ?>

                    <?php if ($canModifier && $historisee) : ?>
                        <a href="<?php echo $this->url('unite-recherche/restaurer', ["uniteRecherche" => $structure->getStructure()->getId()], [], true); ?>"
                        <a href="<?php echo $this->url('unite-recherche/restaurer', ["uniteRecherche" => $unite->getStructure()->getId()], [], true); ?>"
                           title="Restaurer l'établissement">
                            Restaurer
                        </a>
                    <?php endif; ?>
                </td>
            </tr>
            <?php if ($selected == $structure->getStructure()->getId() && !$historisee): ?>
                <tr class="ecole-doctorale selected" style="color:black;">
                    <td colspan="3">

                        <h3>
                            Établissements de rattachement
                            <span class="badge"> <?php echo count($rattachements); ?> </span>
                        </h3>
                        <table class="table table-extra-condensed">
                            <thead>
                                <tr>
                                    <th> Libellé de l'établissement de rattachement </th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach($rattachements as $rattachement): ?>
                                    <tr>
                                        <td>
                                            <?php
                                                /** @var EtablissementRattachement $rattachement */
                                                echo $rattachement->getEtablissement()->getLibelle();
                                            ?>
                                        </td>
                                    </tr>
        <?php endforeach; ?>
                            </tbody>
                        </table>

                        <h3>
                            Domaines scientifiques
                            <span class="badge"> <?php echo count($domaines); ?> </span>
                        </h3>
                        <table class="table table-extra-condensed">
                            <thead>
                            <tr>
                                <th> Libellé des domaines scientifiques associés </th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach($domaines as $domaine): ?>
                                <tr>
                                    <td>
                                        <?php
                                        /** @var DomaineScientifique $domaine */
                                        echo $domaine->getLibelle();
                                        ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
        </tbody>
    </table>

                        <div id="selected">
                            Zone contenant les individus associé à la structure.
</div>
 No newline at end of file

                        <div>
                            <div id="people" class="col-md-8">
                                <?php if ($canModifier): ?>
                                    <div>
                                        <!--                            $urlAjouter = $view->url($prefix . '/ajouter-individu', [$type => $structure->getId()], [], true);-->
                                        <form method="post" action="">
                                            <?php
                                            $sas = new SearchAndSelect('individu');
                                            $sas->setLabel($this->translate("Recherche de l'individu à ajouter :"));
                                            $sas->setAttribute('class', 'individu-finder');
                                            $sas->setAutocompleteSource($this->url('utilisateur/rechercher-individu', [], [], true));
                                            echo $this->formcontrolgroup($sas, 'formSearchAndSelect');
                                            echo generateSelect("role", $roles);
                                            ?>
                                            <br/>
                                            <!--                                <input type="submit" value="Ajouter cet individu" style="margin-top: 0;" title="Ajouter cet individu comme membre" class="btn btn-default btn-sm" />-->
                                        </form>
                                        <button id="add-role" class="add-role btn btn-default">
                                            <span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-user"></span>
                                            Ajouter un membre
                                        </button>
                                        <?php if (empty($roles)): ?>
                                            <a
                                                    href="<?php echo $this->url('structure/generer-roles-defauts',
                                                        ['id' => $structure->getStructure()->getId(), 'type' => \Application\Entity\Db\TypeStructure::CODE_UNITE_RECHERCHE], [], true);?>"
                                                    class="btn btn-warning"
                                            >
                                                <span class="glyphicon glyphicon-refresh"></span>
                                                Générer rôles par défaut
                                            </a>
                                        <?php endif; ?>

                                    </div>
                                <?php endif;?>
                            </div>
                            <div id="logo-div" class="col-md-4">
                                <img style="max-width: 200px; max-height: 200px; border: 1px solid black; background-color: white;" src="data:image/png;base64,<?php echo base64_encode($structure->getLogoContent()); ?>" />
                            </div>
                        </div>
                    </td>
                </tr>
            <?php endif; ?>
        <?php endforeach; ?>

        </tbody>
    </table>

    <script>
        $(document).ready(function () {
            loadIndividu();


            $("div#selected").on("click", ".remove-role", function () {
                var id = $(this).attr("id");
                var splits = id.split("_");
                var role = splits[1];
                var individu = splits[0];

                var url = "../../utilisateur/retirer-role/" + individu + "/" + role;

                $.ajax({
                    url: url,
                    beforeSend:
                        function () {
                            $("#selected").html('<span class="waiting">Chargement des individus associé à la structure ...</span>');
                        },
                    success:
                        function(retour) {
                            loadIndividu();
                        }
                });
            });

            $("div#people").on("click", ".add-role", function () {
                var individu = $("[name='individu[id]']").val();
                var role = $("select[name='role'] option:selected").val();
                var url = "../../utilisateur/ajouter-role/" + individu + "/" + role;

                $.ajax({
                    url: url,
                    beforeSend:
                        function () {
                            $("#selected").html('<span class="waiting">Chargement des individus associé à la structure ...</span>');
                        },
                    success:
                        function(retour) {
                            loadIndividu();
                        }
                });
            });
        });


        function loadIndividu() {
            var url = "../structure/individu-role/" + <?php echo $selected; ?> + "/etablissement";
            $.ajax({
                url : url,
                beforeSend:
                    function () {
                        $("#selected").html('<span class="waiting">Chargement des individus associé à la structure ...</span>');
                    },
                success:
                    function(retour){
                        $("#selected").html(retour);
                    }
            });
        }

    </script>

    <style>
        span.waiting {
            color: DarkBlue;
            font-style: italic;
            font-weight: bold;
        }
    </style>

    <?php
    function generateSelect($id, $roles)
    {
        $texte = '';
        $texte .= '<select name="' . $id . '" class="form-control" >';
        /** @var \Application\Entity\Db\Role $role */
        foreach ($roles as $role) {
            $texte .= '<option value="' . $role->getId() . '">' . $role->getLibelle() . '</option>';
        }
        $texte .= '</select>';
        return $texte;
    }
    ?>

    <!--<script type="text/javascript">-->
    <!--    $(function () {-->
    <!--        $(".retirer-individu").click(function() {-->
    <!--            var individu = $(this).data('individu');-->
    <!--            return confirm("--><?php //echo $this->translate("Êtes-vous sûr-e de vouloir retirer ");?><!--" + "'" + individu + "'" + " " + "--><?php //echo $this->translate("de la liste des membres ?");?><!--");-->
    <!--        }); -->
    <!--        $(".supprimer-etablissement").click(function() {-->
    <!--            var etablissement = $(this).data('etablissement');-->
    <!--            return confirm("--><?php ////echo $this->translate("Êtes-vous sûr-e de vouloir supprimer l'établissement ");?><!--//" + "'" + etablissement + "'" + " ? ");-->
    <!--        });-->
    <!--    });-->
    <!--</script>-->