public function setSteps($steps) { foreach ($steps as $step) { $recipe_step = new \ChopShopper\Entity\RecipeStep(); if (isset($step['directions'])) { $recipe_step->setDirections($step['directions']); } if (isset($step['step_ingredients'])) { $recipe_step->setStepIngredients($step['step_ingredients']); } $recipe_step->setRecipe($this); $this->addStep($recipe_step); } return $this; }
$app['monolog']->addDebug('name: ' . $name); if ($name === null or strlen($name) < 3) { $app->abort('403', 'Whoops'); } $recipe = new Recipe(); $recipe->setName($name); $steps = $request->get('steps'); // this is just crying out for refactor ... and MongoDB $em = $app['orm.em']; $em->persist($recipe); if ($steps) { $app['monolog']->addDebug('steps: ' . var_export($steps, true)); foreach ($steps as $step) { $recipe_step = new \ChopShopper\Entity\RecipeStep(); if (isset($step['directions'])) { $recipe_step->setDirections($step['directions']); } if (isset($step['step_ingredients'])) { foreach ($step['step_ingredients'] as $step_ingredient) { $recipe_step_ingredient = new \ChopShopper\Entity\RecipeStepIngredient(); if (isset($step_ingredient['ingredient'])) { $ingredient = $em->getRepository('ChopShopper\\Entity\\Ingredient')->findOneBy(array('name' => $step_ingredient['ingredient']['name'])); if (!$ingredient) { $ingredient = new \ChopShopper\Entity\Ingredient(); $ingredient->setName($step_ingredient['ingredient']['name']); $em->persist($ingredient); } $recipe_step_ingredient->setIngredient($ingredient); } if (isset($step_ingredient['qty'])) { $recipe_step_ingredient->setQty($step_ingredient['qty']);