From 6fb6fe6ab11ba617ba0ffdeb0c41fb4dfd31c9f4 Mon Sep 17 00:00:00 2001 From: afornerot Date: Mon, 8 Jun 2020 11:43:17 +0200 Subject: [PATCH] =?UTF-8?q?optimisation=20sur=20selection=20du=20projet=20?= =?UTF-8?q?associ=C3=A9=20=C3=A0=20une=20tache=20(ref=20#138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ProjecttaskController.php | 6 +- .../PortalBundle/Form/ProjecttaskType.php | 60 ++++++++++++------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php index c4046d9b..da155215 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php @@ -28,14 +28,16 @@ class ProjecttaskController extends Controller return $this->createForm(ProjecttaskType::class, $entity, [ "mode" => "update", "access" => $access, - "user" => $this->getUser() + "user" => $this->getUser(), + "projecttask" => $entity ]); } else { return $this->createForm(ProjecttaskType::class, $entity, [ "mode" => "submit", "access" => $access, - "user" => $this->getUser() + "user" => $this->getUser(), + "projecttask" => $entity ]); } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjecttaskType.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjecttaskType.php index c7125fd4..9e8a26f6 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjecttaskType.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjecttaskType.php @@ -23,6 +23,7 @@ class ProjecttaskType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $user=$options['user']; + $projecttask=$options['projecttask']; $builder ->add('submit', SubmitType::class, [ @@ -80,28 +81,46 @@ class ProjecttaskType extends AbstractType ]); } else { - $builder - ->add('project', EntityType::class, [ - 'label' => 'Projet associé', - 'class' => 'CadolesPortalBundle:Project', - 'choice_label' => 'name', - "disabled" => ($options["mode"]=="update"?true:false), - 'placeholder' => '-- Sélectionnez un Projet --', - 'query_builder' => function(EntityRepository $er) use ($user) { - $qb=$er->createQueryBuilder('project'); - return $qb->select('project') - ->where('project.user=:user') - ->orwhere(':user MEMBER OF project.writers') + if(!$projecttask->getProject()) { + $builder + ->add('project', EntityType::class, [ + 'label' => 'Projet associé', + 'class' => 'CadolesPortalBundle:Project', + 'choice_label' => 'name', + "disabled" => ($options["mode"]=="update"?true:false), + 'placeholder' => '-- Sélectionnez un Projet --', + 'query_builder' => function(EntityRepository $er) use ($user) { + $qb=$er->createQueryBuilder('project'); + return $qb->select('project') + ->where('project.user=:user') + ->orwhere(':user MEMBER OF project.writers') - ->from('CadolesCoreBundle:UserGroup','usergroup') - ->orwhere('usergroup.group MEMBER OF project.groups AND usergroup.user=:user') + ->from('CadolesCoreBundle:UserGroup','usergroup') + ->orwhere('usergroup.group MEMBER OF project.groups AND usergroup.user=:user') - ->from('CadolesCoreBundle:User','user') - ->andwhere("user=:user") + ->from('CadolesCoreBundle:User','user') + ->andwhere("user=:user") - ->setparameter('user',$user); - }, - ]); + ->setparameter('user',$user); + }, + ]); + } + else { + $builder + ->add('project', EntityType::class, [ + 'label' => 'Projet associé', + 'class' => 'CadolesPortalBundle:Project', + 'choice_label' => 'name', + "disabled" => ($options["mode"]=="update"?true:false), + 'placeholder' => '-- Sélectionnez un Projet --', + 'query_builder' => function(EntityRepository $er) use ($projecttask) { + $qb=$er->createQueryBuilder('project'); + return $qb->select('project') + ->where('project.id=:project') + ->setparameter('project',$projecttask->getProject()->getId()); + }, + ]); + } } $builder->add('user', @@ -133,7 +152,8 @@ class ProjecttaskType extends AbstractType 'data_class' => 'Cadoles\PortalBundle\Entity\Projecttask', 'mode' => 'string', 'access' => 'string', - 'user' => 'Cadoles\CoreBundle\Entity\User' + 'user' => 'Cadoles\CoreBundle\Entity\User', + 'projecttask' => 'Cadoles\PortalBundle\Entity\Projecttask' ]); } }