From ab9b8ee7066d09b7bd8fe2d376b0679aeeb86261 Mon Sep 17 00:00:00 2001 From: Samuel Wolff Date: Sun, 14 Jan 2024 23:25:25 +0100 Subject: [PATCH] filter und GibtsAm Tests --- Controller/FilterController.php | 32 ++++++++++++++ Controller/GibtsAmController.php | 42 ++++++++++++++++++ Model/FilterModel.php | 52 ++++++++++++++++++++++ Model/GibtsAmModel.php | 74 ++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 Controller/FilterController.php create mode 100644 Controller/GibtsAmController.php create mode 100644 Model/FilterModel.php create mode 100644 Model/GibtsAmModel.php diff --git a/Controller/FilterController.php b/Controller/FilterController.php new file mode 100644 index 0000000..20b43ac --- /dev/null +++ b/Controller/FilterController.php @@ -0,0 +1,32 @@ +db = new FilterModel(); + + + } + + public function writeFilter($data) + { + $results = $this->db->insertFilter($data); + + return json_encode($results); + } + + public function deleteFilter($id) + { + $results = $this->db->deleteFilter($id); + + return json_encode($results); + } +} \ No newline at end of file diff --git a/Controller/GibtsAmController.php b/Controller/GibtsAmController.php new file mode 100644 index 0000000..6d301ad --- /dev/null +++ b/Controller/GibtsAmController.php @@ -0,0 +1,42 @@ +db = new GibtsAmModel(); + + + } + + public function getGibtsAm() + { + $result = $this->db->selectGibtsAm(); + + return json_encode($result); + } + + public function writeGibtsAm($data) + { + $result = $this->db->insertGibtsAm($data); + + return json_encode($result); + } + + public function deleteGibtsAm($id) + { + $result = $this->db->deleteGibtsAm($id); + + return json_encode($result); + } +} + + +?> \ No newline at end of file diff --git a/Model/FilterModel.php b/Model/FilterModel.php new file mode 100644 index 0000000..f3f6270 --- /dev/null +++ b/Model/FilterModel.php @@ -0,0 +1,52 @@ +linkDB(); + + $params = array(); + + $sql = "INSERT INTO Filter (kid, iid) VALUES (:kid, :iid)"; + + $params[":kid"] = $data["kid"]; + $params[":iid"] = $data["iid"]; + + try { + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + } catch (\PDOException $e) { + echo $sql; + return false; + } + return true; + } + + public function deleteFilter($id) + { + $pdo = $this->linkDB(); + + $params = array(); + + $sql = "DELETE FROM Filter WHERE id = :id"; + + $params[":id"] = $id; + + try { + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + } catch (\PDOException $e) { + echo $sql; + return false; + } + return true; + } +} \ No newline at end of file diff --git a/Model/GibtsAmModel.php b/Model/GibtsAmModel.php new file mode 100644 index 0000000..38225b2 --- /dev/null +++ b/Model/GibtsAmModel.php @@ -0,0 +1,74 @@ +linkDB(); + + $sql = "SELECT * FROM GibtsAm"; + + try { + $stmt = $pdo->prepare($sql); + $stmt->execute(); + } catch (\PDOException $e) { + return false; + } + + $results = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + foreach ($results as $key => $value) { + $results[$key]["id"] += 0; + $results[$key]["tid"] += 0; + $results[$key]["gid"] += 0; + } + + return $results; + } + + public function insertGibtsAm($data) + { + $pdo = $this->linkDB(); + + $params = array(); + + $sql = "INSERT INTO GibtsAm (tid, gid) VALUES (:tid, :gid)"; + $params[":tid"] = $data["tid"]; + $params[":gid"] = $data["gid"]; + + try { + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + } catch (\PDOException $e) { + echo $sql; + return false; + } + return true; + } + + public function deleteGibtsAm($id) + { + $pdo = $this->linkDB(); + + $params = array(); + + $sql = "DELETE FROM GibtsAm 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