From c47abaf4bb8efe17a7c95831dcc7d80046796667 Mon Sep 17 00:00:00 2001 From: Samuel Wolff Date: Tue, 9 Jan 2024 09:51:28 +0100 Subject: [PATCH] Tests bis zu Gericht Model --- Controller/BestellungController.php | 68 ++++++++++++++++------------- Controller/EnthaeltController.php | 6 +-- Model/EnthaeltModel.php | 4 +- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/Controller/BestellungController.php b/Controller/BestellungController.php index 5f74cc0..b94c1e7 100644 --- a/Controller/BestellungController.php +++ b/Controller/BestellungController.php @@ -1,44 +1,50 @@ db = new BestellungModel(); +class BestellungController +{ + + private $db; + + public function __construct() + { + $this->db = new BestellungModel(); + } + + public function getBestellung($id = false) + { + $result = $this->db->selectBestellung($id); + if ($id !== false) { + if ($result) + $result = $result[0]; + else + $result = false; } - public function getBestellung($id=false) { - $result=$this->db->selectBestellung($id); - if($id !== false){ - if($result) - $result=$result[0]; - else - $result=false; - } - - return json_encode($result); - } + return json_encode($result); + } - public function writeBestellung($data){ - $result=$this->db->insertGericht($data); - return json_encode($result); - } + public function writeBestellung($data) + { + $result = $this->db->insertBestellung($data); + return json_encode($result); + } - public function updateBestellung($id, $data){ - $result=$this->db->updateBestellung($id, $data); - return json_encode($result); - } - - public function deleteBestellung($id){ - $result=$this->db->deleteBestellung($id); - return json_encode($result); - } + public function updateBestellung($id, $data) + { + $result = $this->db->updateBestellung($id, $data); + return json_encode($result); + } + + public function deleteBestellung($id) + { + $result = $this->db->deleteBestellung($id); + return json_encode($result); + } } \ No newline at end of file diff --git a/Controller/EnthaeltController.php b/Controller/EnthaeltController.php index efc77ef..552c3ac 100644 --- a/Controller/EnthaeltController.php +++ b/Controller/EnthaeltController.php @@ -1,5 +1,5 @@ db = new EnthaeltModel(); } - public function getInhaltsstoffe($gerichtId) + public function getEnthaelt($gerichtId) { $result = $this->db->getEnthaelt($gerichtId); return json_encode($result); } - public function insertEnthaelt($data) + public function writeEnthaelt($data) { $result = $this->db->insertEnthaelt($data); return json_encode($result); diff --git a/Model/EnthaeltModel.php b/Model/EnthaeltModel.php index f532ecd..dc25efa 100644 --- a/Model/EnthaeltModel.php +++ b/Model/EnthaeltModel.php @@ -36,12 +36,14 @@ class EnthaeltModel extends Database $sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES ("; foreach ($data as $index => $value) { - $sql .= "':" . $index . "',"; + $sql .= ":" . $index . ","; $params[":" . $index] = $value; } $sql = substr($sql, 0, strlen($sql) - 1) . ");"; + echo $sql; + try { $stmt = $pdo->prepare($sql); $stmt->execute($params);