GroupeprestataireAdmin.php 3.2 KB
Newer Older
Julien Jorry committed
1 2 3 4 5
<?php

namespace App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
Julien Jorry committed
6
use Sonata\AdminBundle\Datagrid\DatagridMapper;
Julien Jorry committed
7 8 9
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
Julien Jorry committed
10 11
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Julien Jorry committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

class GroupeprestataireAdmin extends AbstractAdmin
{
    protected $datagridValues = [
        // reverse order (default = 'ASC')
        '_sort_order' => 'DESC',
        // name of the ordered field (default = the model's id field, if any)
        '_sort_by' => 'updatedAt',
    ];

    /**
    * {@inheritdoc}
    */
    protected function configureShowFields(ShowMapper $showMapper)
    {
    }

    /**
    * {@inheritdoc}
    */
    protected function configureFormFields(FormMapper $formMapper)
    {
Julien Jorry committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        $groupepresta = $this->getSubject();
        $formMapper
            ->add('name', TextType::class, array(
                'label' => 'Nom du groupe :',
                'required' => true
            ))
            ->add('enabled', CheckboxType::class, array(
                'label' => 'Activé ?',
                'required' => false,
                'label_attr' => array('class' => 'checkbox-inline')
            ))
        ;
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        // $datagridMapper
        //     ->add('phone')
        //     ->add('email', null, [
        //         'show_filter' => true
        //     ])
        // ;
Julien Jorry committed
56 57 58 59 60 61 62
    }

    /**
    * {@inheritdoc}
    */
    protected function configureListFields(ListMapper $listMapper)
    {
Julien Jorry committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76
        unset($this->listModes['mosaic']);
        $listMapper
            ->addIdentifier('name', null, array('label' => 'Nom du groupe'))
            ->add(
                'getPrestatairesCount',
                null,
                [
                    '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
77
    }
Julien Jorry committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

    // @TODO : NE FONCTIONNE PAS : pour pouvoir classer par nombre de prestataires !
    // voir https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/297
    // public function createQuery($context = 'list')
    // {
    //     $query = parent::createQuery($context);
    //     if ('list' === $context) {
    //         $rootAlias = $query->getRootAliases()[0];
    //         $parameters = $this->getFilterParameters();
    //         if ('getPrestatairesCount' === $parameters['_sort_by']) {
    //             $query->select('o', 'DISTINCT o');
    //             $query
    //                 ->leftJoin($rootAlias.'.prestataires', 'gpr')
    //                 // ->leftJoin('groupes_prestataires.prestataires', 'pr')
    //                 ->groupBy($rootAlias.'.id')
    //                 ->orderBy('COUNT(gpr.id)', $parameters['_sort_order'])
    //             ;
    //         }
    //     }
    //     return $query;
    // }
Julien Jorry committed
99
}