From b104c8a6fcb21d183ed941b36ffbf6cbc4074671 Mon Sep 17 00:00:00 2001 From: Max Heer Date: Wed, 20 Dec 2023 09:12:15 +0100 Subject: [PATCH] Tagesplan erstellt nicht getestet --- Controller/TagesplanController.php | 23 +++++++++++ Model/EnthaeltModel.php | 2 +- Model/InhaltsstoffModel.php | 5 ++- Model/TagesplanModel.php | 63 ++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 Controller/TagesplanController.php create mode 100644 Model/TagesplanModel.php diff --git a/Controller/TagesplanController.php b/Controller/TagesplanController.php new file mode 100644 index 0000000..b3192e8 --- /dev/null +++ b/Controller/TagesplanController.php @@ -0,0 +1,23 @@ +db->getTagesplan(); + return json_encode($result); + } + + public function insertTagesplan($data){ + $result=$this->db->insertTagesplan($data); + return json_encode($result); + } + + public function deleteTagesplan($id){ + $result=$this->db->deleteTagesplan($id); + return json_encode($result); + } +?> \ No newline at end of file diff --git a/Model/EnthaeltModel.php b/Model/EnthaeltModel.php index a00546d..8b2c907 100644 --- a/Model/EnthaeltModel.php +++ b/Model/EnthaeltModel.php @@ -1,7 +1,7 @@ linkDB(); diff --git a/Model/TagesplanModel.php b/Model/TagesplanModel.php new file mode 100644 index 0000000..aa89ad1 --- /dev/null +++ b/Model/TagesplanModel.php @@ -0,0 +1,63 @@ +linkDB(); + $sql = "SELECT * FROM Tagesplan"; + try{ + $stmt = $pdo->prepare($sql); + $stmt->execute(); + } + catch(\PDOExeption $e){ + return false; + } + $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + return $result; + } + + public function insertTagesplan($data){ + $pdo=$this->linkDB(); + $params = array(); + $sql = "INSERT INTO Tagesplan ("; + foreach($data as $index=>$value){ + $sql .= "".$index.","; + } + $sql = substr($sql,0,strlen($sql)-1).") VALUES ("; + + foreach($data as $index=>$value){ + $sql .= "':".$index."',"; + $params[":".$index] = $value; + } + + $sql = substr($sql,0,strlen($sql)-1).");"; + + try{ + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + return true; + } + catch(\PDOExeption $e){ + return false; + } + } + + public function delteTagesplan($id){ + $pdo=$this->linkDB(); + $params = array(); + $sql = "DELETE FROM Tagesplan WHERE id=:id"; + $params[":id"] = $id; + try{ + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + return true; + } + catch(\PDOExeption $e){ + return false; + } + } +?> \ No newline at end of file -- 2.39.5