<?php
namespace AdminBundle\Admin\Vidi;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
class ResumeAdmin extends AbstractAdmin
{
protected $baseRouteName = 'vidi-resume';
protected $baseRoutePattern = 'vidi-resume';
protected Security $security;
public function setContainerServices(Security $security): void
{
$this->security = $security;
}
/**
* @param RouteCollectionInterface $collection
*/
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->remove('view');
$collection->remove('create');
$collection->remove('edit');
$collection->add('download', $this->getBaseRouteName(). '/');
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('vacancy.title', null, [
'label' => 'Название вакансии'
])
->add('name', null, [
'label' => 'Имя'
])
->add('phone', null, [
'label' => 'Телефон'
])
->add('email', null)
->add('cv', 'url', [
'route' => [
'name' => 'dc.vacancy.resume.download',
'identifier_parameter_name' => 'id',
],
])
;
}
public function configureQuery($context = 'list'): ProxyQueryInterface
{
$User = $this->security->getUser();
if(!$User->getDealer()) {
throw new AccessDeniedException('User without dealer');
}
$query = parent::configureQuery($context);
$query->andWhere(
$query->expr()->isNull($query->getRootAliases()[0] . '.dealer')
);
return $query;
}
}