public function testUpdateRecipe() { $response = $this->executeRequest(array("id" => 1, "values" => array()), true); $this->verifyOk($response, 204); $recipe = RecipeQuery::create()->findPk(1); $this->assertEquals("tarte à la crème", $recipe->getName()); $this->assertEquals("c'est trop bon!", $recipe->getDescription()); }
public function testDeleteCountryWithForeignForce() { $response = $this->executeRequest(array("id" => 2, "force" => "true"), true); $this->verifyOk($response, 204); $this->verifyDeleted(self::$CountryQuery, 2); $recipe2 = RecipeQuery::create()->findPk(2); $recipe3 = RecipeQuery::create()->findPk(3); $this->assertEquals(null, $recipe2->getorigin()); $this->assertEquals(null, $recipe3->getorigin()); }
public function testDeleteRecipeTypeWithForeignForce() { $response = $this->executeRequest(array("id" => 1, "force" => "true"), true); $this->verifyOk($response, 204); $this->verifyDeleted(self::$RecipeTypeQuery, 1); $recipe1 = RecipeQuery::create()->findPk(1); $recipe2 = RecipeQuery::create()->findPk(2); $this->assertEquals(null, $recipe1->getcategory()); $this->assertEquals(null, $recipe2->getcategory()); }
public function getNextStep() { $recipe = RecipeQuery::create()->findPk($this->recipeid); $max = $recipe->countRecipeStepss(); if ($this->order < $max) { $result = RecipeStepsQuery::create()->filterByrecipeId($this->recipeid)->filterByorder($this->order + 1)->findOne(); return $result; } else { return null; } }
public function testCreateRecipe2() { $args = array('photo' => 'http://p2.storage.canalblog.com/25/08/410020/76813294_o.jpg', 'categoryId' => 1, 'countryId' => 1, 'cost' => 2, 'difficulty' => 2, 'time' => 2, 'calories' => 2); $response = $this->executeRequest($args, true); $this->assertEquals(200, $response->getStatusCode()); $result = $response->json(); $created = RecipeQuery::create()->findPk($result["id"]); $this->assertEquals("tarte à la crème", $created->getname()); $this->assertEquals("c'est trop bon!", $created->getdescription()); $this->assertEquals("http://p2.storage.canalblog.com/25/08/410020/76813294_o.jpg", $created->getphoto()); $this->assertEquals(1, $created->getcategory()); $this->assertEquals(1, $created->getorigin()); $this->assertEquals(2, $created->getcost()); $this->assertEquals(2, $created->getdifficulty()); $this->assertEquals(2, $created->gettime()); $this->assertEquals(2, $created->getcalories()); }
<?php require_once '../../bootstrap.php'; if (array_key_exists("offset", $_REQUEST)) { $offset = (int) $_REQUEST["offset"]; } else { $offset = 0; } if (array_key_exists("limit", $_REQUEST)) { $limit = (int) $_REQUEST["limit"]; } else { $limit = 30; } $query = RecipeQuery::create(); if (array_key_exists("filter", $_REQUEST)) { $filter = $_REQUEST["filter"]; if (array_key_exists("recipeTypes", $filter)) { foreach ($filter["recipeTypes"] as $categoryFilter) { $query = $query->filterBycategory($categoryFilter); } } if (array_key_exists("countries", $filter)) { foreach ($filter["countries"] as $countriesFilter) { $query = $query->filterByorigin($countriesFilter); } } if (array_key_exists("maxCost", $filter)) { $query = $query->filterBycost(array('max' => $filter["maxCost"])); } if (array_key_exists("maxDifficulty", $filter)) { $query = $query->filterBydifficulty(array('max' => $filter["maxDifficulty"]));
<?php session_start(); require_once '../../../bootstrap.php'; require '../../../services/UserService.php'; require '../../../services/ItemService.php'; require '../../../utils/Exceptions.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { $ingredient = new ingredient(); $ingredient->setquantity($_POST["quantity"]); if (array_key_exists("unitId", $_POST)) { $unitId = $_POST["unitId"]; if ($unitId != "-1") { $ingredient->setunitId($_POST["unitId"]); } } $ingredient->setingredientId($_POST["ingredientId"]); $recipeId = $_GET["recipeId"]; $recipe = RecipeQuery::create()->findPk($recipeId); if (isset($recipe)) { $recipe->addingredient($ingredient); $saved = ItemService::saveWithValidation($ingredient, 200); if ($saved == true) { $id = $ingredient->getId(); $result = array("id" => $id); echo json_encode($result); } } 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); } ?>