Пример #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;
 }