<?php
namespace AdminBundle\Admin\Insurance;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class ReviewAdmin extends AbstractAdmin
{
/**
* @param RouteCollection $collection
*/
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->remove('delete');
$collection->remove('view');
}
public function toString($object): string
{
return 'Отзыв пользователя '.$object->getUserName();
}
protected function configureFormFields(FormMapper $formMapper): void
{
$formMapper
->with('Отзыв', ['class' => 'col-lg-6'])
->add('state', ChoiceType::class, ['label' => 'Статус', 'choices' => [
'Новый' => 0,
'Опубликован' => 1,
'Отклонен' => 2,
'Комплаєнс' => 3,
]])
->add('user_name', null,['label' => 'Имя пользователя'])
->add('email', null,['label' => 'Email пользователя'])
->add('comment', TextareaType::class,['label' => 'Комментарий'])
->add('response', TextareaType::class,['label' => 'Ответ'])
->end()
->with('Фото', ['class' => 'col-lg-6'])
->add('gallery', ModelListType::class, [
'label' => 'Галерея изображений',
'btn_list' => false,
'required' => false,
], [
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
'link_parameters' => [
'context' => 'insurance',
'provider' => 'sonata.media.provider.image'
],
'admin_code' => 'sonata.media.admin.gallery',
]
)
->end();
}
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper->add('review_type', ChoiceFilter::class, [
'label' => 'Отзывы/Комплаєнс',
'field_type' => ChoiceType::class,
'field_options' => [
'choices' => [
'Отзывы' => 0,
'Комплаєнс' => 1,
],
'expanded' => false,
'multiple' => false,
],
]);
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('user_name', null,['label' => 'Имя пользователя'])
->add('email', null,['label' => 'Email пользователя'])
->add('date_create', null,['label' => 'Дата создания'])
->add('state','choice', ['label' => 'Статус', 'editable' => true, 'choices' => [
0 => 'Новый',
1 => 'Опубликован',
2 => 'Отклонен',
3 => 'Комплаєнс',
]])
->add('_action', 'actions', [
'label' => 'Действия',
'actions' => [
'edit' => [],
'print' => [
'template' => '@AdminBundle/CRUD/list__action_print_sticker.html.twig'
],
]
])
;
}
}