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; } }
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { if (array_key_exists("id", $_GET)) { $recipeStepId = $_GET["id"]; $step = RecipeStepsQuery::create()->findPk($recipeStepId); } if (isset($step)) { $next = $step->getNextStep(); if (isset($next)) { $swap = $step->getorder(); $step->setorder($next->getorder()); $next->setorder($swap); $step->save(); $next->save(); } http_response_code(204); echo "true"; } else { http_response_code(404); } });
protected function verifyStep($stepId, $description) { $step = RecipeStepsQuery::create()->findPk($stepId); $this->assertNotNull($step); $this->assertEquals($description, $step->getdescription()); }
<?php require_once '../../../bootstrap.php'; require '../../../services/UserService.php'; require '../../../services/ItemService.php'; if (array_key_exists("recipeId", $_GET)) { $recipeId = $_GET["recipeId"]; $recipe = RecipeQuery::create()->findPk($recipeId); if (isset($recipe)) { $steps = RecipeStepsQuery::create()->filterByRecipe($recipe)->orderBy("order")->select(array('id', 'description'))->find(); $data = $steps->getData(); echo json_encode($data); } else { http_response_code(404); } }
<?php require_once '../../../bootstrap.php'; $recipeId = $_GET["recipeId"]; $stepOrder = $_GET["id"]; $step = RecipeStepsQuery::create()->filterByrecipeId($recipeId)->filterByorder($stepOrder)->select(array('id', 'description', 'order'))->find()->getFirst(); if (isset($step)) { echo json_encode($step); } else { http_response_code(404); }