diff --git a/module/Application/src/Application/Processus/Intervenant/ServiceProcessus.php b/module/Application/src/Application/Processus/Intervenant/ServiceProcessus.php index f6db7e5041349736b1e1993c3f47075945cc636c..84f7187bb1344d58113cc714617c2b48374d777a 100644 --- a/module/Application/src/Application/Processus/Intervenant/ServiceProcessus.php +++ b/module/Application/src/Application/Processus/Intervenant/ServiceProcessus.php @@ -4,7 +4,7 @@ namespace Application\Processus\Intervenant; use Application\Entity\Db\Intervenant; -use Application\Entity\Db\TblService; +use Application\Entity\Db\TypeVolumeHoraire; use Application\Service\Traits\IntervenantServiceAwareTrait; use UnicaenApp\Service\EntityManagerAwareTrait; @@ -14,30 +14,18 @@ class ServiceProcessus use IntervenantServiceAwareTrait; - - public function canPrevuToPrevu(Intervenant $intervenant) + public function canInitializePrevu(Intervenant $intervenant, TypeVolumeHoraire $typeVolumeHoraire) { $intervenant = $this->getServiceIntervenant()->getPrecedent($intervenant); if (!$intervenant) return false; - $dql = " - SELECT - s - FROM - " . TblService::class . " s - JOIN s.typeVolumeHoraire tvh - WHERE - s.intervenant = :intervenant - AND tvh.code = 'PREVU' - AND s.valide > 0 - "; - - $query = $this->getEntityManager()->createQuery($dql)->setMaxResults(1); - $query->setParameters(compact('intervenant')); - $s = $query->getResult(); - - return count($s) > 0; + $sql = "SELECT valide FROM tbl_service WHERE intervenant_id = :intervenant AND type_volume_horaire_id = :typeVolumeHoraire AND valide > 0"; + $res = $this->getEntityManager()->getConnection()->fetchOne($sql, [ + 'intervenant' => $intervenant->getId(), + 'typeVolumeHoraire' => $typeVolumeHoraire->getId(), + ]); + return $res !== false; } } \ No newline at end of file diff --git a/module/Application/src/Application/View/Helper/Service/Liste.php b/module/Application/src/Application/View/Helper/Service/Liste.php index 501e6fa26d49bca132b13bb7cd0e97fdb894b5de..5615b3ba9cc36926df4077636c2dbaa0b387a692 100755 --- a/module/Application/src/Application/View/Helper/Service/Liste.php +++ b/module/Application/src/Application/View/Helper/Service/Liste.php @@ -259,7 +259,8 @@ class Liste extends AbstractViewHelper $out .= '</div>'; $out .= '</div>'; } elseif ($this->prevuToPrevu) { - if ($this->getProcessusIntervenant()->service()->canPrevuToPrevu($this->prevuToPrevu)) { + $typeVolumeHoraire = $this->getServiceTypeVolumeHoraire()->getByCode($this->getServiceParametres()->get('report_service')); + if ($this->getProcessusIntervenant()->service()->canInitializePrevu($this->prevuToPrevu, $typeVolumeHoraire)) { $attribs = [ 'class' => 'btn btn-warning prevu-to-prevu-show', 'data-toggle' => 'modal', @@ -268,7 +269,7 @@ class Liste extends AbstractViewHelper //'href' => $this->getAddUrl(), 'title' => "Initialiser le service prévisionnel avec le service prévisionnel validé l'année dernière", ]; - $source = $this->getServiceTypeVolumeHoraire()->getByCode($this->getServiceParametres()->get('report_service'))->getLibelle(); + $source = $typeVolumeHoraire->getLibelle(); $out .= '<button type="button" ' . $this->htmlAttribs($attribs) . '>' . $source . ' ' . $this->getServiceContext()->getAnneePrecedente() . ' <span class="glyphicon glyphicon-arrow-right"></span> Prévisionnel ' . $this->getServiceContext()->getAnnee() . '</button> '; $out .= '<div class="modal fade" id="prevu-to-prevu-modal" tabindex="-1" role="dialog" aria-hidden="true">'; $out .= '<div class="modal-dialog modal-md">';