Compare commits
	
		
			12 Commits
		
	
	
		
			3f5bd9b1bc
			...
			getBenutze
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 694802e314 | |||
| b8f03d4321 | |||
| 137c0f7550 | |||
| 5caa672a26 | |||
| a8f4455c9d | |||
| 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,14 @@ class BenutzerController | |||||||
|         return json_encode($data); |         return json_encode($data); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     public function nextId() | ||||||
|  |     { | ||||||
|  |         $result = $this->db->nextId(); | ||||||
|  |  | ||||||
|  |         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); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ?> | ||||||
| @@ -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; | ||||||
|  |  | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| ?> | ?> | ||||||
							
								
								
									
										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; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ?> | ||||||
							
								
								
									
										116
									
								
								restAPI.php
									
									
									
									
									
								
							
							
						
						
									
										116
									
								
								restAPI.php
									
									
									
									
									
								
							| @@ -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'], '/')); | ||||||
|  | $data = json_decode(file_get_contents('php://input'), true); | ||||||
|  |  | ||||||
| 		header('Content-Type: application/json'); | $controllerName = $endpoint[0]; | ||||||
|  | $endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false; | ||||||
|  | $id = false; | ||||||
|  | $alias = false; | ||||||
|  |  | ||||||
|         $controller = new $controllerClassName(); | if ($endpoint2) { | ||||||
|         //GET |     if (preg_match('/^[0-9]+$/', $endpoint2)) { | ||||||
| 		if ($_SERVER['REQUEST_METHOD'] == "GET") { |         $id = $endpoint2; | ||||||
|  |     } else { | ||||||
|  |         $alias = $endpoint2; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|             echo $controller->$methodName($id); | $controllerClassName = 'ppb\\Controller\\' . ucfirst($controllerName) . 'Controller'; | ||||||
|  |  | ||||||
|         } else  | if ($_SERVER['REQUEST_METHOD'] == "DELETE") { | ||||||
| 		//POST	 |     $methodName = "delete" . ucfirst($controllerName); | ||||||
| 		if ($_SERVER['REQUEST_METHOD'] == "POST"){ | } 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); |             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