if (array_key_exists("maxDifficulty", $filter)) { $query = $query->filterBydifficulty(array('max' => $filter["maxDifficulty"])); } if (array_key_exists("maxTime", $filter)) { $query = $query->filterBytime(array('max' => $filter["maxTime"])); } if (array_key_exists("maxCalories", $filter)) { $query = $query->filterBycalories(array('max' => $filter["maxCalories"])); } if (array_key_exists("ingredients", $filter)) { foreach ($filter["ingredients"] as $ingFilter) { $ids = ingredientQuery::create()->filterByingredientId($ingFilter)->select(array("recipeId"))->find(); $query = $query->filterByPrimaryKeys($ids); } } if (array_key_exists("tags", $filter)) { foreach ($filter["tags"] as $tagFilter) { $ids = tagsQuery::create()->filterBytagId($tagFilter)->select(array("recipeId"))->find(); $query = $query->filterByPrimaryKeys($ids); } } } $query = $query->select(array('id', 'name')); $count = $query->count(); $recipes = $query->offset($offset)->limit($limit)->orderByName()->find(); $data = $recipes->getData(); $result = array("count" => $count, "offset" => $offset, "limit" => $limit, "data" => $data); echo json_encode($result); ?>
} if (array_key_exists("countryId", $_PUT) && $_PUT["countryId"] != "-1") { $recipe->setorigin($_PUT["countryId"]); } else { $recipe->setcountry(); } if (array_key_exists("categoryId", $_PUT) && $_PUT["categoryId"] != "-1") { $recipe->setcategory($_PUT["categoryId"]); } else { $recipe->setrecipeType(); } if (array_key_exists("tags", $_PUT)) { $tags = TagService::processTags($_PUT["tags"]); foreach ($tags as $current) { $tagsId[] = $current->getid(); } tagsQuery::create()->filterByRecipe($recipe)->where("tags.tagId NOT IN ?", $tagsId)->delete(); $existingTags = tagsQuery::create()->filterByRecipe($recipe)->select(array("tagId"))->find()->toArray(); foreach ($tagsId as $index => $current) { if (!in_array($current, $existingTags)) { $newTag = new tags(); $newTag->settagNames($tags[$index]); $recipe->addtags($newTag); } } } ItemService::saveWithValidation($recipe, 204); } else { http_response_code(404); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { if (array_key_exists("id", $_GET)) { $recipeId = $_GET["id"]; $recipe = RecipeQuery::create()->findPk($recipeId); } if (isset($recipe)) { try { tagsQuery::create()->filterByRecipe($recipe)->delete(); $recipe->delete(); http_response_code(204); } catch (PropelException $ex) { http_response_code(500); } } else { http_response_code(404); } });
<?php require_once '../../bootstrap.php'; $recipeId = $_GET["id"]; $recipe = RecipeQuery::create()->join("country", Criteria::LEFT_JOIN)->join("recipeType", Criteria::LEFT_JOIN)->select(array("id", "name", "description", "photo", "cost", "difficulty", "time", "calories"))->withColumn("country.id", "countryId")->withColumn("country.name", "country")->withColumn("country.flag", "flag")->withColumn("recipeType.id", "categoryId")->withColumn("recipeType.name", "category")->findPk($recipeId); $tags = tagsQuery::create()->join("tagNames")->filterByrecipeId($recipeId)->select(array("tagNames.name"))->find(); if (count($tags) > 0) { $recipe["tags"] = join(', ', $tags->toArray()); } if (isset($recipe)) { echo json_encode($recipe); } else { http_response_code(404); } ?>