2023-01-05 05:06:19 +01:00
|
|
|
package com.bib.essensbestellungsverwaltung;
|
2023-01-06 01:51:42 +01:00
|
|
|
/*
|
|
|
|
@author Malte Schulze Hobeling
|
|
|
|
*/
|
2023-01-05 05:06:19 +01:00
|
|
|
|
2023-01-07 23:14:41 +01:00
|
|
|
import java.util.ArrayList;
|
2023-01-05 05:06:19 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class FoodMgr {
|
|
|
|
public static long createFood(String[] foodData, String[] allergyData){
|
|
|
|
String[] foodH = {"name","description","isDessert","food_typeid"};
|
|
|
|
String[] food_restrictionH = {"foodid","allergyid"};
|
|
|
|
long id = Database.insert("food",foodH,foodData);
|
|
|
|
if(allergyData.length > 0){
|
|
|
|
String sId = String.valueOf(id);
|
|
|
|
for (String allergyId : allergyData) {
|
|
|
|
String[] food_restrictionD = {sId,allergyId};
|
|
|
|
Database.insert("food_restriction",food_restrictionH, food_restrictionD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long createFood_plan(String[] food_planData){
|
|
|
|
String[] food_planH = {"date","food1","food2","dessert1","dessert2"};
|
|
|
|
return Database.insert("food_plan",food_planH,food_planData);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> getFood(boolean isDessert){
|
|
|
|
String[] foodH = {"isDessert"};
|
|
|
|
String[] foodD = {(isDessert ? "1" : "0")};
|
|
|
|
return Database.select("food",foodH,foodD);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> getVeganFood(boolean isDessert){
|
|
|
|
String[] foodH = {"isDessert","food_typeid"};
|
|
|
|
String[] foodD = {(isDessert ? "1" : "0"),"1"};
|
|
|
|
return Database.select("food",foodH,foodD);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> getFood_plan(String date){
|
|
|
|
String[] food_planH = {"date"};
|
|
|
|
String[] food_planD = {date};
|
|
|
|
return Database.select("food_plan",food_planH,food_planD);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> getFoodById(long id){
|
|
|
|
return Database.getEntryById("food",id);
|
|
|
|
}
|
2023-01-06 01:51:42 +01:00
|
|
|
|
|
|
|
public static long createFood_selection(String[] food_selectionData){
|
2023-01-07 23:14:41 +01:00
|
|
|
String[] food_selectionH = {"childid","food_planid","foodid"};
|
|
|
|
List<String> food_plan = Database.getEntryById("food_plan",Long.parseLong(food_selectionData[1]));
|
|
|
|
String[] food_planParts = food_plan.get(0).split(":");
|
|
|
|
if(Long.parseLong(food_planParts[6]) == 0){
|
|
|
|
return Database.insert("food_selection",food_selectionH,food_selectionData);
|
|
|
|
}else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> getDayOrder(String date){
|
|
|
|
List<String> orders = new ArrayList<>();
|
|
|
|
List<String> food_plan = getFood_plan(date);
|
|
|
|
String[] food_planParts = food_plan.get(0).split(":");
|
|
|
|
for(int i = 2; i < 2+4; i++){
|
|
|
|
List<String> food = getFoodById(Long.parseLong(food_planParts[i]));
|
|
|
|
String[] foodParts = food.get(0).split(":");
|
|
|
|
String foodName = foodParts[1];
|
|
|
|
String[] food_selectionH = {"food_planid","foodid"};
|
|
|
|
String[] food_selectionD = {food_planParts[0],foodParts[0]};
|
|
|
|
int count = Database.count("food_selection",food_selectionH,food_selectionD);
|
|
|
|
orders.add(foodName+":"+count);
|
|
|
|
}
|
|
|
|
String[] updateH = {"id","issent"};
|
|
|
|
String[] updateD = {food_planParts[0],"1"};
|
|
|
|
if(Database.update("food_plan",updateH,updateD) < 0){
|
|
|
|
System.out.println("Fehler");
|
|
|
|
}
|
|
|
|
return orders;
|
2023-01-06 01:51:42 +01:00
|
|
|
}
|
2023-01-05 05:06:19 +01:00
|
|
|
}
|