Add autocompletion to city and tankstelle elements
[infodrom.org/service.infodrom.org] / class / spritlog.class.php
index e0b8f70..451edc4 100644 (file)
@@ -82,6 +82,29 @@ class SpritLog extends DatabaseTable {
 
     $d = explode('-', $data['date']);
     return array('status' => $ok, 'year' => $d[0]);
+  }
+
+  public function ajaxSuggestCity(Array $data)
+  {
+    $data['query'] .= '%';
+    $sql = sprintf("SELECT DISTINCT city FROM sprit_log WHERE lower(city) LIKE %s ORDER BY city",
+                  $this->quote(strtolower($data['query'])));
+    $list = array();
+    foreach ($this->fetchObjectList($sql) as $row)
+      $list[] = array('value' => $row->city, 'data' => $row->city);
+    return array('suggestions' => $list);
+  }
 
+  public function ajaxSuggestTankstelle(Array $data)
+  {
+    $data['query'] .= '%';
+    $sql = sprintf("SELECT DISTINCT tankstelle FROM sprit_log WHERE city = %s AND lower(tankstelle) LIKE %s ORDER BY tankstelle",
+                  $this->quote($data['city']),
+                  $this->quote(strtolower($data['query'])));
+    $list = array();
+    foreach ($this->fetchObjectList($sql) as $row)
+      $list[] = array('value' => $row->tankstelle, 'data' => $row->tankstelle);
+    return array('suggestions' => $list);
   }
+
 }