Compare commits
2 Commits
f588e5f608
...
3e9fdd36bb
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e9fdd36bb | |||
| 95e41b813f |
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Lycoreco\Apps\Recipes\Models\{
|
use Lycoreco\Apps\Recipes\Models\{
|
||||||
|
IngredientModel,
|
||||||
RecipeModel,
|
RecipeModel,
|
||||||
RecipeUserMenu
|
RecipeUserMenu
|
||||||
};
|
};
|
||||||
@ -30,12 +31,8 @@ function ajax_search()
|
|||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
$recipes = RecipeModel::filter(
|
$recipes = RecipeModel::filter(
|
||||||
array(),
|
count: 5,
|
||||||
array(),
|
search: $search_query
|
||||||
5,
|
|
||||||
'AND',
|
|
||||||
0,
|
|
||||||
$search_query
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$result['count'] = count($recipes);
|
$result['count'] = count($recipes);
|
||||||
@ -97,3 +94,44 @@ function ajax_usermenu()
|
|||||||
$result['success'] = 'You have successfully added the recipe to your menu.';
|
$result['success'] = 'You have successfully added the recipe to your menu.';
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
function ajax_create_ingredient()
|
||||||
|
{
|
||||||
|
$ingredient_name = $_POST['name'] ?? null;
|
||||||
|
$ingredient_unit = $_POST['unit'] ?? null;
|
||||||
|
|
||||||
|
if (!CURRENT_USER) {
|
||||||
|
return get_ajax_error('You are not authorized', 401);
|
||||||
|
}
|
||||||
|
if (!isset($ingredient_name)) {
|
||||||
|
return get_ajax_error("Missing 'name' parameter.", 400);
|
||||||
|
}
|
||||||
|
if (!isset($ingredient_unit)) {
|
||||||
|
return get_ajax_error("Missing 'unit' parameter.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ingredient = new IngredientModel();
|
||||||
|
$ingredient->field_name = $ingredient_name;
|
||||||
|
$ingredient->field_unit_name = $ingredient_unit;
|
||||||
|
$ingredient->save();
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
$result['success'] = 'You have successfully added new ingredient';
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
function ajax_search_ingredient()
|
||||||
|
{
|
||||||
|
$search_query = $_POST['query'] ?? null;
|
||||||
|
if (!isset($search_query)) {
|
||||||
|
return get_ajax_error("Missing 'query' parameter.", 400);
|
||||||
|
}
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
$ingredients = IngredientModel::filter(
|
||||||
|
count: 5,
|
||||||
|
search: $search_query
|
||||||
|
);
|
||||||
|
$result['count'] = count($ingredients);
|
||||||
|
$result['result'] = $ingredients;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user