Passed
Pull Request — master (#494)
by Andrew
04:59
created

PromoCodeAdmin::preUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Stfalcon\Bundle\EventBundle\Admin;
4
5
use A2lix\TranslationFormBundle\Util\GedmoTranslatable;
6
use Sonata\AdminBundle\Admin\Admin;
7
use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
use Sonata\AdminBundle\Form\FormMapper;
9
use Sonata\AdminBundle\Datagrid\ListMapper;
10
use Stfalcon\Bundle\EventBundle\Admin\AbstractClass\AbstractTranslateAdmin;
11
12
/**
13
 * Class PromoCodeAdmin.
14
 */
15
class PromoCodeAdmin extends AbstractTranslateAdmin
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $datagridValues =
21
        [
22
            '_page' => 1,
23
            '_sort_order' => 'DESC',
24
            '_sort_by' => 'id',
25
        ];
26
27
    /**
28
     * @param ListMapper $listMapper
29
     */
30
    protected function configureListFields(ListMapper $listMapper)
31
    {
32
        $listMapper
33
            ->addIdentifier('title', null, ['label' => 'Название'])
34
            ->add('discountAmount', null, ['label' => 'Скидка (%)'])
35
            ->add('code', null, ['label' => 'Код'])
36
            ->add('event', null, ['label' => 'Событие'])
37
            ->add('used', null, ['label' => 'Использований'])
38
            ->add('endDate', null, ['label' => 'Дата окончания']);
39
    }
40
41
    /**
42
     * @param FormMapper $formMapper
43
     */
44
    protected function configureFormFields(FormMapper $formMapper)
45
    {
46
        $localsRequiredService = $this->getConfigurationPool()->getContainer()->get('application_default.sonata.locales.required');
47
        $localOptions = $localsRequiredService->getLocalsRequiredArray();
48
        $datetimePickerOptions =
49
            [
50
                'format' => 'dd.MM.y',
51
            ];
52
        $formMapper
53
            ->with('Переводы')
54
                ->add('translations', 'a2lix_translations_gedmo', [
55
                    'label' => 'Переводы',
56
                    'translatable_class' => $this->getClass(),
57
                    'fields' => [
58
                        'title' => [
59
                            'label' => 'Название',
60
                            'locale_options' => $localOptions,
61
                        ],
62
                    ],
63
                ])
64
            ->end()
65
            ->with('Общие')
66
                ->add('discountAmount', null, ['required' => true, 'label' => 'Скидка (%)'])
67
                ->add('code', null, ['label' => 'Код'])
68
                ->add('event', null, [
69
                    'label' => 'Событие',
70
                    'required' => true,
71
                    'placeholder' => 'Choose event',
72
                ])
73
                ->add('maxUseCount', null, ['label' => 'Максимальное количество использований', 'help' => '(0 - безлимитный)'])
74
                ->add(
75
                    'endDate',
76
                    'sonata_type_date_picker',
77
                    array_merge(
78
                        [
79
                            'required' => true,
80
                            'label' => 'Дата окончания',
81
                        ],
82
                        $datetimePickerOptions
83
                    )
84
                )
85
            ->end();
86
    }
87
88
    /**
89
     * @param DatagridMapper $datagridMapper
90
     */
91
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
92
    {
93
        $datagridMapper->add('event');
94
    }
95
}
96