コード例 #1
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;
 }
コード例 #2
0
ファイル: current.php プロジェクト: pjflameboy/phprecipebook
             $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;
 }
 // Delete Recipe(s) from the Shopping List
コード例 #3
0
 /**
 	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();
     }
 }