|
@@ -3,11 +3,14 @@
|
|
|
namespace HostBundle\Admin;
|
|
|
|
|
|
use Base\AdminBundle\Admin\BaseAdmin;
|
|
|
+use Doctrine\ORM\EntityRepository;
|
|
|
+use HostBundle\Entity\Host ;
|
|
|
use HostBundle\Utils\HostStatus;
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper;
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper;
|
|
|
use Sonata\AdminBundle\Form\FormMapper;
|
|
|
use Sonata\AdminBundle\Show\ShowMapper;
|
|
|
+use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
|
|
|
|
class HostAdmin extends BaseAdmin
|
|
@@ -19,8 +22,24 @@ class HostAdmin extends BaseAdmin
|
|
|
{
|
|
|
$datagridMapper
|
|
|
->add('mac')
|
|
|
- ->add('state')
|
|
|
- ;
|
|
|
+ ->add('hostType')
|
|
|
+ ->add('state', 'doctrine_orm_choice', [], 'choice', [
|
|
|
+ 'choices' => HostStatus::getChoices(),
|
|
|
+ ])
|
|
|
+ ->add('options', 'doctrine_orm_callback', [
|
|
|
+ 'callback' => function($queryBuilder, $alias, $field, $value) {
|
|
|
+ if (!$value['value']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $queryBuilder
|
|
|
+ ->andWhere("{$alias}.options LIKE :fixed_address")
|
|
|
+ ->setParameter('fixed_address', "%\"fixed_address\":\"{$value['value']}%");
|
|
|
+
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ 'label' => 'filter.label_options_fixed_address',
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -32,6 +51,8 @@ class HostAdmin extends BaseAdmin
|
|
|
->add('mac')
|
|
|
->add('hostType')
|
|
|
->add('state')
|
|
|
+ ->add('options.fixed_address')
|
|
|
+ ->add('host')
|
|
|
->add('_action', null, array(
|
|
|
'actions' => array(
|
|
|
'show' => array(),
|
|
@@ -47,6 +68,8 @@ class HostAdmin extends BaseAdmin
|
|
|
*/
|
|
|
protected function configureFormFields(FormMapper $formMapper)
|
|
|
{
|
|
|
+ $subject = $this->getSubject();
|
|
|
+
|
|
|
$formMapper
|
|
|
->tab('Host')
|
|
|
->with('Host')
|
|
@@ -58,6 +81,23 @@ class HostAdmin extends BaseAdmin
|
|
|
'choices' => HostStatus::getChoices(),
|
|
|
'translation_domain' => 'HostBundle',
|
|
|
])
|
|
|
+ ->add('host', EntityType::class, [
|
|
|
+ 'class' => Host::class,
|
|
|
+ 'query_builder' => function (EntityRepository $er) use ($subject) {
|
|
|
+ $qb = $er->createQueryBuilder('Host')
|
|
|
+ ->join('Host.hostType', 'HostType')
|
|
|
+ ->andWhere('HostType.name = \'Cablemodem\'')
|
|
|
+ ->orderBy('Host.mac', 'ASC');
|
|
|
+
|
|
|
+ $mac = $subject->getMac();
|
|
|
+ if ($mac) {
|
|
|
+ $qb->andWhere('Host.mac <> :mac')->setParameter('mac', $mac);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $qb;
|
|
|
+ },
|
|
|
+ 'required' => false,
|
|
|
+ ])
|
|
|
->end()
|
|
|
->end()
|
|
|
;
|
|
@@ -74,6 +114,7 @@ class HostAdmin extends BaseAdmin
|
|
|
->add('mac')
|
|
|
->add('hostType')
|
|
|
->add('state')
|
|
|
+ ->add('host')
|
|
|
->end()
|
|
|
->end()
|
|
|
;
|