|
@@ -0,0 +1,75 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace FTTHBundle\EventListener;
|
|
|
+
|
|
|
+use Sonata\AdminBundle\Event\ConfigureEvent;
|
|
|
+use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter;
|
|
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
+
|
|
|
+class ClientFilterListListener
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @var ContainerInterface
|
|
|
+ */
|
|
|
+ protected $container;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * ClientFilterListListener constructor.
|
|
|
+ */
|
|
|
+ public function __construct(ContainerInterface $container)
|
|
|
+ {
|
|
|
+ $this->setContainer($container);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return ContainerInterface
|
|
|
+ */
|
|
|
+ public function getContainer(): ContainerInterface
|
|
|
+ {
|
|
|
+ return $this->container;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ContainerInterface $container
|
|
|
+ */
|
|
|
+ public function setContainer(ContainerInterface $container)
|
|
|
+ {
|
|
|
+ $this->container = $container;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Funcion que verifica si existe la propiedad clientId y agrega un callback para poder filtrar las listas.
|
|
|
+ * @param ConfigureEvent $event
|
|
|
+ */
|
|
|
+ public function configureDatagridFilters(ConfigureEvent $event)
|
|
|
+ {
|
|
|
+ if ($event->getMapper()->has('clientId')) {
|
|
|
+ $order = $event->getMapper()->keys();
|
|
|
+ $event->getMapper()->remove('clientId');
|
|
|
+ $event->getMapper()
|
|
|
+ ->add('clientId', CallbackFilter::class,
|
|
|
+ array(
|
|
|
+ 'callback' => array($this, 'getClientFilter'),
|
|
|
+ 'field_type' => 'text'));
|
|
|
+ $event->getMapper()->reorder($order);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Filtra las ONU por el filtro de clientes.
|
|
|
+ * @param $queryBuilder
|
|
|
+ * @param $alias
|
|
|
+ * @param $field
|
|
|
+ * @param $value
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function getClientFilter($queryBuilder, $alias, $field, $value)
|
|
|
+ {
|
|
|
+ $resp = false;
|
|
|
+ if ($value['value']) {
|
|
|
+ $resp = $this->getContainer()->get('webservice')->getClientFilter($queryBuilder, $alias, $field, $value);
|
|
|
+ }
|
|
|
+ return $resp;
|
|
|
+ }
|
|
|
+}
|