public function testDeleteIngredientTypeWithForeignForce() { $response = $this->executeRequest(array("id" => 2, "force" => "true"), true); $this->verifyOk($response, 204); $this->verifyDeleted(self::$IngredientTypeQuery, 2); $this->assertNull(ingredientQuery::create()->findPk(2)); }
public function testUpdateIngredient() { $args = array("quantity" => 70, "unitId" => 2, "ingredientId" => 2, "recipeId" => 1); $response = $this->executeRequest(array("id" => 1, "values" => $args), true); $this->verifyOk($response, 204); $ingredient = ingredientQuery::create()->findPk(1); $this->assertEquals(70, $ingredient->getquantity()); $this->assertEquals(2, $ingredient->getunitId()); $this->assertEquals(2, $ingredient->getingredientId()); $this->assertEquals(1, $ingredient->getrecipeId()); }
public function testCreateIngredient() { $args = array("quantity" => 10, "unitId" => 1, "ingredientId" => 1, "recipeId" => 1); $response = $this->executeRequest($args, true); $this->verifyOk($response); $result = $response->json(); $created = ingredientQuery::create()->findPk($result["id"]); $this->assertEquals(10, $created->getquantity()); $this->assertEquals(1, $created->getunitId()); $this->assertEquals(1, $created->getingredientId()); $this->assertEquals(1, $created->getrecipeId()); }
} 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"])); } 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);
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { if (array_key_exists("id", $_GET)) { $ingredient = ingredientQuery::create()->findPk($_GET["id"]); } if (isset($ingredient)) { try { $ingredient->delete(); http_response_code(204); } catch (PropelException $ex) { http_response_code(500); } } else { http_response_code(404); } });
<?php require_once '../../../bootstrap.php'; if (array_key_exists("recipeId", $_GET)) { $recipeId = $_GET["recipeId"]; $recipe = RecipeQuery::create()->findPk($recipeId); if (isset($recipe)) { $ingredients = ingredientQuery::create()->filterByrecipeId($recipeId)->join("ingredientType")->join("unit", Criteria::LEFT_JOIN)->select(array('id', "quantity"))->withColumn("ingredientType.name", "ingredient")->withColumn("unit.name", "unit")->find(); $data = $ingredients->getData(); echo json_encode($data); } else { http_response_code(404); } } ?>
<?php require_once '../../bootstrap.php'; $ingredientId = $_GET["id"]; $ingredient = ingredientQuery::create()->findPk($ingredientId); if (isset($ingredient)) { echo $ingredient->toJSON(true); } else { http_response_code(404); } ?>