Ver Fonte

FD3-249 En el choice loader, por defecto no se hacen consultas al webservice, solo por ajax. Se agregó limit=20

Guillermo Espinoza há 7 anos atrás
pai
commit
d0ffcf26eb
2 ficheiros alterados com 42 adições e 25 exclusões
  1. 25 18
      Form/ChoiceList/Loader/ClientChoiceLoader.php
  2. 17 7
      Services/Webservice.php

+ 25 - 18
Form/ChoiceList/Loader/ClientChoiceLoader.php

@@ -92,25 +92,28 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
      */
     public function loadChoiceList($value = null)
     {
-        $choices = $this->getChoicesList(false);
-        
-        $missing_choices = array_flip($this->selected);
-        
-        foreach ($choices as $label => $id) {
-            if (isset($missing_choices[$id])) {
-                unset($missing_choices[$id]);
-            }
-        }
+        $choices = array();
+        if ($this->selected) {
+            $choices = $this->getChoicesList(false);
 
-        // Now add selected choices if they're missing
-        foreach (array_keys($missing_choices) as $id) {
-            $label = $this->getChoiceLabel($id);
+            $missing_choices = array_flip($this->selected);
 
-            if (strlen($label) === 0) {
-                continue;
+            foreach ($choices as $label => $id) {
+                if (isset($missing_choices[$id])) {
+                    unset($missing_choices[$id]);
+                }
             }
 
-            $choices[$label] = $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;
+                }
+
+                $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;
     }
 
     /**

+ 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
@@ -187,10 +192,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)) {
@@ -212,6 +218,10 @@ class Webservice
         if ($offset) {
             $url .= "&offset={$offset}";
         }
+        
+        if ($qbCriteria) {
+            $url .= '&filters[qb-criteria]';
+        }
 
         return $url;
     }