WIP Contract Form
This commit is contained in:
@@ -220,6 +220,8 @@ class ProductController extends mfBaseController {
|
||||
case "getProduct":
|
||||
$return = $this->getProductApi();
|
||||
break;
|
||||
case "findProduct":
|
||||
$return = $this->findProductApi();
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
@@ -259,4 +261,38 @@ class ProductController extends mfBaseController {
|
||||
|
||||
return ["product" => $product->data, "form_id" => $form_id];
|
||||
}
|
||||
|
||||
private function findProductApi() {
|
||||
$search = trim($this->request->q);
|
||||
$autocomplete = $this->request->autocomplete;
|
||||
|
||||
$products = [];
|
||||
|
||||
if(is_numeric($search)) {
|
||||
$pnumbers = ProductModel::search(["id" => $search]);
|
||||
if($pnumbers) {
|
||||
$products = array_merge($products, $pnumbers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$products = array_merge($products, ProductModel::search(["nameLike" => $search]));
|
||||
|
||||
if(!is_array($products) && !count($products)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
// return bootstrap-autocomplete format
|
||||
foreach($products as $product) {
|
||||
$result = ['value' => $product->id, 'text' => str_replace("'", "\\'", str_replace(["\n", "\r"], " ",$product->name))];
|
||||
$results[] = $result;
|
||||
if(count($results) > 15) {
|
||||
$results[] = ['value' => 0, 'text' => " --> Mehr Suchergebnisse vorhanden. Bitte Suchbegriff genauer definieren <--"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->returnJson($results);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user