Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 $app['monolog']->addDebug('logging output / Post Recipe');
 $name = $request->get('name');
 $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);
                 }