Merge branch 'develop' of gitea.steve-dekart.xyz:web_programming/fridge_bites into TIST-40
This commit is contained in:
commit
44863aecbd
@ -31,10 +31,17 @@ function ajax_search()
|
|||||||
}
|
}
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
$recipes = RecipeModel::filter(
|
$recipes = array();
|
||||||
|
$recipe_models = RecipeModel::filter(
|
||||||
count: 5,
|
count: 5,
|
||||||
search: $search_query
|
search: $search_query
|
||||||
);
|
);
|
||||||
|
foreach ($recipe_models as $recipe_model) {
|
||||||
|
$recipe = $recipe_model->getAssocArr();
|
||||||
|
$recipe['image_url'] = $recipe_model->get_image_url();
|
||||||
|
$recipe['url'] = $recipe_model->get_absolute_url();
|
||||||
|
$recipes[] = $recipe;
|
||||||
|
}
|
||||||
|
|
||||||
$result['count'] = count($recipes);
|
$result['count'] = count($recipes);
|
||||||
$result['result'] = $recipes;
|
$result['result'] = $recipes;
|
||||||
@ -132,7 +139,9 @@ function ajax_search_ingredient()
|
|||||||
search: $search_query
|
search: $search_query
|
||||||
);
|
);
|
||||||
$result['count'] = count($ingredients);
|
$result['count'] = count($ingredients);
|
||||||
$result['result'] = $ingredients;
|
$result['result'] = array_map(function($ing) {
|
||||||
|
return $ing->getAssocArr();
|
||||||
|
}, $ingredients);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,6 +86,10 @@ class RecipeModel extends BaseModel
|
|||||||
);');
|
);');
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
public function get_absolute_url()
|
||||||
|
{
|
||||||
|
return get_permalink('recipes:single', [ $this->get_id() ]);
|
||||||
|
}
|
||||||
public function get_price()
|
public function get_price()
|
||||||
{
|
{
|
||||||
return $this->field_estimated_price . '$';
|
return $this->field_estimated_price . '$';
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<a href="<?php the_permalink('recipes:single', [$recipe->get_id()]) ?>" class="catalog-recipe hover-anim">
|
<a href="<?= $recipe->get_absolute_url() ?>" class="catalog-recipe hover-anim">
|
||||||
<div class="catalog-recipe__image">
|
<div class="catalog-recipe__image">
|
||||||
<img src="<?= $recipe->get_image_url() ?>" alt="<?= $recipe->field_title ?>">
|
<img src="<?= $recipe->get_image_url() ?>" alt="<?= $recipe->field_title ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -364,6 +364,9 @@ abstract class BaseModel
|
|||||||
else
|
else
|
||||||
return $filter_result[0]->func_total_count;
|
return $filter_result[0]->func_total_count;
|
||||||
}
|
}
|
||||||
|
public function getAssocArr() {
|
||||||
|
return get_object_vars($this);
|
||||||
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
@ -436,7 +439,7 @@ abstract class BaseModel
|
|||||||
/**
|
/**
|
||||||
* Return model from Mysql result
|
* Return model from Mysql result
|
||||||
* @param array $pdo_result pdo resut FETCH_MODE = FETCH_ASSOC
|
* @param array $pdo_result pdo resut FETCH_MODE = FETCH_ASSOC
|
||||||
* @return array
|
* @return array(self)
|
||||||
*/
|
*/
|
||||||
protected static function createObjectsFromQuery(array $pdo_result)
|
protected static function createObjectsFromQuery(array $pdo_result)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user