GetDKAN / dkan

DKAN Open Data Portal
https://dkan.readthedocs.io/en/latest/index.html
GNU General Public License v2.0
366 stars 170 forks source link

Recline grid view filter not working when imported csv file column name has spaces #143

Closed viewpnt closed 7 years ago

viewpnt commented 10 years ago

Hi: Recline grid view filter not working when imported csv file column name has spaces. The example file Polling_Places_Madison.csv has a space in column "Aldermanic District" When a filter is applied, the "Loading" message never disappears.

I traced the issue to the function _dkan_datastore_api_datastore_index() In the variable $filters, the spaces need to be replaced with underscores.

My hack to solve the problem follows, just as a reference, because as you see, it is just an ugly hack.

--- /root/docroot-new/profiles/dkan/modules/dkan/dkan_datastore/modules/dkan_datastore_api/dkan_datastore_api.module    2014-04-28 13:40:07.000000000 -0500
+++ /var/www/html/profiles/dkan/modules/dkan/dkan_datastore/modules/dkan_datastore_api/dkan_datastore_api.module        2014-06-05 17:23:59.318552600 -0500
@@ -170,12 +170,27 @@
   );
 }

+function fixArrayKey(&$arr)
+{
+  //Function replaces space with underscore in keys from an array recursively
+  $arr=array_combine(array_map(function($str){return str_replace(" ","_",$str);},array_keys($arr)),array_values($arr));
+  foreach($arr as $key=>$val)
+  {
+    if(is_array($val)) fixArrayKey($arr[$key]);
+  }
+}
+
 /**
  * Creates index based off of query.
  *
  * For arguments, see: dkan_datastore_api_services_resources().
  */
 function _dkan_datastore_api_datastore_index($resource_ids, $filters, $query, $offset, $limit, $fields, $sort, $join) {
+
+  if (is_array($filters)) {
+    fixArrayKey($filters);
+  }
+
   try {
     // Query for a single resource.
     if (count($resource_ids) < 2) {
acouch commented 10 years ago

Thanks for reporting. Will look into this.

davehodg commented 9 years ago

I just installed DKAN and this bit me. Has it been fixed?

janette commented 7 years ago

This has been fixed. Please upgrade to the latest release https://github.com/NuCivic/dkan/releases