本文整理汇总了PHP中Food::getFood方法的典型用法代码示例。如果您正苦于以下问题:PHP Food::getFood方法的具体用法?PHP Food::getFood怎么用?PHP Food::getFood使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Food
的用法示例。
在下文中一共展示了Food::getFood方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculate
public static function calculate($id)
{
if ($id == 0) {
return array();
}
$food = Food::getFood($id);
$returnArray = array();
// Search food components table for input food
$foodComponents = FoodComponent::getComponentsWithChild($id);
foreach ($foodComponents as $foodComponent) {
$parentFood = Food::getFood($foodComponent["foodId"]);
$returnArray[] = array("foodId" => $parentFood["id"], "foodName" => $parentFood["name"], "componentId" => $food["id"], "componentName" => $food["name"], "quantity" => $foodComponent["quantity"], "unitOfMeasure" => $food["unitOfMeasure"]);
}
return $returnArray;
}
示例2: addFood
public static function addFood($id, &$shoppingArray, $quantity = 0)
{
if ($id == 0) {
return array();
}
// Prepare needed data
$food = Food::getFood($id);
$foodComponents = FoodComponent::getComponents($id);
if (sizeof($foodComponents) == 0) {
// Default to serving size in this case
if ($quantity == 0) {
$quantity = $food["quantity"];
}
// No components, just add entry for self
self::addShopping($shoppingArray, $id, $food, $quantity);
} else {
// Default to recipe quantity in this case
if ($quantity == 0) {
$quantity = $food["recipeQuantity"];
}
if ($quantity == 0) {
$quantity = $food["quantity"];
}
// Return shopping for each component
foreach ($foodComponents as $foodComponent) {
// Determine component quantity needed
if ($food["recipeQuantity"] == 0) {
$food["recipeQuantity"] = $food["quantity"];
}
if ($food["recipeQuantity"] == 0) {
$food["recipeQuantity"] = 1;
}
$componentQuantity = $foodComponent["quantity"] * $quantity / $food["recipeQuantity"];
self::addFood($foodComponent["componentId"], $shoppingArray, $componentQuantity);
}
}
}
示例3: function
<?php
require 'classes/Food.php';
// get all food items route
$app->get('/food/', function () use($session) {
// if($session->isValidRequest() == 0){
// $session->goodnight();
// }
try {
$return = array();
$return['success'] = true;
$return['data'] = Food::getFood();
$return['time'] = time();
//$return['id'] = $_SESSION['user_id'];
$return['sid'] = session_id();
echo json_encode($return);
} catch (Exception $e) {
echo json_encode($e->getMessage());
}
});
示例4: calculateComponents
public static function calculateComponents($parentId)
{
$returnArray = array();
if ($parentId == 0) {
return $returnArray;
}
// Prepare needed data
$parentFood = Food::getFood($parentId);
$foodComponents = FoodComponent::getComponents($parentId);
// Calculate nutrition for each component
foreach ($foodComponents as $foodComponent) {
// Determine quantity needed for one serving of parent food
if ($parentFood["recipeQuantity"] == 0) {
$parentFood["recipeQuantity"] = 1;
}
$quantity = $foodComponent["quantity"] * $parentFood["quantity"] / $parentFood["recipeQuantity"];
// Calculate component nutrition at that quantity
$componentNutrition = self::calculate($foodComponent["componentId"], $quantity);
// Add component nutrition to output array
$returnArray[] = $componentNutrition;
}
return $returnArray;
}