<?php
namespace com\whitemagicsoftware;
require "constants.php";
require "class.Ajax.php";
class AjaxIngredientSearch extends Ajax {
function __construct() {
parent::__construct();
}
private function getIngredients( $search, $category = false ) {
$search = mb_strtolower( $search );
$proc = "search_ingredient";
if( $category ) {
$proc = $proc . "_category";
}
return $this->call( $proc, "id, label", $search );
}
public function handleAjaxRequest() {
$search = $this->getParameter( "term" );
$category = $this->getParameter( "category" );
$ingredients = $this->getIngredients( $search, $category );
$result = array();
foreach( $ingredients as $key => $value ) {
$value["value"] = $value["label"];
array_push( $result, $value );
}
return json_encode( $result, true );
}
}