mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
add an "active" field on activity type
This commit is contained in:
@@ -114,7 +114,8 @@ class ActivityType extends AbstractType
|
||||
'required' => false
|
||||
))
|
||||
->add('type', TranslatableActivityType::class, array(
|
||||
'placeholder' => 'Choose a type'
|
||||
'placeholder' => 'Choose a type',
|
||||
'active_only' => true
|
||||
))
|
||||
;
|
||||
|
||||
|
@@ -4,7 +4,8 @@ namespace Chill\ActivityBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
class ActivityTypeType extends AbstractType
|
||||
{
|
||||
@@ -16,13 +17,20 @@ class ActivityTypeType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('name', 'translatable_string')
|
||||
;
|
||||
->add('active', ChoiceType::class, array(
|
||||
'choices' => array(
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
'expanded' => true
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\ActivityBundle\Entity\ActivityType'
|
||||
|
@@ -65,30 +65,27 @@ class TranslatableActivityType extends AbstractType
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options) {
|
||||
/* @var $qb \Doctrine\ORM\QueryBuilder */
|
||||
$qb = $options['query_builder'];
|
||||
|
||||
if ($options['active_only'] === true) {
|
||||
$qb->where($qb->expr()->eq('at.active', ':active'));
|
||||
$qb->setParameter('active', true, \Doctrine\DBAL\Types\Type::BOOLEAN);
|
||||
}
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
// create a local copy for use in closures
|
||||
$translatableStringHelper = $this->translatableStringHelper;
|
||||
$types = $this->activityTypeRepository->findAll();
|
||||
|
||||
// sort by alphabetical order
|
||||
usort($types, function(ActivityType $typeA, ActivityType $typeB) use ($translatableStringHelper) {
|
||||
$strA = $translatableStringHelper->localize($typeA->getName());
|
||||
$strB = $translatableStringHelper->localize($typeB->getName());
|
||||
|
||||
if ($strA === $strB) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $strA < $strB ? -1 : 1;
|
||||
});
|
||||
|
||||
$resolver->setDefaults(
|
||||
array(
|
||||
'class' => 'ChillActivityBundle:ActivityType',
|
||||
'choices' => $types,
|
||||
'choice_label' => function (ActivityType $type) use ($translatableStringHelper) {
|
||||
return $translatableStringHelper->localize($type->getName());
|
||||
'active_only' => true,
|
||||
'query_builder' => $this->activityTypeRepository
|
||||
->createQueryBuilder('at'),
|
||||
'choice_label' => function (ActivityType $type) {
|
||||
return $this->translatableStringHelper->localize($type->getName());
|
||||
}
|
||||
)
|
||||
);
|
||||
|
Reference in New Issue
Block a user