<?php
namespace AdminBundle\Admin\SubAutoSite;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
/**
* Class InnerMailAdmin
* @package AdminBundle\Admin\SubAutoSite
*/
class InnerMailAdmin extends BaseImporterAdmin
{
/**
* @param RouteCollection $collection
*/
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->remove('view');
$collection->remove('delete');
}
/**
* @param $object
*/
public function prePersist($object): void
{
$dealer = $this->security->getUser()->getSubDealer();
$object->setDealer($dealer);
}
/**
* @param string $context
* @return ProxyQueryInterface
*/
public function configureQuery($context = 'list'): ProxyQueryInterface
{
$user = $this->security->getUser();
$dealer = $user->getSubDealer();
$query = parent::configureQuery($context);
$query->andWhere(
$query->expr()->eq($query->getRootAliases()[0] . '.dealer', ':dealer')
);
$query->setParameter('dealer', $dealer);
return $query;
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper
->add('dealer', null, ['admin_code' => 'admin.sub.contact'])
->add('_action', null, [
'actions' => [
'edit' => [],
],
])
;
}
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper): void
{
$options = [
'required' => false,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false,
];
$formMapper
->with(' ', ['class' => 'col-md-4'])
->add('serviceType', CollectionType::class, array_merge($options, ['label' => 'Запис на сервіс']))
->add('sparePartsType', CollectionType::class, array_merge($options, ['label' => 'Замовлення запчастин']))
->add('orderType', CollectionType::class, array_merge($options, ['label' => 'Заявка на купівлю ТЗ']))
->end()
->with(' ', ['class' => 'col-md-4'])
->add('questionType', CollectionType::class, array_merge($options, ['label' => 'Зворотний зв\'язок']))
->add('creditType', CollectionType::class, array_merge($options, ['label' => 'Консультація щодо кредиту']))
->add('insuranceType', CollectionType::class, array_merge($options, ['label' => 'Консультація щодо страхування']))
->end()
->with(' ', ['class' => 'col-md-4'])
->add('commisionType', CollectionType::class, array_merge($options, ['label' => 'Заявка техніки на комісію']))
->add('testDriveType', CollectionType::class, array_merge($options, ['label' => 'Заявка на тест-драйв']))
->add('accessoriesType', CollectionType::class, array_merge($options, ['label' => 'Заявка аксессуарів']))
->end()
;
}
}