18 Commits

Author SHA1 Message Date
694802e314 jetestet, wirklisch 2024-01-18 12:06:22 +01:00
b8f03d4321 suche nach name, nicht id 2024-01-18 10:47:56 +01:00
137c0f7550 getestet 2024-01-18 10:28:16 +01:00
5caa672a26 BenutzerV2 2024-01-18 10:14:52 +01:00
a8f4455c9d getBenutzer 2024-01-18 10:00:42 +01:00
1826e9f61b Merge pull request 'Testing' (#10) from Testing into main
Reviewed-on: #10
2024-01-17 10:24:24 +01:00
1357e21155 ??? 2024-01-17 10:21:14 +01:00
d4a67f0a30 Merge branch 'Testing' of https://git.bib.de/Subway-Surfers/VPR_Schnittstelle into Testing 2024-01-17 10:21:04 +01:00
2b14563643 nextId 2024-01-15 09:39:19 +01:00
9c82aec3c5 nextId 2024-01-15 08:58:24 +01:00
b6ec972c19 Merge pull request 'filter und GibtsAm Tests' (#9) from Testing into main
Reviewed-on: #9
2024-01-14 23:27:08 +01:00
ab9b8ee706 filter und GibtsAm Tests 2024-01-14 23:25:25 +01:00
3f5bd9b1bc Merge pull request 'Testing' (#7) from Testing into main
Reviewed-on: #7
2024-01-14 18:31:59 +01:00
d4c11ef611 Test waren doch noch nicht done *smileyface* 2024-01-14 18:30:05 +01:00
f0caeb3cfc Merge Konflikte bereinigt 2024-01-14 18:11:27 +01:00
7b55e50029 SvenControllerUndModellFertigFertig 2024-01-13 15:51:38 +01:00
7bb6d00eb1 Merge pull request 'Tagesplan erstellt nicht getestet' (#8) from max into main
Reviewed-on: #8
2023-12-20 09:14:37 +01:00
b104c8a6fc Tagesplan erstellt nicht getestet 2023-12-20 09:12:15 +01:00
17 changed files with 462 additions and 74 deletions

View File

@@ -1,7 +1,7 @@
<?php <?php
// Programmiert durch Samuel Wolff // Programmiert durch Samuel Wolff
// Getestet durch: Nicht getestet // Getestet durch: Samuel Wolff
namespace ppb\Controller; namespace ppb\Controller;
@@ -18,6 +18,18 @@ class BenutzerController
$this->db = new BenutzerModel(); $this->db = new BenutzerModel();
} }
public function getBenutzer() {
$result = $this->db->selectBenutzer();
if (isset($_GET["name"])) {
if ($result)
$result = $result[0];
else
$result = false;
}
return json_encode($result);
}
// Updated einen Benutzer // Updated einen Benutzer
public function updateBenutzer($elternId, $data) public function updateBenutzer($elternId, $data)
{ {
@@ -36,6 +48,14 @@ class BenutzerController
return json_encode($data); return json_encode($data);
} }
public function nextId()
{
$result = $this->db->nextId();
return json_encode($result);
}
} }
?> ?>

View File

@@ -1,6 +1,6 @@
<?php <?php
//Programmierung: Sven Alteköster 100% //Programmierung: Sven Alteköster 100%
//Getestet durch: Samuel Wolff //Getestet durch: Sven Alteköster 100%
namespace ppb\Controller; namespace ppb\Controller;

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

@@ -1,6 +1,6 @@
<?php <?php
//Programmierung: Sven Alteköster 100% //Programmierung: Sven Alteköster 100%
//Getestet durch: //Getestet durch: Sven Alteköster 100%
namespace ppb\Controller; namespace ppb\Controller;

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);
}
}
?>

View File

@@ -1,5 +1,5 @@
<?php <?php
//Programmiert von: Max Heer, Getestet von: //Programmiert von: Max Heer, Getestet von: Samuel Wolff
namespace ppb\Controller; namespace ppb\Controller;

View File

@@ -0,0 +1,37 @@
<?php
//Programmiert von: Max Heer, Getestet von: Samuel Wolff
namespace ppb\Controller;
use ppb\Libary\Msg;
use ppb\Model\TagesplanModel;
class TagesplanController
{
private $db;
public function __construct()
{
$this->db = new TagesplanModel();
}
public function getTagesplan()
{
$result = $this->db->getTagesplan();
return json_encode($result);
}
public function writeTagesplan($data)
{
$result = $this->db->insertTagesplan($data);
return json_encode($result);
}
public function deleteTagesplan($id)
{
$result = $this->db->deleteTagesplan($id);
return json_encode($result);
}
}
?>

View File

@@ -1,5 +1,5 @@
<?php <?php
// Erstellt durch Stefan Groß - Nicht getestet // Erstellt durch Stefan Groß - Getestet von Samuel Wolff
namespace ppb\Controller; namespace ppb\Controller;
use ppb\Model\IstTeilModel; use ppb\Model\IstTeilModel;

View File

@@ -9,6 +9,37 @@ use ppb\Library\Msg;
class BenutzerModel extends Database class BenutzerModel extends Database
{ {
public function selectBenutzer()
{
$pdo = $this->linkDB();
$params = array();
$sql = "SELECT * FROM Benutzerkonto";
if(isset($_GET["name"])){
$params[":name"] = $_GET["name"];
$sql .= " WHERE name = :name";
}
//Ausführen des SQL befehls
try {
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
} catch (\PDOException $e) {
echo $e;
return false;
}
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
//Die Datensätze werden nummeriert
foreach ($result as $key => $row) {
$result[$key]["id"] += 0;
}
return $result;
}
/** /**
@@ -94,7 +125,25 @@ class BenutzerModel extends Database
return $result; return $result;
} }
public function nextId()
{
$pdo = $this->linkDB();
$sql = "SELECT `auto_increment` FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'Benutzerkonto'; ";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
return false;
}
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
return $result;
}
} }
?> ?>

View File

@@ -1,4 +1,6 @@
<?php <?php
//Programmierung: Sven Alteköster 100%
//Getestet durch: Sven Alteköster 100%
namespace ppb\Model; namespace ppb\Model;
@@ -9,18 +11,20 @@ class BestellungModel extends Database
/** /**
* Sucht die Bestellung in der Datenbank und gibt diese im json-Format zurück. * Sucht die Bestellung in der Datenbank und gibt diese im json-Format zurück.
* @param $id gibt die id, des gesuchten Objektes an. Wenn keine id angegeben wird, werden alle Einträge ausgegeben * @param $id gibt die id, des Benutzerkontos an, über den die Bestellung getätigt wurde. Wenn keine id angegeben wird, werden alle Einträge ausgegeben
*/ */
public function selectBestellung($id = false) public function selectBestellung($id = false)
{ {
$pdo = $this->linkDB(); $pdo = $this->linkDB();
$sql = "SELECT * FROM Bestellung"; $sql = "SELECT Bestellung.id, Bestellung.istBezahlt, Bestellung.bestelldatum, Bestellung.gesamtpreis, Bestellung.kid FROM Bestellung";
$params = array(); $params = array();
//Ist eine id angegeben wird der Datensatz in der Datenbank gesucht //Ist eine id angegeben wird der Datensatz in der Datenbank gesucht
if ($id !== false) { if ($id !== false) {
$sql .= " WHERE id = :id"; $sql .= " INNER JOIN Kind k ON k.id = kid INNER JOIN Benutzerkonto b ON b.id = bid";
$params["id"] = $id; $sql .= " WHERE bid = :bid";
$params["bid"] = $id;
} }
//Ausführen des SQL befehls //Ausführen des SQL befehls
try { try {
$stmt = $pdo->prepare($sql); $stmt = $pdo->prepare($sql);

View File

@@ -1,5 +1,7 @@
<?php <?php
//Programmiert von: Max Heer, Getestet von: Samuel Wolff
namespace ppb\Model; namespace ppb\Model;
use ppb\Library\Msg; use ppb\Library\Msg;

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;
}
}

View File

@@ -1,4 +1,6 @@
<?php <?php
//Programmierung: Sven Alteköster 100%
//Getestet durch: Sven Alteköster 100%
namespace ppb\Model; namespace ppb\Model;

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;
}
}
?>

View File

@@ -1,4 +1,5 @@
<?php <?php
// Programmiert von Max Heer
// Getestet von Samuel Wolff // Getestet von Samuel Wolff
namespace ppb\Model; namespace ppb\Model;

69
Model/TagesplanModel.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
//Programmiert von: Max Heer, Getestet von: Samuel Wolff
namespace ppb\Model;
use ppb\Library\Msg;
class TagesplanModel extends Database
{
public function getTagesplan()
{
$pdo = $this->linkDB();
$sql = "SELECT * FROM Tagesplan";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
return false;
}
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
public function insertTagesplan($data)
{
$pdo = $this->linkDB();
$params = array();
$sql = "INSERT INTO Tagesplan (";
foreach ($data as $index => $value) {
$sql .= "" . $index . ",";
}
$sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES (";
foreach ($data as $index => $value) {
$sql .= ":" . $index . ",";
$params[":" . $index] = $value;
}
$sql = substr($sql, 0, strlen($sql) - 1) . ");";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
echo $sql;
return false;
}
}
public function deleteTagesplan($id)
{
$pdo = $this->linkDB();
$params = array();
$sql = "DELETE FROM Tagesplan WHERE id=:id";
$params[":id"] = $id;
try {
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
return false;
}
}
}
?>

View File

@@ -1,4 +1,4 @@
<?php <?php
/* /*
Dieses Skript analysiert die URL und generiert daraus die passenden Controller-Aufrufe Dieses Skript analysiert die URL und generiert daraus die passenden Controller-Aufrufe
@@ -14,72 +14,76 @@
file_get_contents('php://input') die übergebenen json-Strings (für PUT/POST-Requests) file_get_contents('php://input') die übergebenen json-Strings (für PUT/POST-Requests)
*/ */
spl_autoload_register(function ($className) { spl_autoload_register(function ($className) {
if (substr($className, 0, 4) !== 'ppb\\') { return; } if (substr($className, 0, 4) !== 'ppb\\') {
return;
$fileName = __DIR__.'/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)).'.php';
if (file_exists($fileName)) { include $fileName; }
});
$endpoint = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$data = json_decode(file_get_contents('php://input'), true);
$controllerName = $endpoint[0];
$endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false;
$id = false;
$alias = false;
if ($endpoint2) {
if (preg_match('/^[0-9]+$/', $endpoint2)) {
$id = $endpoint2;
} else {
$alias = $endpoint2;
}
} }
$controllerClassName = 'ppb\\Controller\\'.ucfirst($controllerName). 'Controller'; $fileName = __DIR__ . '/' . str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)) . '.php';
if ($_SERVER['REQUEST_METHOD'] == "DELETE") { if (file_exists($fileName)) {
$methodName = "delete" . ucfirst($controllerName); include $fileName;
} else if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$methodName = "update" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
$methodName = "write" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($alias) {
$methodName = $alias;
} else {
$methodName = "get" . ucfirst($controllerName);
}
} }
});
if (method_exists($controllerClassName, $methodName)) {
$endpoint = explode('/', trim($_SERVER['PATH_INFO'], '/'));
header('Content-Type: application/json'); $data = json_decode(file_get_contents('php://input'), true);
$controller = new $controllerClassName(); $controllerName = $endpoint[0];
//GET $endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false;
if ($_SERVER['REQUEST_METHOD'] == "GET") { $id = false;
$alias = false;
echo $controller->$methodName($id);
if ($endpoint2) {
} else if (preg_match('/^[0-9]+$/', $endpoint2)) {
//POST $id = $endpoint2;
if ($_SERVER['REQUEST_METHOD'] == "POST"){
echo $controller->$methodName($data);
} else
//DELETE
if ($_SERVER['REQUEST_METHOD'] == "DELETE"){
echo $controller->$methodName($id);
} else
//PUT
{
echo $controller->$methodName($id, $data);
}
} else { } else {
//http_response_code(404); $alias = $endpoint2;
new \ppb\Library\Msg(true, 'Page not found: '.$controllerClassName.'::'.$methodName);
} }
}
$controllerClassName = 'ppb\\Controller\\' . ucfirst($controllerName) . 'Controller';
if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
$methodName = "delete" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$methodName = "update" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
$methodName = "write" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($alias) {
$methodName = $alias;
} else {
$methodName = "get" . ucfirst($controllerName);
}
}
if (method_exists($controllerClassName, $methodName)) {
header('Content-Type: application/json');
$controller = new $controllerClassName();
//GET
if ($_SERVER['REQUEST_METHOD'] == "GET") {
echo $controller->$methodName($id);
} else
//POST
if ($_SERVER['REQUEST_METHOD'] == "POST") {
echo $controller->$methodName($data);
} else
//DELETE
if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
echo $controller->$methodName($id);
} else
//PUT
{
echo $controller->$methodName($id, $data);
}
} else {
//http_response_code(404);
new \ppb\Library\Msg(true, 'Page not found: ' . $controllerClassName . '::' . $methodName);
}
?> ?>