resolution lenteur sur submit/update blogarticle (ref #180)

This commit is contained in:
afornerot 2020-09-16 09:58:57 +02:00
parent 936b6810b0
commit cb5b98237d
2 changed files with 44 additions and 22 deletions

View File

@ -26,14 +26,16 @@ class BlogarticleController extends Controller
return $this->createForm(BlogarticleType::class, $entity, [ return $this->createForm(BlogarticleType::class, $entity, [
"mode" => "update", "mode" => "update",
"access" => $access, "access" => $access,
"user" => $this->getUser() "user" => $this->getUser(),
'blogarticle' => $entity,
]); ]);
} }
else { else {
return $this->createForm(BlogarticleType::class, $entity, [ return $this->createForm(BlogarticleType::class, $entity, [
"mode" => "submit", "mode" => "submit",
"access" => $access, "access" => $access,
"user" => $this->getUser() "user" => $this->getUser(),
'blogarticle' => $entity,
]); ]);
} }
} }

View File

@ -21,6 +21,7 @@ class BlogarticleType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$user=$options['user']; $user=$options['user'];
$blogarticle=$options['blogarticle'];
$builder $builder
->add('submit', SubmitType::class, [ ->add('submit', SubmitType::class, [
@ -60,29 +61,47 @@ class BlogarticleType extends AbstractType
]); ]);
} }
else { else {
$builder if(!$blogarticle->getBlog()) {
->add('blog', EntityType::class, [ $builder
'label' => 'Blog associé', ->add('blog', EntityType::class, [
'class' => 'CadolesPortalBundle:Blog', 'label' => 'Blog associé',
'choice_label' => 'name', 'class' => 'CadolesPortalBundle:Blog',
'placeholder' => '-- Sélectionnez un Blog --', 'choice_label' => 'name',
'query_builder' => function(EntityRepository $er) use ($user) { 'placeholder' => '-- Sélectionnez un Blog --',
$qb=$er->createQueryBuilder('blog'); 'query_builder' => function(EntityRepository $er) use ($user) {
return $qb->select('blog') $qb=$er->createQueryBuilder('blog');
->where('blog.user=:user') return $qb->select('blog')
->orwhere(':user MEMBER OF blog.writers') ->where('blog.user=:user')
->orwhere(':user MEMBER OF blog.writers')
->from('CadolesCoreBundle:UserGroup','usergroup') ->from('CadolesCoreBundle:UserGroup','usergroup')
->orwhere('usergroup.group MEMBER OF blog.groups AND usergroup.user=:user AND usergroup.fgmanager=:flag') ->orwhere('usergroup.group MEMBER OF blog.groups AND usergroup.user=:user AND usergroup.fgmanager=:flag')
->from('CadolesCoreBundle:User','user') ->from('CadolesCoreBundle:User','user')
->andwhere("user=:user") ->andwhere("user=:user")
->setparameter('user',$user) ->setparameter('user',$user)
->setparameter('flag',true); ->setparameter('flag',true);
}, },
]); ]);
}
else {
$builder
->add('blog', EntityType::class, [
'label' => 'Blog associé',
'class' => 'CadolesPortalBundle:Blog',
'choice_label' => 'name',
"disabled" => ($options["mode"]=="update"?true:false),
'placeholder' => '-- Sélectionnez un Blog --',
'query_builder' => function(EntityRepository $er) use ($blogarticle) {
$qb=$er->createQueryBuilder('blog');
return $qb->select('blog')
->where('blog.id=:blog')
->setparameter('blog',$blogarticle->getBlog()->getId());
},
]);
}
} }
} }
@ -92,7 +111,8 @@ class BlogarticleType extends AbstractType
'data_class' => 'Cadoles\PortalBundle\Entity\Blogarticle', 'data_class' => 'Cadoles\PortalBundle\Entity\Blogarticle',
'mode' => 'string', 'mode' => 'string',
'access' => 'string', 'access' => 'string',
'user' => 'Cadoles\CoreBundle\Entity\User' 'user' => 'Cadoles\CoreBundle\Entity\User',
'blogarticle' => 'Cadoles\PortalBundle\Entity\Blogarticle'
]); ]);
} }
} }