From 215ddf86cb50fd48d81cdf2e8913a5dd3d5052be Mon Sep 17 00:00:00 2001 From: Samuel Wolff Date: Sun, 14 Jan 2024 17:51:11 +0100 Subject: [PATCH] TestsDone --- Controller/InhaltsstoffController.php | 2 +- Controller/istTeilController.php | 35 ++++++++--- Model/InhaltsstoffModel.php | 9 ++- Model/KindModel.php | 2 +- Model/istTeilModel.php | 91 ++++++++++++++++++--------- 5 files changed, 95 insertions(+), 44 deletions(-) diff --git a/Controller/InhaltsstoffController.php b/Controller/InhaltsstoffController.php index 4a02cd1..756a84d 100644 --- a/Controller/InhaltsstoffController.php +++ b/Controller/InhaltsstoffController.php @@ -23,7 +23,7 @@ class InhaltsstoffController return json_encode($result); } - public function insertInhaltsstoff($data) + public function writeInhaltsstoff($data) { $result = $this->db->insertInhaltsstoff($data); return json_encode($result); diff --git a/Controller/istTeilController.php b/Controller/istTeilController.php index 3aece25..f2ee50f 100644 --- a/Controller/istTeilController.php +++ b/Controller/istTeilController.php @@ -1,21 +1,40 @@ db = new istTeilModel(); + + $this->db = new istTeilModel(); } - public function getBestellung(){ - $result = $this->db->getBestellung(); + public function getIstTeil() + { + $result = $this->db->selectIstTeil(); return json_encode($result); } + + public function writeIstTeil($data) + { + $result = $this->db->insertIstTeil($data); + + return json_encode($result); + } + + public function deleteIstTeil($id) + { + $result = $this->db->deleteIstTeil($id); + + return json_encode($result); + } + } -?> +?> \ No newline at end of file diff --git a/Model/InhaltsstoffModel.php b/Model/InhaltsstoffModel.php index e4e46c8..6f4e240 100644 --- a/Model/InhaltsstoffModel.php +++ b/Model/InhaltsstoffModel.php @@ -1,4 +1,5 @@ linkDB(); $params = array(); - $sql = "INSERT INTO Inhaltsstoff "; + $sql = "INSERT INTO Inhaltsstoff ("; foreach ($data as $index => $value) { $sql .= "" . $index . ","; } $sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES ("; foreach ($data as $index => $value) { - $sql .= "':" . $index . "',"; + $sql .= ":" . $index . ","; $params[":" . $index] = $value; } @@ -44,6 +45,7 @@ class InhaltsstoffModel extends Database $stmt->execute($params); return true; } catch (\PDOException $e) { + echo $sql; return false; } } @@ -52,13 +54,14 @@ class InhaltsstoffModel extends Database { $pdo = $this->linkDB(); $params = array(); - $sql = "DELETE FROM Inhalsstoff WHERE id=:id"; + $sql = "DELETE FROM Inhaltsstoff WHERE id=:id"; $params[":id"] = $id; try { $stmt = $pdo->prepare($sql); $stmt->execute($params); return true; } catch (\PDOException $e) { + echo $sql; return false; } } diff --git a/Model/KindModel.php b/Model/KindModel.php index 21162af..651ef2c 100644 --- a/Model/KindModel.php +++ b/Model/KindModel.php @@ -1,7 +1,7 @@ linkDB(); + public function selectIstTeil() + { + $pdo = $this->linkDB(); - $sql = "SELECT bid FROM istTeil"; - - try { - $stmt = $pdo->prepare($sql); - }catch (\PDOException $e){ - //nur zum Testen: - //new Msg(true,null,$e); - //echo $e; - return false; - } - return $stmt->fetchAll(\PDO::FETCH_ASSOC); - } - - - public function InsertIstTeil($data){ - $pdo = $this -> linkDB(); - - $sql = "INSERT INTO istTeil(bid, gid)"; - - + $sql = "SELECT * FROM istTeil"; try { $stmt = $pdo->prepare($sql); - }catch (\PDOException $e){ - //nur zum Testen: - //new Msg(true,null,$e); - //echo $e; + $stmt->execute(); + } catch (\PDOException $e) { return false; } - return $stmt->fetchAll(\PDO::FETCH_ASSOC); + $results = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + foreach ($results as $key => $value) { + $results[$key]["bid"] += 0; + $results[$key]["gid"] += 0; + $results[$key]["id"] += 0; + } + + return $results; + } + + public function insertIstTeil($data) + { + $pdo = $this->linkDB(); + + $params = array(); + + $sql = "INSERT INTO istTeil (bid, gid) VALUES (:bid, :gid)"; + + foreach ($data as $key => $value) { + $params[":" . $key] = $value; + } + + try { + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + } catch (\PDOException $e) { + return false; + } + return true; + } + + public function deleteIstTeil($id) + { + $pdo = $this->linkDB(); + + $params = array(); + + $sql = "DELETE FROM istTeil WHERE id = :id"; + + $params[":id"] = $id; + + try { + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + } catch (\PDOException $e) { + return false; + } + return true; } } ?> \ No newline at end of file