Ejemplo n.º 1
0
    }
    if (array_key_exists("calories", $_POST)) {
        $recipe->setcalories($_POST['calories']);
    }
    if (array_key_exists("countryId", $_POST)) {
        $origin = $_POST["countryId"];
        if ($origin != "-1") {
            $recipe->setorigin($origin);
        }
    }
    if (array_key_exists("categoryId", $_POST)) {
        $category = $_POST["categoryId"];
        if ($category != "-1") {
            $recipe->setcategory($category);
        }
    }
    if (array_key_exists("tags", $_POST)) {
        $tags = TagService::processTags($_POST["tags"]);
        foreach ($tags as $current) {
            $newTag = new tags();
            $newTag->settagNames($current);
            $recipe->addtags($newTag);
        }
    }
    $saved = ItemService::saveWithValidation($recipe, 200);
    if ($saved == true) {
        $id = $recipe->getId();
        $result = array("id" => $id);
        echo json_encode($result);
    }
});
Ejemplo n.º 2
0
        }
        if (array_key_exists("countryId", $_PUT) && $_PUT["countryId"] != "-1") {
            $recipe->setorigin($_PUT["countryId"]);
        } else {
            $recipe->setcountry();
        }
        if (array_key_exists("categoryId", $_PUT) && $_PUT["categoryId"] != "-1") {
            $recipe->setcategory($_PUT["categoryId"]);
        } else {
            $recipe->setrecipeType();
        }
        if (array_key_exists("tags", $_PUT)) {
            $tags = TagService::processTags($_PUT["tags"]);
            foreach ($tags as $current) {
                $tagsId[] = $current->getid();
            }
            tagsQuery::create()->filterByRecipe($recipe)->where("tags.tagId NOT IN ?", $tagsId)->delete();
            $existingTags = tagsQuery::create()->filterByRecipe($recipe)->select(array("tagId"))->find()->toArray();
            foreach ($tagsId as $index => $current) {
                if (!in_array($current, $existingTags)) {
                    $newTag = new tags();
                    $newTag->settagNames($tags[$index]);
                    $recipe->addtags($newTag);
                }
            }
        }
        ItemService::saveWithValidation($recipe, 204);
    } else {
        http_response_code(404);
    }
});