<?php
namespace AdminBundle\Admin\Insurance;
use DateTime;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Contracts\Translation\TranslatorInterface;
class PayoutsAdmin extends AbstractAdmin
{
protected TranslatorInterface $translator;
public function setContainerServices(TranslatorInterface $translator): void
{
$this->translator = $translator;
}
protected function configureFormFields(FormMapper $formMapper): void
{
$month = [];
for($i = 1; $i <= 12; $i ++) {
$month[$i] = $this->translator->trans('date.mh_'.$i,[],'core','ru');
}
$nowYear = (new DateTime())->format('Y');
$years = [
$nowYear => $nowYear,
$nowYear-1 => $nowYear-1,
$nowYear-2 => $nowYear-2,
];
$formMapper
->with('Информация о страховом деле', ['class' => 'col-lg-6'])
->add('month', ChoiceType::class, ['label' => 'Месяц', 'choices' => array_flip($month)])
->add('year', ChoiceType::class, ['label' => 'Год', 'choices' => $years])
->add('amount', TextType::class, ['label' => 'Сумма'])
->end();
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$month = [];
for($i = 1; $i <= 12; $i ++) {
$month[$i] = $this->translator->trans('date.mh_'.$i,[],'core','ru');
}
$nowYear = (new DateTime())->format('Y');
$years = [
$nowYear => $nowYear,
$nowYear-1 => $nowYear-1,
$nowYear-2 => $nowYear-2,
];
$listMapper->addIdentifier('id')
->add('month', 'choice', ['label' => 'Месяц', 'choices' => $month])
->add('year', 'choice', ['label' => 'Год', 'choices' => $years])
->add('amount', null, ['label' => 'Сумма'])
->add('_action', 'actions', [
'label' => 'Действия',
'actions' => [
'edit' => [],
]
])
;
}
}