From d4c11ef6112afb0a467eacb75170b980a2ae9c5c Mon Sep 17 00:00:00 2001 From: Samuel Wolff Date: Sun, 14 Jan 2024 18:30:05 +0100 Subject: [PATCH] Test waren doch noch nicht done *smileyface* --- Controller/BenutzerController.php | 2 +- Controller/InhaltsstoffController.php | 2 +- Controller/TagesplanController.php | 34 +++++++++++----- Controller/istTeilController.php | 2 +- Model/EnthaeltModel.php | 2 + Model/InhaltsstoffModel.php | 1 + Model/TagesplanModel.php | 56 +++++++++++++++------------ 7 files changed, 61 insertions(+), 38 deletions(-) diff --git a/Controller/BenutzerController.php b/Controller/BenutzerController.php index 3c5d585..1d6e02b 100644 --- a/Controller/BenutzerController.php +++ b/Controller/BenutzerController.php @@ -1,7 +1,7 @@ db->getTagesplan(); +class TagesplanController +{ + + private $db; + + public function __construct() + { + $this->db = new TagesplanModel(); + } + + public function getTagesplan() + { + $result = $this->db->getTagesplan(); return json_encode($result); } - public function insertTagesplan($data){ - $result=$this->db->insertTagesplan($data); + public function writeTagesplan($data) + { + $result = $this->db->insertTagesplan($data); return json_encode($result); } - public function deleteTagesplan($id){ - $result=$this->db->deleteTagesplan($id); + public function deleteTagesplan($id) + { + $result = $this->db->deleteTagesplan($id); return json_encode($result); } +} ?> \ No newline at end of file diff --git a/Controller/istTeilController.php b/Controller/istTeilController.php index f2ee50f..20e7328 100644 --- a/Controller/istTeilController.php +++ b/Controller/istTeilController.php @@ -1,5 +1,5 @@ linkDB(); +use ppb\Library\Msg; + +class TagesplanModel extends Database +{ + + public function getTagesplan() + { + $pdo = $this->linkDB(); $sql = "SELECT * FROM Tagesplan"; - try{ + try { $stmt = $pdo->prepare($sql); $stmt->execute(); - } - catch(\PDOExeption $e){ + } catch (\PDOException $e) { return false; } $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); @@ -20,44 +24,46 @@ return $result; } - public function insertTagesplan($data){ - $pdo=$this->linkDB(); + public function insertTagesplan($data) + { + $pdo = $this->linkDB(); $params = array(); $sql = "INSERT INTO Tagesplan ("; - foreach($data as $index=>$value){ - $sql .= "".$index.","; + foreach ($data as $index => $value) { + $sql .= "" . $index . ","; } - $sql = substr($sql,0,strlen($sql)-1).") VALUES ("; + $sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES ("; - foreach($data as $index=>$value){ - $sql .= "':".$index."',"; - $params[":".$index] = $value; + foreach ($data as $index => $value) { + $sql .= ":" . $index . ","; + $params[":" . $index] = $value; } - $sql = substr($sql,0,strlen($sql)-1).");"; + $sql = substr($sql, 0, strlen($sql) - 1) . ");"; - try{ + try { $stmt = $pdo->prepare($sql); $stmt->execute($params); return true; - } - catch(\PDOExeption $e){ + } catch (\PDOException $e) { + echo $sql; return false; } } - public function delteTagesplan($id){ - $pdo=$this->linkDB(); + public function deleteTagesplan($id) + { + $pdo = $this->linkDB(); $params = array(); $sql = "DELETE FROM Tagesplan WHERE id=:id"; $params[":id"] = $id; - try{ + try { $stmt = $pdo->prepare($sql); $stmt->execute($params); return true; - } - catch(\PDOExeption $e){ + } catch (\PDOException $e) { return false; } } +} ?> \ No newline at end of file