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, [
"mode" => "update",
"access" => $access,
"user" => $this->getUser()
"user" => $this->getUser(),
'blogarticle' => $entity,
]);
}
else {
return $this->createForm(BlogarticleType::class, $entity, [
"mode" => "submit",
"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)
{
$user=$options['user'];
$blogarticle=$options['blogarticle'];
$builder
->add('submit', SubmitType::class, [
@ -60,29 +61,47 @@ class BlogarticleType extends AbstractType
]);
}
else {
$builder
->add('blog', EntityType::class, [
'label' => 'Blog associé',
'class' => 'CadolesPortalBundle:Blog',
'choice_label' => 'name',
'placeholder' => '-- Sélectionnez un Blog --',
'query_builder' => function(EntityRepository $er) use ($user) {
$qb=$er->createQueryBuilder('blog');
return $qb->select('blog')
->where('blog.user=:user')
->orwhere(':user MEMBER OF blog.writers')
if(!$blogarticle->getBlog()) {
$builder
->add('blog', EntityType::class, [
'label' => 'Blog associé',
'class' => 'CadolesPortalBundle:Blog',
'choice_label' => 'name',
'placeholder' => '-- Sélectionnez un Blog --',
'query_builder' => function(EntityRepository $er) use ($user) {
$qb=$er->createQueryBuilder('blog');
return $qb->select('blog')
->where('blog.user=:user')
->orwhere(':user MEMBER OF blog.writers')
->from('CadolesCoreBundle:UserGroup','usergroup')
->orwhere('usergroup.group MEMBER OF blog.groups AND usergroup.user=:user AND usergroup.fgmanager=:flag')
->from('CadolesCoreBundle:UserGroup','usergroup')
->orwhere('usergroup.group MEMBER OF blog.groups AND usergroup.user=:user AND usergroup.fgmanager=:flag')
->from('CadolesCoreBundle:User','user')
->andwhere("user=:user")
->from('CadolesCoreBundle:User','user')
->andwhere("user=:user")
->setparameter('user',$user)
->setparameter('flag',true);
->setparameter('user',$user)
->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',
'mode' => 'string',
'access' => 'string',
'user' => 'Cadoles\CoreBundle\Entity\User'
'user' => 'Cadoles\CoreBundle\Entity\User',
'blogarticle' => 'Cadoles\PortalBundle\Entity\Blogarticle'
]);
}
}