filter und GibtsAm Tests

This commit is contained in:
Samuel Wolff 2024-01-14 23:25:25 +01:00
parent d4c11ef611
commit ab9b8ee706
4 changed files with 200 additions and 0 deletions

View File

@ -0,0 +1,32 @@
<?php
//Erstellt durch Stefan Groß - Samuel Wolff
namespace ppb\Controller;
use ppb\Model\FilterModel;
class FilterController
{
private $db;
public function __construct()
{
$this->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);
}
}

View File

@ -0,0 +1,42 @@
<?php
//Erstellt durch Stefan Groß - Getestet von Samuel Wolff
namespace ppb\Controller;
use ppb\Model\GibtsAmModel;
class GibtsAmController
{
private $db;
public function __construct()
{
$this->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);
}
}
?>

52
Model/FilterModel.php Normal file
View File

@ -0,0 +1,52 @@
<?php
namespace ppb\Model;
use ppb\Model\Database;
//Erstellt durch Stefan Groß - Samuel Wolff
class FilterModel extends Database
{
public function insertFilter($data)
{
$pdo = $this->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;
}
}

74
Model/GibtsAmModel.php Normal file
View File

@ -0,0 +1,74 @@
<?php
namespace ppb\Model;
//Programmiert von Stefan Groß - Getestet von Samuel Wolff
class GibtsAmModel extends Database
{
public function selectGibtsAm()
{
$pdo = $this->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;
}
}
?>