Пример #1
0
             // Add the recipe
             $listObj->addRecipe($recipeObj, $_REQUEST[$item_scale]);
             // Check the related recipes to see which ones should added as well
             $children = $recipeObj->getRelated(true);
             // just get the required children
             foreach ($children as $relObj) {
                 $listObj->addRecipe($relObj, $_REQUEST[$item_scale]);
             }
         } else {
             if ($itemType == 'ingredient' && !$listObj->containsIngredient($_REQUEST[$item_id])) {
                 // It is an ingredient, add it. If extra info is present put it in as well
                 $ing_qualifier = $itemType . "_qualifier_" . $iterator;
                 $ing_quantity = $itemType . "_quantity_" . $iterator;
                 $ing_units = $itemType . "_unit_" . $iterator;
                 $ingObj = new Ingredient();
                 $ingObj->setIngredientMap($_REQUEST[$item_id], NULL, NULL, isset($_REQUEST[$ing_quantity]) ? $_REQUEST[$ing_quantity] : 0, $_REQUEST[$ing_units]);
                 $ingObj->loadIngredient();
                 $listObj->addIngredient($ingObj);
             } else {
                 // Ingredient is already in the list
                 echo '<font size="-1" color="red">' . $LangUI->_('Ingredient is already in list') . "</font><br />";
             }
         }
     }
     // Set the next item
     $iterator++;
     $item_id = $itemType . "_id_" . $iterator;
     $item_scale = $itemType . "_scale_" . $iterator;
     $item_name = $itemType . "_name_" . $iterator;
     $item_add = $itemType . "_selected_" . $iterator;
 }
Пример #2
0
    }
}
$count = 0;
$i = 0;
$ingArray = array();
while (isset($_POST['ingredientId_' . $i])) {
    // Set if the ingredient is optional or not
    if (isset($_POST['ingredientOptional_' . $i])) {
        $optional = "TRUE";
    } else {
        $optional = "FALSE";
    }
    // Now add the updated/new recipes in.
    if (isset($_POST['ingredientId_' . $i]) && $_POST['ingredientQuantity_' . $i] > 0 && isset($_POST['ingredientUnit_' . $i]) && $_POST['ingredientId_' . $i] != "") {
        $ingObj = new Ingredient();
        $ingObj->setIngredientMap($_POST['ingredientId_' . $i], $recipe_id, $_POST['ingredientQualifier_' . $i], $_POST['ingredientQuantity_' . $i], $_POST['ingredientUnit_' . $i], $optional, $count);
        $count++;
        // keep track of which number we are on (for ordering)
        $ingArray[] = $ingObj;
        //Add the object to the list
    }
    $i++;
}
/*
	Handle adding and editing of recipes
*/
$recipeObj = new Recipe($recipe_id, $recipe_name, $recipe_ethnic, $recipe_base, $recipe_course, $recipe_prep_time, $recipe_difficulty, $recipe_directions, $recipe_comments, $recipe_serving_size, $recipe_source, $recipe_source_desc, $SMObj->getUserID(), $recipe_private, $_FILES['recipe_picture'], $recipe_picture_type, $recipe_picture_oid);
// Add or update the recipe
$recipeObj->addUpdate();
// Handle the picture
if ($remove_picture == "yes") {
Пример #3
0
 /**
 	Returns an array with all the current ingredients in it for this recipe
 	@param $servings the number of servings to scale the ingredients to
 	@param $optional if true then the optional ingredients are returned as well
 */
 function getIngredients($servings = NULL, $optional = FALSE)
 {
     global $DB_LINK, $db_table_ingredientmaps;
     $ingredients = array();
     $scaling = null;
     // compute the scaling
     if ($this->serving_size != 0 && $this->serving_size != "") {
         $scaling = $servings / $this->serving_size;
     }
     if ($scaling == NULL || $servings == 0) {
         $scaling = 1;
     }
     $sql = "SELECT * FROM {$db_table_ingredientmaps} WHERE map_recipe=" . $DB_LINK->addq($this->id, get_magic_quotes_gpc());
     $rc = $DB_LINK->Execute($sql);
     while (!$rc->EOF) {
         // Only add the ingredient if we are suppose to
         if ($optional && $rc->fields['map_optional'] == $DB_LINK->true || $rc->fields['map_optional'] != $DB_LINK->true) {
             $ingObj = new Ingredient();
             $ingObj->setIngredientMap($rc->fields['map_ingredient'], $rc->fields['map_recipe'], $rc->fields['map_qualifier'], $rc->fields['map_quantity'], $rc->fields['map_unit'], $rc->fields['map_order']);
             $ingObj->loadIngredient();
             $ingObj->convertToBaseUnits($scaling);
             $ingredients = ShoppingList::combineIngredients($ingredients, $ingObj);
         }
         $rc->MoveNext();
     }
     return $ingredients;
 }
 /**
 	Loads all of the ingredients and recipes saved in the database for this shopping
 	list into an instance of this shopping list.
 	@param $clear if true then the list is cleared before new items are added, if false then they are appended
 */
 function loadItems($clear)
 {
     global $DB_LINK, $db_table_list_recipes, $db_table_list_ingredients;
     if (isset($clear) && $clear) {
         // clear out the items if we are told to
         $this->recipes = array();
         $this->ingredients = array();
     }
     // Add the recipes
     $sql = "SELECT list_rp_recipe, list_rp_scale FROM {$db_table_list_recipes} WHERE list_rp_id=" . $DB_LINK->addq($this->id, get_magic_quotes_gpc());
     $rc = $DB_LINK->Execute($sql);
     DBUtils::checkResult($rc, NULL, NULL, $sql);
     while (!$rc->EOF) {
         $recipeObj = new Recipe($rc->fields['list_rp_recipe']);
         $recipeObj->loadRecipe();
         $this->addRecipe($recipeObj, $rc->fields['list_rp_scale']);
         $rc->MoveNext();
     }
     // Add the ingredients
     $sql = "SELECT list_ing_ingredient,list_ing_unit,list_ing_qualifier,list_ing_quantity FROM {$db_table_list_ingredients} WHERE list_ing_id=" . $DB_LINK->addq($this->id, get_magic_quotes_gpc()) . " ORDER BY list_ing_order";
     $rc = $DB_LINK->Execute($sql);
     DBUtils::checkResult($rc, NULL, NULL, $sql);
     while (!$rc->EOF) {
         $ingObj = new Ingredient();
         $ingObj->setIngredientMap($rc->fields['list_ing_ingredient'], NULL, $rc->fields['list_ing_qualifier'], $rc->fields['list_ing_quantity'], $rc->fields['list_ing_unit']);
         $ingObj->loadIngredient();
         $this->addIngredient($ingObj);
         $rc->MoveNext();
     }
 }