Commit 99586522 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Tri des statuts en place

Correction d'un bug au niveau du ParametreEntityListener
parent df97094e
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -1833,12 +1833,12 @@
            "source": {
                "type": "git",
                "url": "https://github.com/laminas/laminas-cache-storage-adapter-memory.git",
                "reference": "7dfdd263ce9b318b4476c0a0fea059169f42fd44"
                "reference": "e99380bf735559e69770da7f4fc69cb6525cd00f"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/laminas/laminas-cache-storage-adapter-memory/zipball/7dfdd263ce9b318b4476c0a0fea059169f42fd44",
                "reference": "7dfdd263ce9b318b4476c0a0fea059169f42fd44",
                "url": "https://api.github.com/repos/laminas/laminas-cache-storage-adapter-memory/zipball/e99380bf735559e69770da7f4fc69cb6525cd00f",
                "reference": "e99380bf735559e69770da7f4fc69cb6525cd00f",
                "shasum": ""
            },
            "require": {
@@ -1891,7 +1891,7 @@
                    "type": "community_bridge"
                }
            ],
            "time": "2021-12-06T20:27:17+00:00"
            "time": "2022-02-28T20:15:47+00:00"
        },
        {
            "name": "laminas/laminas-cache-storage-deprecated-factory",
@@ -5043,25 +5043,29 @@
        },
        {
            "name": "myclabs/deep-copy",
            "version": "1.10.2",
            "version": "1.10.3",
            "source": {
                "type": "git",
                "url": "https://github.com/myclabs/DeepCopy.git",
                "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220"
                "reference": "c6a951b75d684fd43fbbd69617488e1e2e8924ba"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220",
                "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220",
                "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/c6a951b75d684fd43fbbd69617488e1e2e8924ba",
                "reference": "c6a951b75d684fd43fbbd69617488e1e2e8924ba",
                "shasum": ""
            },
            "require": {
                "php": "^7.1 || ^8.0"
            },
            "conflict": {
                "doctrine/collections": "<1.6.8",
                "doctrine/common": "<2.13.3 || >=3,<3.2.2"
            },
            "require-dev": {
                "doctrine/collections": "^1.0",
                "doctrine/common": "^2.6",
                "phpunit/phpunit": "^7.1"
                "doctrine/collections": "^1.6.8",
                "doctrine/common": "^2.13.3 || ^3.2.2",
                "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
            },
            "type": "library",
            "autoload": {
@@ -5086,7 +5090,7 @@
            ],
            "support": {
                "issues": "https://github.com/myclabs/DeepCopy/issues",
                "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2"
                "source": "https://github.com/myclabs/DeepCopy/tree/1.10.3"
            },
            "funding": [
                {
@@ -5094,7 +5098,7 @@
                    "type": "tidelift"
                }
            ],
            "time": "2020-11-13T09:40:50+00:00"
            "time": "2022-03-02T14:16:47+00:00"
        },
        {
            "name": "nikic/php-parser",
@@ -5625,12 +5629,12 @@
                }
            },
            "autoload": {
                "psr-4": {
                    "Ramsey\\Uuid\\": "src/"
                },
                "files": [
                    "src/functions.php"
                ]
                ],
                "psr-4": {
                    "Ramsey\\Uuid\\": "src/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ class ParametreEntityListener implements EventSubscriber
        $this->args     = $args;
        $this->em       = $args->getEntityManager();
        $this->entity   = $args->getEntity();
        $this->key      = [];
        $this->metadata = $this->em->getClassMetadata(get_class($this->entity));
        $this->hydrator = new ClassMethodsHydrator();
        $this->hydrator->setUnderscoreSeparatedKeys(false);
+22 −10
Original line number Diff line number Diff line
@@ -61,10 +61,10 @@ class StatutController extends AbstractController
        $form = $this->getFormStatutSaisie();

        if (empty($statut)) {
            $title  = 'Création d\'un nouveau statut d\'intervenant';
            $title  = 'Ajout d\'un nouveau statut';
            $statut = $this->getServiceStatut()->newEntity();
        } else {
            $title = 'Édition d\'un statut d\'intervenant';
            $title = $statut->getLibelle();
        }

        $canEdit = $this->isAllowed($statut, Privileges::INTERVENANT_STATUT_EDITION);
@@ -150,22 +150,34 @@ class StatutController extends AbstractController

    public function trierAction()
    {
        $champsIds = explode(',', $this->params()->fromPost('champsIds', ''));
        $this->em()->getFilters()->enable('historique')->init([
            Statut::class,
        ]);
        $this->em()->getFilters()->enable('annee')->init([
            Statut::class,
        ]);

        $statuts = $this->getServiceStatut()->getList();
        $ids     = $this->params()->fromPost('ids');

        $ordre = $this->getServiceStatut()->fetchMaxOrdre() + 1; // Pour éviter tout doublon!!
        foreach ($champsIds as $champId) {
            $si = $this->getServiceStatut()->get($champId);
            if ($si) {
                $si->setOrdre($ordre);
                $ordre++;

        foreach ($ids as $id) {
            $statut = $statuts[$id] ?? null;
            if ($statut) {
                $statut->setOrdre($ordre++);
                try {
                    $this->getServiceStatut()->save($si);
                    $this->getServiceStatut()->save($statut);
                } catch (\Exception $e) {
                    $this->flashMessenger()->addErrorMessage($this->translate($e));
                }
            }
        }
        if (!$this->flashMessenger()->hasErrorMessages()) {
            $this->flashMessenger()->addSuccessMessage('Le tri a été pris en compte');
        }

        return new JsonModel(['msg' => 'Tri des champs effectué']);
        return new MessengerViewModel();
    }

}
+35 −60
Original line number Diff line number Diff line
@@ -17,85 +17,60 @@ $this->headTitle()->append($title = "Statuts des intervenants");

?>
<h1 class="page-header"><?php echo $title ?></h1>

<div class="resultats"></div>
<div>
    <?php foreach ($typesIntervenants as $typeIntervenant): ?>
        <h3><?= $typeIntervenant ?></h3>
    <table class="table table-bordered table-hover table-condensed">
        <head>
            <tr>
                <th style="width:25%">Code</th>
                <th style="width:65%">Libellé</th>
        <?php
        echo $this->tag('div', ['style' => 'padding-left: 3em;padding-right:3em']);
        echo $this->tag('div', ['class' => 'list-group statuts']);
        foreach ($statuts as $s) {
            if ($s->getTypeIntervenant() == $typeIntervenant) {
                ?>
                <div class="list-group-item statut" data-id="<?= $s->getId() ?>">
                    <a href="<?= $this->url('statut/saisie', ['statut' => $s->getId()]) ?>">
                        <?= $s ?>
                    </a>
                    <?php if ($canEdit): ?>
                    <th style="width:1%">Actions</th>
                        <i class="fas fa-arrows-up-down pull-right" title="Vous pouvez trier les statuts en déplaçant les lignes"></i>
                    <?php endif; ?>
            </tr>
        </head>
        <body>
        <?php foreach ($statuts as $statut): if ($statut->getTypeIntervenant() == $typeIntervenant): ?>
            <tr class="statut" data-id="<?= $statut->getId() ?>">
                <td><?= $statut->getCode() ?></td>
                <td><?= $statut->getLibelle() ?></td>
                <?php if ($canEdit): ?>
                    <th style="text-align: center">
                        <a href="<?= $this->url('statut/saisie', ['statut' => $statut->getId()]) ?>" title="Modifier le statut">
                            <i class="fas fa-pen-to-square"></i>
                        </a>
                </div>
                <?php
            }
        }

                        <a class="pop-ajax"
                           href="<?= $this->url('statut/delete', ['statut' => $statut->getId()]) ?>"
                           title="Supprimer le statut"
                           data-content="<p class='lead text-danger'><strong>Attention!</strong> Confirmez-vous cette suppression ?</p>"
                           data-confirm="true"
                           data-confirm-button="Oui"
                           data-cancel-button="Non"
                           data-submit-reload="true"
                        >
                            <i class="fas fa-trash-can"></i>
                        </a>
        echo '</div></div>';
        ?>

                        <a role="button" data-toggle="collapse" title="Vous pouvez trier les statuts en déplaçant les lignes">
                            <i class="fas fa-arrows-up-down-left-right"></i>
                        </a>
                    </th>
                <?php endif; ?>
            </tr>
        <?php endif; endforeach; ?>
        </body>
    </table>
    <?php endforeach; ?>
</div>

<?php if ($canEdit): ?>
    <a class="btn btn-primary" href="<?= $this->url('statut/saisie') ?>" title="Ajouter un statut">
        <i class="fas fa-plus"></i> Ajouter un statut
        <span class="fas fa-plus"></span> Ajouter un statut
    </a>

    <script type="text/javascript">
        $(function () {
            function injecte(element)
            {
                var ancre = '#c_' + $(element).data('id');
                var ti = $(element).data('id');
                adr = "<?php echo $this->url('statut/saisie') ?>" + "/" + ti;
                $(ancre).load(adr);
            }

            $(function () {
                $(".triables").sortable({
                    handle: '.glyphicon-move',
        $(".statuts").sortable({
            handle: '.fa-arrows-up-down',
            axis: 'y',
            update: function (event, ui) {
                        var champsIds = '';
                        ui.item.parent().find('div.champ-triable').each(function () {
                            if (champsIds != '') champsIds += ',';
                            console.log($(this)[0]['id']);
                            champsIds += $(this)[0]['id'];
                        });
                        $.post(Url('statut/trier'), {champsIds: champsIds}).done(function (res) {
                            alertFlash(res.msg, 'success', 3000);
                var ids = [];
                $(".statuts .statut").each(function () {
                    ids.push($(this).data('id'));
                });
                $('.resultats').html('<div class="alert alert-info"><span class="loading">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> Tri en cours ...</div>');
                $.ajax({
                    type: 'POST',
                    url: "<?= $this->url('statut/trier')?>",
                    data: {ids: ids},
                    success: function (res) {
                        $('.resultats').html(res);
                    }
                });
            }
        });
        });

    </script>
<?php endif; ?>
+13 −6
Original line number Diff line number Diff line
@@ -9,17 +9,18 @@ use Application\Provider\Privilege\Privileges;
 * @var $statuts           \Intervenant\Entity\Db\Statut[]
 * @var $statut            \Intervenant\Entity\Db\Statut
 * @var $form              \Intervenant\Form\StatutSaisieForm
 * @var $title             string
 */

$this->headTitle()->append($title = "Modification d'un statut d'intervenant");

echo $this->tag('h1')->text($title);
$this->headTitle()->append($title);

echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formElement($form->get('security'));
echo $this->messenger()->addCurrentMessagesFromFlashMessenger();

$canAdd = $this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_STATUT_EDITION));

?>

<div class="row">
@@ -32,14 +33,21 @@ echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
                if ($s->getTypeIntervenant() == $typeIntervenant) {
                    $url    = $this->url('statut/saisie', ['statut' => $s->getId()]);
                    $active = $s == $statut ? ' active' : '';
                    echo $this->tag('a', ['class' => 'list-group-item' . $active, 'href' => $url])->text($s) . "\n";
                    echo $this->tag('a', ['class' => 'list-group-item' . $active, 'href' => $url])->html($s) . "\n";
                }
            }
            echo '</div>';
        }
        ?>
        <?php if ($canAdd): ?>
            <a class="btn btn-primary" href="<?= $this->url('statut/saisie') ?>" title="Ajouter un statut">
                <span class="fas fa-plus"></span> Ajouter un statut
            </a>
        <?php endif; ?>
    </div>
    <div class="col-md-9">
        <h1><?= $title ?></h1>

        <!-- Informations générales -->
        <div class="panel panel-default">
            <div class="panel-heading">Informations générales</div>
@@ -353,7 +361,6 @@ echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
            {
                return this.element.find('[name=' + name + ']');
            }
        })
        ;
        });
    });
</script>
 No newline at end of file