GroupeAdmin.php 5.24 KB
Newer Older
Julien Jorry committed
1 2 3 4
<?php

namespace App\Admin;

Julien Jorry committed
5 6
use App\Entity\Comptoir;
use App\Entity\Siege;
7
use FOS\CKEditorBundle\Form\Type\CKEditorType;
Julien Jorry committed
8
use Sonata\AdminBundle\Admin\AbstractAdmin;
9
use Sonata\AdminBundle\Datagrid\DatagridMapper;
Julien Jorry committed
10 11
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
Julien Jorry committed
12
use Sonata\AdminBundle\Route\RouteCollection;
Julien Jorry committed
13
use Sonata\AdminBundle\Show\ShowMapper;
14
use Sonata\FormatterBundle\Form\Type\SimpleFormatterType;
Julien Jorry committed
15 16 17 18 19
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Julien Jorry committed
20

21 22 23 24 25 26
/**
 * Administration des groupes locaux
 *
 * LOCO : Outil de gestion de Monnaie Locale Complémentaire
 * @author Julien Jorry <julien.jorry@gmail.com>
 */
Julien Jorry committed
27 28
class GroupeAdmin extends AbstractAdmin
{
Julien Jorry committed
29 30 31 32 33
    protected $datagridValues = [
        '_sort_order' => 'ASC',
        '_sort_by' => 'name',
    ];

Julien Jorry committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47
    /**
    * {@inheritdoc}
    */
    protected function configureShowFields(ShowMapper $showMapper)
    {
    }

    /**
    * {@inheritdoc}
    */
    protected function configureFormFields(FormMapper $formMapper)
    {
        $groupe = $this->getSubject();
        $formMapper
48
            ->with("Création d'un groupe")
Julien Jorry committed
49 50 51 52 53 54 55 56 57 58
                ->add('siege', HiddenType::class, array(
                    'data' => 1,
                    'data_class' => null,
                    'entity_class' => Siege::class,
                    'em' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager()
                ))
                ->add('name', TextType::class, array(
                    'label' => 'Nom du groupe :',
                    'required' => true
                ))
59 60 61 62
                ->add('content', CKEditorType::class, array(
                    'label' => 'Description :',
                    'required' => false,
                ))
63 64 65 66 67 68
                // ->add('content', SimpleFormatterType::class, [
                //     'format' => 'richhtml',
                //     'ckeditor_context' => 'default',
                //     'label' => 'Description :',
                //     'required' => false,
                // ])
Julien Jorry committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
                ->add('comptoirs', CollectionType::class, array(
                    'label' => 'Comptoirs',
                    'entry_type' => EntityType::class,
                    'entry_options' => array(
                        'class' => Comptoir::class,
                        'choices' =>  $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Comptoir::class)->findAll(),
                        'choice_label' => 'slug',
                        'placeholder' => 'Comptoir',
                        'required' => false,
                        'label' => false),
                    'by_reference' => false,
                    'allow_add' => true,
                    'allow_delete' => true
                ))
                ->add('enabled', CheckboxType::class, array(
                    'label' => 'Activé ?',
                    'required' => false,
                    'label_attr' => array('class' => 'checkbox-inline')
                ))
            ->end()
Julien Jorry committed
89 90 91
        ;
    }

92 93 94 95 96 97 98 99 100 101
    /**
    * {@inheritdoc}
    */
    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
    {
        $datagridMapper
            ->add('enabled')
        ;
    }

Julien Jorry committed
102 103 104 105 106
    protected function configureRoutes(RouteCollection $collection)
    {
        $collection->remove('delete');
    }

Julien Jorry committed
107 108 109 110 111
    /**
    * {@inheritdoc}
    */
    protected function configureListFields(ListMapper $listMapper)
    {
Julien Jorry committed
112 113 114
        unset($this->listModes['mosaic']);
        $listMapper
            ->addIdentifier('name', null, array('label' => 'Nom du groupe'))
Julien Jorry committed
115
            ->addIdentifier('gestionnaires', null, array('label' => 'Gestionnaires'))
116
            ->addIdentifier('content', 'html', array('truncate' => array('length' => 80), 'label' => 'Description'))
117
            ->addIdentifier('compte', null, array('label' => 'Solde'))
Julien Jorry committed
118 119 120 121 122 123 124 125 126
            ->add(
                'getPrestatairesCount',
                null,
                [
                    'label' => 'Nb prestataires',
                    'sortable' => true,
                    'sort_field_mapping' => ['fieldName' => 'id'],
                    'sort_parent_association_mappings' => [],
                ]
127 128 129 130 131 132 133 134 135
            )->add(
                'getAdherentsCount',
                null,
                [
                    'label' => 'Nb adherents',
                    'sortable' => true,
                    'sort_field_mapping' => ['fieldName' => 'id'],
                    'sort_parent_association_mappings' => [],
                ]
Julien Jorry committed
136 137 138 139 140 141 142 143 144 145 146 147 148
            )
            ->add(
                'getComptoirsCount',
                null,
                [
                    'label' => 'Nb comptoirs',
                    'sortable' => true,
                    'sort_field_mapping' => ['fieldName' => 'id'],
                    'sort_parent_association_mappings' => [],
                ]
            )
            ->addIdentifier('enabled', null, array('label' => 'Activé', 'datatype' => 'App.Groupeprestataire', 'template' => '@SonataAdmin/Boolean/editable_boolean.html.twig'))
        ;
Julien Jorry committed
149 150
    }
}