From 0a15c86a9d5696193c113090aee0e6839bc94e9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr>
Date: Fri, 19 Jun 2020 17:11:02 +0200
Subject: [PATCH] =?UTF-8?q?Possibilit=C3=A9=20de=20dupliquer,=20am=C3=A9li?=
 =?UTF-8?q?oration=20de=20la=20pr=C3=A9cision=20de=20la=20recherche?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 code/test4.php                                |  5 +++-
 .../Application/config/intervenant.config.php | 16 +++++++++--
 .../Controller/IntervenantController.php      | 18 ++++++++----
 .../Controller/RechercheController.php        | 28 ++++++++++++-------
 .../src/Application/Entity/Db/Intervenant.php | 13 +++++++++
 .../Service/ServiceReferentielService.php     |  2 +-
 .../Intervenant/IntervenantViewHelper.php     |  2 +-
 7 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/code/test4.php b/code/test4.php
index 400c3bc0c5..dfce9d745f 100755
--- a/code/test4.php
+++ b/code/test4.php
@@ -9,4 +9,7 @@
  */
 
 
-return $controller->redirect()->toRoute('intervenant/voir', ['intervenant' => 51987], ['query' => ['tab' => 'edition']]);
\ No newline at end of file
+/* @var $intervenant \Application\Entity\Db\Intervenant */
+$intervenant = $container->get(\Application\Service\IntervenantService::class)->get(578);
+
+$ni = $intervenant->dupliquer();
\ No newline at end of file
diff --git a/module/Application/config/intervenant.config.php b/module/Application/config/intervenant.config.php
index ebb1de2d09..960139d6a3 100755
--- a/module/Application/config/intervenant.config.php
+++ b/module/Application/config/intervenant.config.php
@@ -62,7 +62,8 @@ return [
                         'options' => [
                             'route'    => '/creer',
                             'defaults' => [
-                                'action' => 'saisir',
+                                'action'        => 'saisir',
+                                'action-detail' => 'creer',
                             ],
                         ],
                     ],
@@ -71,7 +72,18 @@ return [
                         'options' => [
                             'route'    => '/:intervenant/saisir',
                             'defaults' => [
-                                'action' => 'saisir',
+                                'action'        => 'saisir',
+                                'action-detail' => 'saisir',
+                            ],
+                        ],
+                    ],
+                    'dupliquer'               => [
+                        'type'    => 'Segment',
+                        'options' => [
+                            'route'    => '/:intervenant/dupliquer',
+                            'defaults' => [
+                                'action'        => 'saisir',
+                                'action-detail' => 'dupliquer',
                             ],
                         ],
                     ],
diff --git a/module/Application/src/Application/Controller/IntervenantController.php b/module/Application/src/Application/Controller/IntervenantController.php
index 95aa21d362..e9d6d3974c 100755
--- a/module/Application/src/Application/Controller/IntervenantController.php
+++ b/module/Application/src/Application/Controller/IntervenantController.php
@@ -261,11 +261,12 @@ class  IntervenantController extends AbstractController
 
     public function saisirAction()
     {
-        $role        = $this->getServiceContext()->getSelectedIdentityRole();
-        $intervenant = $role->getIntervenant() ?: $this->getEvent()->getParam('intervenant');
-        $title       = "Saisie d'un intervenant";
-        $form        = $this->getFormIntervenantEdition();
-        $errors      = [];
+        $role         = $this->getServiceContext()->getSelectedIdentityRole();
+        $intervenant  = $role->getIntervenant() ?: $this->getEvent()->getParam('intervenant');
+        $title        = "Saisie d'un intervenant";
+        $form         = $this->getFormIntervenantEdition();
+        $errors       = [];
+        $actionDetail = $this->params()->fromRoute('action-detail');
 
         $isNew = !$intervenant;
         if (!$intervenant) {
@@ -277,6 +278,13 @@ class  IntervenantController extends AbstractController
             $intervenant->setCode(uniqid('OSE'));
         }
 
+        if ($actionDetail == 'dupliquer') {
+            $intervenant = $intervenant->dupliquer();
+            $intervenant->setSource($this->getServiceSource()->getOse());
+            $intervenant->setSourceCode(null);
+            $intervenant->setStatut($this->getServiceStatutIntervenant()->getAutres());
+        }
+
         $canEdit = $this->isAllowed($intervenant, Privileges::INTERVENANT_EDITION);
         $form->setReadOnly(!$canEdit);
         $form->bind($intervenant);
diff --git a/module/Application/src/Application/Controller/RechercheController.php b/module/Application/src/Application/Controller/RechercheController.php
index 50b7189a4a..55e80d5519 100755
--- a/module/Application/src/Application/Controller/RechercheController.php
+++ b/module/Application/src/Application/Controller/RechercheController.php
@@ -28,19 +28,27 @@ class RechercheController extends AbstractController
 
         $result = [];
         foreach ($res as $key => $r) {
-            $feminin = $r['civilite'] != 'Monsieur';
-
-            $civilite        = $feminin ? 'M<sup>me</sup>' : 'M.';
-            $nom             = strtoupper($r['nom']);
-            $prenom          = ucfirst($r['prenom']);
-            $naissance       = 'né' . ($feminin ? 'e' : '') . ' le ' . $r['date-naissance']->format(Constants::DATE_FORMAT);
-            $numeroPersonnel = 'N°' . $r['numero-personnel'];
-            $structure       = $r['structure'];
+            $feminin = $r['civilite'] == 'Madame';
+
+            $details = [];
+            if ($r['civilite']) {
+                $details['civilite'] = $feminin ? 'M<sup>me</sup>' : 'M.';
+            }
+            $details['nom']       = strtoupper($r['nom']);
+            $details['prenom']    = ucfirst($r['prenom']);
+            $details['naissance'] = 'né' . ($feminin ? 'e' : '') . ' le ' . $r['date-naissance']->format(Constants::DATE_FORMAT);
+            $details['code']      = 'N°' . $r['numero-personnel'];
+            if ($r['structure']) {
+                $details['structure'] = $r['structure'];
+            }
+            if ($r['statut']) {
+                $details['statut'] = $r['statut'];
+            }
 
             $result[$key] = [
                 'id'    => $key,
-                'label' => "$nom $prenom",
-                'extra' => "<small>($civilite, $naissance, $numeroPersonnel, $structure)</small>",
+                'label' => $details['nom'] . ' ' . $details['prenom'],
+                'extra' => "<small>(" . implode(', ', $details) . ")</small>",
             ];
         }
 
diff --git a/module/Application/src/Application/Entity/Db/Intervenant.php b/module/Application/src/Application/Entity/Db/Intervenant.php
index e988d0e262..52f91a5139 100755
--- a/module/Application/src/Application/Entity/Db/Intervenant.php
+++ b/module/Application/src/Application/Entity/Db/Intervenant.php
@@ -18,6 +18,7 @@ use UnicaenApp\Entity\HistoriqueAwareTrait;
 use UnicaenApp\Service\EntityManagerAwareTrait;
 use UnicaenImport\Entity\Db\Interfaces\ImportAwareInterface;
 use UnicaenImport\Entity\Db\Traits\ImportAwareTrait;
+use Zend\Hydrator\ClassMethods;
 use Zend\Permissions\Acl\Resource\ResourceInterface;
 
 /**
@@ -1386,4 +1387,16 @@ class Intervenant implements HistoriqueAwareInterface, ResourceInterface, Import
         return $validations;
     }
 
+
+
+    public function dupliquer()
+    {
+        $intervenant = new Intervenant();
+
+        $hydrator = new ClassMethods();
+        $data     = $hydrator->extract($this);
+        $hydrator->hydrate($data, $intervenant);
+
+        return $intervenant;
+    }
 }
diff --git a/module/Application/src/Application/Service/ServiceReferentielService.php b/module/Application/src/Application/Service/ServiceReferentielService.php
index 245b0878bb..4de63723f3 100755
--- a/module/Application/src/Application/Service/ServiceReferentielService.php
+++ b/module/Application/src/Application/Service/ServiceReferentielService.php
@@ -379,7 +379,7 @@ class ServiceReferentielService extends AbstractEntityService
         $tvhPrevu  = $this->getServiceTypeVolumeHoraire()->getPrevu();
         $evhValide = $this->getServiceEtatVolumeHoraire()->getSaisi();
 
-        $intervenantPrec = $this->getServiceIntervenant()->getPrecedent();
+        $intervenantPrec = $this->getServiceIntervenant()->getPrecedent($intervenant);
 
         $sVolumeHoraireReferentiel = $this->getServiceVolumeHoraireReferentiel();
 
diff --git a/module/Application/src/Application/View/Helper/Intervenant/IntervenantViewHelper.php b/module/Application/src/Application/View/Helper/Intervenant/IntervenantViewHelper.php
index 3676b0887c..010f23cfd5 100755
--- a/module/Application/src/Application/View/Helper/Intervenant/IntervenantViewHelper.php
+++ b/module/Application/src/Application/View/Helper/Intervenant/IntervenantViewHelper.php
@@ -172,7 +172,7 @@ class IntervenantViewHelper extends AbstractHtmlElement
                         <?php endforeach; ?>
                         <?php if ($canAddIntervenant): ?>
                             <li class="ajout-intervenant">
-                                <a href="<?= $this->getView()->url('intervenant/voir', ['intervenant' => $intervenantId]); ?>"
+                                <a href="<?= $this->getView()->url('intervenant/dupliquer', ['intervenant' => $intervenantId]); ?>"
                                    title="Ajout d'un nouveau statut à l'intervenant"><span
                                             class="glyphicon glyphicon-plus"></span></a>
                             </li>
-- 
GitLab