Example #1
0
 public function copy()
 {
     if (isset($this->params["id"])) {
         return MealPlanComponent::copyWithinMealPlan($this->params["id"]);
     } else {
         throw new Exception('Missing id parameter');
     }
 }
Example #2
0
 public static function calculateMeal($params)
 {
     $shoppingArray = array();
     // Add each food in meal plan to shopping array
     if (isset($params["id"]) && $params["id"] != 0) {
         $mealPlanComponents = MealPlanComponent::getComponents($params["id"]);
         foreach ($mealPlanComponents as $mealPlanComponent) {
             self::addFood($mealPlanComponent["foodId"], $shoppingArray, $mealPlanComponent["quantity"]);
         }
     }
     // Return array without keys
     return array_values($shoppingArray);
 }
Example #3
0
 public static function copy($params)
 {
     if (!isset($params["id"])) {
         throw new Exception("Missing id parameter");
     }
     // Connect to database
     $mysqli = FoodAppDatabase::connect();
     // Copy meal_plan table record
     $mealFields = implode(",", array_slice(static::$fieldMap, 1));
     $queryString = "INSERT into meal_plan (" . $mealFields . ") ";
     $queryString .= "SELECT " . $mealFields . " FROM meal_plan ";
     $queryString .= "WHERE id='" . $params["id"] . "'";
     // Run query
     if (!$mysqli->query($queryString)) {
         throw new Exception($mysqli->error);
     }
     $newMealId = $mysqli->insert_id;
     // Copy Components
     MealPlanComponent::copy($params["id"], $newMealId);
 }
Example #4
0
 public static function calculateMealPlanComponents($mealPlanId)
 {
     $returnArray = array();
     if ($mealPlanId == 0) {
         return $returnArray;
     }
     $mealPlanComponents = MealPlanComponent::getComponents($mealPlanId);
     foreach ($mealPlanComponents as $mealPlanComponent) {
         $componentNutrition = self::calculate($mealPlanComponent["foodId"], $mealPlanComponent["quantity"]);
         $componentNutrition["foodId"] = $componentNutrition["id"];
         $componentNutrition["id"] = $mealPlanComponent["id"];
         $componentNutrition["day"] = $mealPlanComponent["day"];
         $returnArray[] = $componentNutrition;
     }
     return $returnArray;
 }