Completed
Pull Request — 3.1 (#348)
by Piotr
20:24
created

Subscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 84
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getClassName() 0 4 1
A initDataGrid() 0 32 1
A initDataSource() 0 36 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FSi\FixturesBundle\Admin;
6
7
use FSi\Bundle\AdminBundle\Doctrine\Admin\ListElement;
8
use FSi\Component\DataGrid\DataGridFactoryInterface;
9
use FSi\Component\DataGrid\DataGridInterface;
10
use FSi\Component\DataSource\DataSourceFactoryInterface;
11
use FSi\Component\DataSource\DataSourceInterface;
12
use FSi\FixturesBundle\Entity;
13
use Symfony\Component\Form\Extension\Core\Type\EmailType;
14
15
class Subscriber extends ListElement
16
{
17
    const ID = 'subscriber';
18
19
    public function getId(): string
20
    {
21
        return self::ID;
22
    }
23
24
    public function getClassName(): string
25
    {
26
        return Entity\Subscriber::class;
27
    }
28
29
    protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface
30
    {
31
        $datagrid = $factory->createDataGrid($this->getId());
32
        $datagrid->addColumn('batch', 'batch', [
33
            'actions' => [
34
                [
35
                    'element' => 'subscriber_delete',
36
                    'label' => 'crud.list.batch.delete'
37
                ]
38
            ]
39
        ]);
40
        $datagrid->addColumn('email', 'text', [
41
            'label' => 'admin.subscriber.list.email',
42
            'editable' => true,
43
            'form_type' => [
44
                'email' => EmailType::class
45
            ]
46
        ]);
47
        $datagrid->addColumn('active', 'boolean', [
48
            'label' => 'admin.subscriber.list.active'
49
        ]);
50
        $datagrid->addColumn('created_at', 'datetime', [
51
            'label' => 'admin.subscriber.list.created_at'
52
        ]);
53
        $datagrid->addColumn('actions', 'action', [
54
            'label' => 'admin.subscriber.list.actions',
55
            'field_mapping' => ['id'],
56
            'actions' => ['edit' => ['element' => 'subscriber_form']]
57
        ]);
58
59
        return $datagrid;
60
    }
61
62
    protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface
63
    {
64
        $datasource = $factory->createDataSource(
65
            'doctrine-orm',
66
            ['entity' => $this->getClassName()],
67
            $this->getId()
68
        );
69
        $datasource->addField('email', 'text', 'like', [
70
            'sortable' => true,
71
            'form_options' => [
72
                'label' => 'admin.subscriber.list.email',
73
            ]
74
        ]);
75
        $datasource->addField('created_at', 'date', 'between', [
76
            'field' => 'createdAt',
77
            'sortable' => true,
78
            'form_from_options' => [
79
                'widget' => 'single_text',
80
                'label' => 'admin.subscriber.list.created_at_from',
81
            ],
82
            'form_to_options' => [
83
                'widget' => 'single_text',
84
                'label' => 'admin.subscriber.list.created_at_to',
85
            ]
86
        ]);
87
        $datasource->addField('active', 'boolean', 'eq', [
88
            'sortable' => false,
89
            'form_options' => [
90
                'label' => 'admin.subscriber.list.active',
91
            ]
92
        ]);
93
94
        $datasource->setMaxResults(10);
95
96
        return $datasource;
97
    }
98
}
99