ClientAdmin::toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
c 1
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace ClientBundle\Admin;
4
5
use Sonata\AdminBundle\Admin\AbstractAdmin;
6
use Sonata\AdminBundle\Datagrid\ListMapper;
7
use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
use Sonata\AdminBundle\Form\FormMapper;
9
use ClientBundle\Entity\Client;
10
11
/**
12
 * Class ClientAdmin
13
 */
14
class ClientAdmin extends AbstractAdmin
15
{
16
    /**
17
     * @param mixed $object
18
     * @return string
19
     */
20
    public function toString($object)
21
    {
22
        return $object instanceof Client
23
            ? $object->getDisplayName()
24
            : 'Client';
25
    }
26
27
    protected function configureRoutes(\Sonata\AdminBundle\Route\RouteCollection $collection)
28
    {
29
    }
30
31
    protected function configureFormFields(FormMapper $formMapper)
32
    {
33
        $formMapper
34
            ->with('дати', array('class' => 'col-md-4'))
35
                ->add('createdAt', 'date', ['widget' => 'text', 'required' => false, 'format' => 'd M y', 'disabled' => true])
36
                ->add('birthday', 'birthday', ['format' => 'd M y', 'placeholder' => 'd m y', 'widget' => 'text', 'required' => false])
37
            ->end()
38
            ->with('фіо', array('class' => 'col-md-8'))
39
                ->add('firstname', 'text')
40
                ->add('surname', 'text', ['required' => false])
41
            ->end()
42
            ->add('description', 'text', ['required' => false])
43
            ->add('categories', 'sonata_type_model', ['multiple' => true, 'required' => false])
44
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
            ->add('categories','entity', array(
46
                'class' => 'ClientBundle:Category',
47
                'choice_label' => 'name',
48
                'multiple' => true,
49
                'required' => false
50
                ))
51
*/
52
            ->add('language', 'sonata_type_model', ['multiple' => false])
53
            ->add('contacts', 'sonata_type_model', ['multiple' => true, 'required' => false]);
54
    }
55
56
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
57
    {
58
        $datagridMapper
59
            ->add('createdAt', null, array(), 'date', array('format' => 'd M y' ))
60
            ->add('firstname')
61
            ->add('surname')
62
            ->add('birthday', null, array(), 'birthday', array('widget' => 'text', 'format' => 'd M y' ))
63
            ->add('categories', null, array(), 'entity', null, array(
64
                'class' => 'ClientBundle:Category',
65
                'choice_label' => 'name',
66
            ))
67
            ->add('language', null, array(), 'entity', null, ['class' => 'ClientBundle:Lang', 'choice_label' => 'name']);
68
    }
69
70
    protected function configureListFields(ListMapper $listMapper)
71
    {
72
        $listMapper
73
            ->add('createdAt', 'date', ['format' => 'd-m-Y'])
74
            ->addIdentifier('getDisplayName')
75
            ->add('language.name')
76
        ;
77
    }
78
}
79