Compare commits
	
		
			26 Commits
		
	
	
		
			3f5bd9b1bc
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2a1ab99070 | |||
| 5db540d1d1 | |||
| bc4d16055f | |||
| c9a52853e5 | |||
| 694802e314 | |||
| b8f03d4321 | |||
| 28dc1b076f | |||
| 555b475b69 | |||
| 137c0f7550 | |||
| 93e3b8e0c8 | |||
| 64b6aa2716 | |||
| 34ae68bfdc | |||
| 5caa672a26 | |||
| 1f2789eead | |||
| 40b6c85eb9 | |||
| bbb5ebcbac | |||
| a8f4455c9d | |||
| e730377103 | |||
| add9a27630 | |||
| 1826e9f61b | |||
| 1357e21155 | |||
| d4a67f0a30 | |||
| 2b14563643 | |||
| 9c82aec3c5 | |||
| b6ec972c19 | |||
| ab9b8ee706 | 
| @@ -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,21 @@ class BenutzerController | |||||||
|         return json_encode($data); |         return json_encode($data); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     public function nextId() | ||||||
|  |     { | ||||||
|  |         $result = $this->db->nextId(); | ||||||
|  |  | ||||||
|  |         return json_encode($result); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function anmeldeVersuch() | ||||||
|  |     { | ||||||
|  |         $result = $this->db->anmeldeVersuch(); | ||||||
|  |  | ||||||
|  |         return json_encode($result); | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| ?> | ?> | ||||||
							
								
								
									
										32
									
								
								Controller/FilterController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Controller/FilterController.php
									
									
									
									
									
										Normal 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); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										42
									
								
								Controller/GibtsAmController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Controller/GibtsAmController.php
									
									
									
									
									
										Normal 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); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ?> | ||||||
| @@ -48,7 +48,7 @@ class KindController | |||||||
|     { |     { | ||||||
|         $result = $this->db->deleteKind($kindId); |         $result = $this->db->deleteKind($kindId); | ||||||
|  |  | ||||||
|         return $result; |         return json_encode($result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -33,5 +33,11 @@ class TagesplanController | |||||||
|         $result = $this->db->deleteTagesplan($id); |         $result = $this->db->deleteTagesplan($id); | ||||||
|         return json_encode($result); |         return json_encode($result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public function getGerichteOnTag() | ||||||
|  |     { | ||||||
|  |         $result = $this->db->getGerichteOnTag(); | ||||||
|  |         return json_encode($result); | ||||||
|  |     } | ||||||
| } | } | ||||||
| ?> | ?> | ||||||
| @@ -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; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -86,6 +117,7 @@ class BenutzerModel extends Database | |||||||
|             $stmt = $pdo->prepare($sql); |             $stmt = $pdo->prepare($sql); | ||||||
|             $stmt->execute($params); |             $stmt->execute($params); | ||||||
|         } catch (\PDOException $e) { |         } catch (\PDOException $e) { | ||||||
|  |             echo "Faulty Sql? " . $sql; | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -94,7 +126,54 @@ 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) { | ||||||
|  |             echo "Faulty Sql? " . $sql; | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $result = $stmt->fetchALL(\PDO::FETCH_ASSOC); | ||||||
|  |  | ||||||
|  |         return $result; | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function anmeldeVersuch() | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $pdo = $this->linkDB(); | ||||||
|  |  | ||||||
|  |         $params = array(); | ||||||
|  |  | ||||||
|  |         $params[":Benutzername"] = $_GET["Benutzername"]; | ||||||
|  |         $params[":passwort"] = $_GET["passwort"]; | ||||||
|  |  | ||||||
|  |         $sql = "SELECT * FROM Benutzerkonto WHERE name = :Benutzername AND passwort = :passwort"; | ||||||
|  |  | ||||||
|  |         try { | ||||||
|  |             $stmt = $pdo->prepare($sql); | ||||||
|  |             $stmt->execute($params); | ||||||
|  |         } catch (\PDOException $e) { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $result = $stmt->fetchALL(\PDO::FETCH_ASSOC); | ||||||
|  |  | ||||||
|  |         if (count($result) > 0) | ||||||
|  |             return true; | ||||||
|  |         else | ||||||
|  |             return false; | ||||||
|  |  | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| ?> | ?> | ||||||
							
								
								
									
										52
									
								
								Model/FilterModel.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Model/FilterModel.php
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										74
									
								
								Model/GibtsAmModel.php
									
									
									
									
									
										Normal 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; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ?> | ||||||
| @@ -65,5 +65,28 @@ class TagesplanModel extends Database | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public function getGerichteOnTag() | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $pdo = $this->linkDB(); | ||||||
|  |  | ||||||
|  |         $datum = $_GET["datum"]; | ||||||
|  |  | ||||||
|  |         $sql = "SELECT Gericht.id, Gericht.name, Gericht.preis, Gericht.beschreibung FROM Gericht LEFT JOIN GibtsAm ON Gericht.id = GibtsAm.gid LEFT JOIN Tagesplan ON GibtsAm.tid = Tagesplan.id WHERE Tagesplan.datum = '$datum'"; | ||||||
|  |  | ||||||
|  |         try { | ||||||
|  |             $stmt = $pdo->prepare($sql); | ||||||
|  |             $stmt->execute(); | ||||||
|  |         } catch (\PDOException $e) { | ||||||
|  |             echo $sql . " This do be faulty"; | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); | ||||||
|  |  | ||||||
|  |         return $result; | ||||||
|  |  | ||||||
|  |     } | ||||||
| } | } | ||||||
| ?> | ?> | ||||||
							
								
								
									
										54
									
								
								restAPI.php
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								restAPI.php
									
									
									
									
									
								
							| @@ -14,47 +14,51 @@ | |||||||
|     |     | ||||||
|    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'; |     $fileName = __DIR__ . '/' . str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)) . '.php'; | ||||||
|  |  | ||||||
|         if (file_exists($fileName)) { include $fileName; } |     if (file_exists($fileName)) { | ||||||
|     });     |         include $fileName; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
|     $endpoint = explode('/', trim($_SERVER['PATH_INFO'],'/')); | $endpoint = explode('/', trim($_SERVER['PATH_INFO'], '/')); | ||||||
|     $data = json_decode(file_get_contents('php://input'), true); | $data = json_decode(file_get_contents('php://input'), true); | ||||||
|  |  | ||||||
|     $controllerName = $endpoint[0]; | $controllerName = $endpoint[0]; | ||||||
|     $endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false; | $endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false; | ||||||
|     $id = false; | $id = false; | ||||||
|     $alias = false; | $alias = false; | ||||||
|  |  | ||||||
|     if ($endpoint2) { | if ($endpoint2) { | ||||||
|     if (preg_match('/^[0-9]+$/', $endpoint2)) { |     if (preg_match('/^[0-9]+$/', $endpoint2)) { | ||||||
|         $id = $endpoint2; |         $id = $endpoint2; | ||||||
|     } else { |     } else { | ||||||
|         $alias = $endpoint2; |         $alias = $endpoint2; | ||||||
|     } |     } | ||||||
|     } | } | ||||||
|  |  | ||||||
|     $controllerClassName = 'ppb\\Controller\\'.ucfirst($controllerName). 'Controller'; | $controllerClassName = 'ppb\\Controller\\' . ucfirst($controllerName) . 'Controller'; | ||||||
|  |  | ||||||
|     if ($_SERVER['REQUEST_METHOD'] == "DELETE") { | if ($_SERVER['REQUEST_METHOD'] == "DELETE") { | ||||||
|     $methodName = "delete" . ucfirst($controllerName); |     $methodName = "delete" . ucfirst($controllerName); | ||||||
|     } else if ($_SERVER['REQUEST_METHOD'] == "PUT") { | } else if ($_SERVER['REQUEST_METHOD'] == "PUT") { | ||||||
|     $methodName = "update" . ucfirst($controllerName); |     $methodName = "update" . ucfirst($controllerName); | ||||||
|     } else if ($_SERVER['REQUEST_METHOD'] == "POST") { | } else if ($_SERVER['REQUEST_METHOD'] == "POST") { | ||||||
|     $methodName = "write" . ucfirst($controllerName); |     $methodName = "write" . ucfirst($controllerName); | ||||||
|     } else if ($_SERVER['REQUEST_METHOD'] == "GET") { | } else if ($_SERVER['REQUEST_METHOD'] == "GET") { | ||||||
|     if ($alias) { |     if ($alias) { | ||||||
|         $methodName = $alias; |         $methodName = $alias; | ||||||
|     } else { |     } else { | ||||||
|         $methodName = "get" . ucfirst($controllerName); |         $methodName = "get" . ucfirst($controllerName); | ||||||
|     } |     } | ||||||
|     } | } | ||||||
|  |  | ||||||
|     if (method_exists($controllerClassName, $methodName)) { | if (method_exists($controllerClassName, $methodName)) { | ||||||
|  |  | ||||||
|     header('Content-Type: application/json'); |     header('Content-Type: application/json'); | ||||||
|  |  | ||||||
| @@ -66,20 +70,20 @@ | |||||||
|  |  | ||||||
|     } else |     } else | ||||||
|         //POST	 |         //POST	 | ||||||
| 		if ($_SERVER['REQUEST_METHOD'] == "POST"){ |         if ($_SERVER['REQUEST_METHOD'] == "POST") { | ||||||
|             echo $controller->$methodName($data); |             echo $controller->$methodName($data); | ||||||
|         } else |         } else | ||||||
|             //DELETE	 |             //DELETE	 | ||||||
| 		if ($_SERVER['REQUEST_METHOD'] == "DELETE"){ |             if ($_SERVER['REQUEST_METHOD'] == "DELETE") { | ||||||
|                 echo $controller->$methodName($id); |                 echo $controller->$methodName($id); | ||||||
|             } else |             } else | ||||||
|             //PUT |             //PUT | ||||||
|             { |             { | ||||||
|                 echo $controller->$methodName($id, $data); |                 echo $controller->$methodName($id, $data); | ||||||
|             } |             } | ||||||
|     } else { | } else { | ||||||
|     //http_response_code(404); |     //http_response_code(404); | ||||||
|         new \ppb\Library\Msg(true, 'Page not found: '.$controllerClassName.'::'.$methodName);  |     new \ppb\Library\Msg(true, 'Page not found: ' . $controllerClassName . '::' . $methodName); | ||||||
|  |  | ||||||
|     } | } | ||||||
| ?> | ?> | ||||||
		Reference in New Issue
	
	Block a user