<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $unit = new unit(); $unit->setName($_POST["name"]); $saved = ItemService::saveWithValidation($unit, 200); if ($saved == true) { $id = $unit->getId(); $result = array("id" => $id); echo json_encode($result); } });
} if (array_key_exists("calories", $_POST)) { $recipe->setcalories($_POST['calories']); } if (array_key_exists("countryId", $_POST)) { $origin = $_POST["countryId"]; if ($origin != "-1") { $recipe->setorigin($origin); } } if (array_key_exists("categoryId", $_POST)) { $category = $_POST["categoryId"]; if ($category != "-1") { $recipe->setcategory($category); } } if (array_key_exists("tags", $_POST)) { $tags = TagService::processTags($_POST["tags"]); foreach ($tags as $current) { $newTag = new tags(); $newTag->settagNames($current); $recipe->addtags($newTag); } } $saved = ItemService::saveWithValidation($recipe, 200); if ($saved == true) { $id = $recipe->getId(); $result = array("id" => $id); echo json_encode($result); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; require '../../services/RequestService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $_PUT = RequestService::processPutParams(); if (array_key_exists("id", $_GET)) { $ingredientId = $_GET["id"]; $ingredient = ingredientTypeQuery::create()->findPk($ingredientId); } if (isset($ingredient)) { $ingredient->setName($_PUT["name"]); ItemService::saveWithValidation($ingredient, 204); } else { http_response_code(404); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; require '../../services/RequestService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $_PUT = RequestService::processPutParams(); if (array_key_exists("id", $_GET)) { $countryId = $_GET["id"]; $country = countryQuery::create()->findPk($countryId); } if (isset($country)) { $country->setName($_PUT["name"]); $country->setflag($_PUT["flag"]); ItemService::saveWithValidation($country, 204); } else { http_response_code(404); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; require '../../services/RequestService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $_PUT = RequestService::processPutParams(); if (array_key_exists("id", $_GET)) { $categoryId = $_GET["id"]; $category = countryQuery::create()->findPk($categoryId); } if (isset($category)) { $category->setName($_PUT["name"]); ItemService::saveWithValidation($category, 204); } else { http_response_code(404); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $country = new country(); $country->setName($_POST["name"]); $country->setflag($_POST["flag"]); $saved = ItemService::saveWithValidation($country, 200); if ($saved == true) { $id = $country->getId(); $result = array("id" => $id); echo json_encode($result); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $category = new recipeType(); $category->setName($_POST["name"]); $saved = ItemService::saveWithValidation($category, 200); if ($saved == true) { $id = $category->getId(); $result = array("id" => $id); echo json_encode($result); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; require '../../services/RequestService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $_PUT = RequestService::processPutParams(); if (array_key_exists("id", $_GET)) { $recipeStepId = $_GET["id"]; $step = RecipeStepsQuery::create()->findPk($recipeStepId); } if (isset($step)) { $step->setdescription($_PUT["description"]); ItemService::saveWithValidation($step, 204); } else { http_response_code(404); } });
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ItemService.php'; require '../../services/RequestService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $_PUT = RequestService::processPutParams(); if (array_key_exists("id", $_GET)) { $unitId = $_GET["id"]; $unit = unitQuery::create()->findPk($unitId); } if (isset($unit)) { $unit->setName($_PUT["name"]); ItemService::saveWithValidation($unit, 204); } else { http_response_code(404); } });
} 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); } });