Ejemplo n.º 1
0
function parseRecipe($html, $url)
{
    $parsedRecipe = RecipeParser::parse($html, $url);
    $recipe = new Recipe();
    $recipe->RecipeName = $parsedRecipe->title;
    $recipe->ServingCount = getNumberFromString($parsedRecipe->yield);
    $recipe->PrepTimeMinute = $parsedRecipe->time['prep'];
    $recipe->CookTimeMinute = $parsedRecipe->time['cook'];
    $recipe->RecipeNote = $parsedRecipe->url;
    $directions = '';
    foreach ($parsedRecipe->instructions[0]['list'] as $key => $n) {
        if ($directions != '') {
            $directions .= "\n\n";
        }
        $directions .= $parsedRecipe->instructions[0]['list'][$key];
    }
    $recipe->Directions = $directions;
    $recipe->save();
    foreach ($parsedRecipe->ingredients[0]['list'] as $key => $n) {
        $ingredient = new RecipeIngredient();
        $ingredient->RecipeId = $recipe->RecipeId;
        $origText = $parsedRecipe->ingredients[0]['list'][$key];
        try {
            $text = trim($origText);
            preg_match('~[a-z]~i', $text, $match, PREG_OFFSET_CAPTURE);
            $count = substr($text, 0, $match[0][1]);
            $countEncode = urlencode($count);
            $countEncode = str_replace("%C2%BC", " 1/4", $countEncode);
            $countEncode = str_replace("%C2%BD", " 1/2", $countEncode);
            $countEncode = str_replace("%C2%BE", " 3/4", $countEncode);
            $count = urldecode($countEncode);
            $count = str_replace("-", " ", $count);
            $count = fractionToDecimal($count);
            $text = trim(substr($text, $match[0][1]));
            $size = getItemSize(substr($text, 0, strpos($text, " ")));
            if (!isNullOrEmptyString($size)) {
                $text = trim(substr($text, strpos($text, " ")));
            }
            $ingredient->ItemCount = $count;
            $ingredient->ItemSize = $size;
            $ingredient->RecipeIngredientName = $text;
            //$ingredient->RecipeIngredientNote = $origText;
        } catch (Exception $e) {
            $ingredient->RecipeIngredientName = $origText;
            $ingredient->RecipeIngredientNote = $e->getMessage();
        }
        // save the Tag on the Post
        $recipe->ingredients()->save($ingredient);
    }
    if (!isNullOrEmptyString($parsedRecipe->photo_url)) {
        saveImage($recipe, $parsedRecipe->photo_url);
    }
    return $recipe;
}
Ejemplo n.º 2
0
function getFBAItemHaisoPrice($kind, $weight, $width, $height, $length, $price)
{
    $item_size;
    $syuka_price = 0;
    //商品サイズを取得する
    $item_size = getItemSize($weight, $width, $height, $length, $price);
    switch ($item_size) {
        case "Small":
            if ($kind == 1) {
                return HAISO_MEDIA_SMALL_PRICE;
            } else {
                return HAISO_NOMEDIA_SMALL_PRICE;
            }
            break;
        case "Basic":
            $resPrice = 0;
            if ($kind == 1) {
                $resPrice = HAISO_MEDIA_BASIC_PRICE;
            } else {
                $resPrice = HAISO_NOMEDIA_BASIC_PRICE;
            }
            //加重料金2kg以上1kgごとに6円
            $resPrice = $resPrice + ceil($weight - 2) * 6;
            return $resPrice;
        case "Big1":
            return HAISO_BIG1_PRICE;
        case "Big2":
            return HAISO_BIG2_PRICE;
        case "Big3":
            return HAISO_BIG3_PRICE;
        case "High":
            return HAISO_HIGH_PRICE;
        default:
            return 0;
    }
}