From eebe65bb762a4256ac9945d3e1e939b905af46dd Mon Sep 17 00:00:00 2001
From: Antony Le Courtes <antony.lecourtes@unicaen.fr>
Date: Wed, 18 Nov 2020 16:58:51 +0100
Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20m=C3=A9thode=20=C3=A0=20WfEtape?=
 =?UTF-8?q?Service.php=20qui=20renvoie=20un=20element=20zend=20form=20sele?=
 =?UTF-8?q?ct=20multiple=20avec=20boostrap=20select=20pour=20choisir=20les?=
 =?UTF-8?q?=20=C3=A9tapes=20du=20worflow=20n=C3=A9cessaires.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Application/Service/WfEtapeService.php    | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/module/Application/src/Application/Service/WfEtapeService.php b/module/Application/src/Application/Service/WfEtapeService.php
index 2146f09cbe..01ca9efa49 100755
--- a/module/Application/src/Application/Service/WfEtapeService.php
+++ b/module/Application/src/Application/Service/WfEtapeService.php
@@ -4,6 +4,7 @@ namespace Application\Service;
 
 use Application\Entity\Db\WfEtape;
 use Doctrine\ORM\QueryBuilder;
+use Zend\Form\Element\Select;
 
 
 /**
@@ -59,10 +60,47 @@ class WfEtapeService extends AbstractEntityService
      */
     public function orderBy(QueryBuilder $qb = null, $alias = null)
     {
-        list($qb, $alias) = $this->initQuery($qb, $alias);
+        [$qb, $alias] = $this->initQuery($qb, $alias);
         $qb->orderBy($alias . '.ordre');
 
         return $qb;
     }
 
+
+
+    /**
+     * @param Collection|null $wfEtapes
+     *
+     * @return Select
+     */
+
+    public function getWfEtapeElement(Collection $wfEtapes = null)
+    {
+        $wfEtapesElement = new Select('select-wfetapes');
+        $wfEtapesElement->setLabel('Liste étapes');
+        $attributes = [
+            'multiple'                  => 'multiple',
+            'class'                     => 'selectpicker',
+            'data-selected-text-format' => 'count',
+            'data-count-selected-text'  => '{0} étape(s) sélectionnée(s)',
+            'data-with'                 => 'auto',
+            'title'                     => 'Choisissez les étapes du workflow devant être validées',
+        ];
+        $wfEtapesElement->setAttributes($attributes);
+
+        $qb = $this->finderByHistorique();
+        $qb->orderBy('ordre', 'ASC');
+        $wfEtapesElement->setValueOptions(\UnicaenApp\Util::collectionAsOptions($this->getList($qb)));
+
+        if ($wfEtapes) {
+            $ids = [];
+            foreach ($wfEtapes as $wfEtape) {
+                $ids[] = $wfEtape->getId();
+            }
+            $wfEtapesElement->setValue($ids);
+        }
+
+        return $wfEtapesElement;
+    }
+
 }
\ No newline at end of file
-- 
GitLab