소스 검색

Merge branch 'master' of ssh://gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/Webservice into FD3-247

Luciano Andrade 7 년 전
부모
커밋
7a2a535083

+ 23 - 16
Form/ChoiceList/Loader/ClientChoiceLoader.php

@@ -92,25 +92,28 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
      */
     public function loadChoiceList($value = null)
     {
-        $choices = $this->getChoicesList(false);
+        $choices = array();
+        if (empty($this->selected)) {
+            $choices = $this->getChoicesList(false);
 
-        $missing_choices = array_flip($this->selected);
+            $missing_choices = array_flip($this->selected);
 
-        foreach ($choices as $label => $id) {
-            if (isset($missing_choices[$id])) {
-                unset($missing_choices[$id]);
+            foreach ($choices as $label => $id) {
+                if (isset($missing_choices[$id])) {
+                    unset($missing_choices[$id]);
+                }
             }
-        }
 
-        // Now add selected choices if they're missing
-        foreach (array_keys($missing_choices) as $id) {
-            $label = $this->getChoiceLabel($id);
+            // Now add selected choices if they're missing
+            foreach (array_keys($missing_choices) as $id) {
+                $label = $this->getChoiceLabel($id);
 
-            if (strlen($label) === 0) {
-                continue;
-            }
+                if (strlen($label) === 0) {
+                    continue;
+                }
 
-            $choices[$label] = $id;
+                $choices[$label] = $id;
+            }
         }
 
         return new ArrayChoiceList($choices);
@@ -195,9 +198,13 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
      */
     protected function choiceExists($id)
     {
-        $label = array_search($id, $this->initChoices(array("id" => $id)));
-
-        return $label === false ? false : true;
+        if (!is_null($id)) {
+            $label = array_search($id, $this->initChoices(array("id" => $id)));
+            
+            return $label === false ? false : true;
+        }
+        
+        return false;
     }
 
     /**

+ 9 - 0
Resources/views/Type/remote_client_widget.html.twig

@@ -2,6 +2,12 @@
     {% spaceless %}
 
         {% set locale = app.request.locale %}
+        {# SE AGREGA UNA VERSION DE SELECT2 MAS NUEVA QUE LA DE SONATA ADMIN #}
+        <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
+        <link href="{{ asset('bundles/baseadmin/vendor/select2/select2.css') }}" rel="stylesheet" />
+        <link href="{{ asset('bundles/baseadmin/vendor/select2-bootstrap-css/select2-bootstrap.css') }}" rel="stylesheet" />
+        <script src="{{ asset('bundles/baseadmin/vendor/select2/select2.min.js') }}"></script>
+        <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/i18n/{{ locale }}.js"></script>
 
         <script type="text/javascript">
         $(function () {
@@ -20,7 +26,10 @@
             {% set ajax_url = 'ajax_client_list' %}
         {% endif %}
 
+
             $('select[id$="{{ id }}"]').select2({
+                theme: "bootstrap",
+                width: '100%',
                 ajax: {
                     url: '{{ path(ajax_url) }}',
                     dataType: 'json',

+ 17 - 7
Services/Webservice.php

@@ -41,6 +41,8 @@ class Webservice
     }
 
     /**
+     * Retorna el resultado para utilizar en un choice form field
+     * 
      * @param string $webservice
      * @param array $params
      *
@@ -60,6 +62,8 @@ class Webservice
     }
 
     /**
+     * Retorna el resultado como un array
+     * 
      * @param string $webservice
      * @param array $params
      *
@@ -69,15 +73,12 @@ class Webservice
     {
         $results = array();
         if ($this->serviceContainer->hasParameter($webservice)) {
-            $url = $this->serviceContainer->getParameter($webservice);
-            $url .= '?filters[qb-criteria]';
-            foreach ($params as $param => $value) {
-                $url .= "&filters[{$param}]=$value";
-            }
             try {
+                // Por defecto agrega filters[qb-criteria] y limit=20
+                $url = $this->buildUrl($webservice, $params, true);
                 $results = json_decode($this->makeGetRequest($url), true);
             } catch (\Exception $ex) {
-
+                var_dump($ex->getMessage());
             }
         }
 
@@ -140,6 +141,8 @@ class Webservice
     }
 
     /**
+     * Similar a getArray pero con mas parametros
+     * 
      * @param string $url
      * @param array $filters
      * @param array $order_by
@@ -162,6 +165,8 @@ class Webservice
     }
 
     /**
+     *  Similar a getData pero la request no hace authentication
+     * 
      * @param string $url
      * @param array $filters
      * @param array $order_by
@@ -188,10 +193,11 @@ class Webservice
      * @param array $order_by
      * @param int $limit
      * @param int $offset
+     * @param boolean $qbCriteria
      *
      * @return string
      */
-    public function buildUrl($webservice, $filters = array(), $order_by = array(), $limit = null, $offset = null)
+    public function buildUrl($webservice, $filters = array(), $qbCriteria = false, $order_by = array(), $limit = 20, $offset = null)
     {
         $url = $webservice . '?';
         if ($this->serviceContainer->hasParameter($webservice)) {
@@ -213,6 +219,10 @@ class Webservice
         if ($offset) {
             $url .= "&offset={$offset}";
         }
+        
+        if ($qbCriteria) {
+            $url .= '&filters[qb-criteria]';
+        }
 
         return $url;
     }

+ 1 - 1
Services/WebserviceMock.php

@@ -75,7 +75,7 @@ class WebserviceMock extends Webservice
     public function makeGetRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array(), $credentials = array())
     {
         $response = '';
-        foreach ($this->dataResponse as $k => $v) {
+        foreach ((array)$this->dataResponse as $k => $v) {
             $key = null;
             if ($this->serviceContainer->hasParameter($k)) {
                 $key = $this->serviceContainer->getParameter($k);

+ 0 - 21
tests/WebTestCaseBase.php

@@ -88,25 +88,6 @@ class WebTestCaseBase extends WebTestCase
         return $rc->newInstance();
     }
 
-    /**
-     * Utiliza un mock del webservice original. Solo modifica el llamado de la url.
-     * @param array $webServiceData Contiene los datos que debe retorna el webservice.
-     */
-    public function fakeWebservice($webServiceData = null)
-    {
-        if ($webServiceData != null && is_array($webServiceData)) {
-            if ($this->getClient()->getContainer()->has('webservice')) {
-                $original = $this->getClient()->getContainer()->get('webservice');
-                $fake = new WebserviceMock(
-                    $original->getServiceContainer(),
-                    null, //$original->getSecurityTokenStorage(),
-                    null, //$original->getHttpClient(),
-                    $webServiceData);
-                $this->setContainerObject('webservice', $fake);
-            }
-        }
-    }
-
     /**
      * Funcion que crea el servicio de tenencias. Por defecto crea la tenencia base.
      * @param int $current Contiene la tenencia actual.
@@ -392,8 +373,6 @@ class WebTestCaseBase extends WebTestCase
     {
         // creo un nuevo cliente para consultar. Lo tengo que crear para cada consulta.
         $this->getClient(true);
-        // reemplaza el webservice por un mock
-        $this->fakeWebservice($webServiceData);
         // hago fake del login
         $this->FakeLogin();
         // creo el servicio de tenencias