2023-12-06 08:33:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Programmiert durch Samuel Wolff
|
|
|
|
// Getestet durch: Nicht getestet
|
|
|
|
|
2023-12-14 16:59:16 +01:00
|
|
|
namespace ppb\Model;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-14 16:59:16 +01:00
|
|
|
use ppb\Library\Msg;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
class KindModel extends Database{
|
|
|
|
|
|
|
|
public function getKind($parentId){
|
|
|
|
$pdo = $this->linkDB();
|
|
|
|
|
|
|
|
$params = array();
|
|
|
|
$sql = "SELECT * FROM Kind";
|
|
|
|
|
|
|
|
|
|
|
|
// Das mitgeben einer Id erlaubt es die Kinder eines bestimmten Benutzerkontos anzeigen zu lassen,
|
|
|
|
// während das leerlassen alle Kinder ausgibt.
|
2023-12-14 16:59:16 +01:00
|
|
|
if($parentId !== false){
|
|
|
|
$sql .= " WHERE bid=:id;";
|
2023-12-06 08:33:25 +01:00
|
|
|
$params[":id"] = $parentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
|
|
|
$stmt = $pdo->prepare($sql);
|
2023-12-14 16:59:16 +01:00
|
|
|
$stmt->execute($params);
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
|
|
|
catch(\PDOException $e){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-11 15:32:24 +01:00
|
|
|
*
|
2023-12-06 08:33:25 +01:00
|
|
|
* Updated die Daten eines Kindes
|
|
|
|
*
|
|
|
|
* @param $kindId Id des Kindes
|
|
|
|
* @param $data Json encoded Daten mit den neuen Werten
|
|
|
|
*/
|
|
|
|
public function updateKind($kindId, $data){
|
|
|
|
$pdo = $this->linkDB();
|
|
|
|
|
|
|
|
$params = array();
|
|
|
|
$sql = "UPDATE KIND SET";
|
|
|
|
|
|
|
|
// Geht die Json-Daten durch und erweitert den SQL-Query
|
|
|
|
// und setzt die Bindparameter
|
|
|
|
// $index -> Spalte die geupdated wird
|
|
|
|
// $value -> neuer Wert
|
|
|
|
foreach($data as $index=>$value){
|
|
|
|
$sql .= " ".$index." = :".$index;
|
|
|
|
$params[":".$index] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= " WHERE id = :kindId;";
|
|
|
|
|
|
|
|
$params[":kindId"] = $kindId;
|
|
|
|
|
|
|
|
try{
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->excute($params);
|
|
|
|
}
|
|
|
|
catch(\PDOException $e){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-11 15:32:24 +01:00
|
|
|
*
|
|
|
|
* Fügt ein Kind mit gegebenen Daten in die Datenbank hinzu
|
|
|
|
*
|
2023-12-06 08:33:25 +01:00
|
|
|
* @param $data Die Daten für das neue Kind
|
|
|
|
*/
|
|
|
|
public function addKind($data){
|
|
|
|
$pdo = $this->linkDB();
|
|
|
|
|
|
|
|
$params = array();
|
|
|
|
|
|
|
|
$sql = "INSERT INTO Kind (";
|
|
|
|
|
|
|
|
foreach($data as $index=>$value){
|
|
|
|
$sql .= $index.", ";
|
|
|
|
$params[":"+$index] = $index;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = substr($sql, 0, strlen($sql)-2).") VALUES (";
|
|
|
|
|
|
|
|
foreach($data as $value){
|
|
|
|
$sql .= ":".$value." ,";
|
|
|
|
$params[":"+$value] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = substr($sql, 0, strlen($sql)-2).");";
|
|
|
|
|
|
|
|
try{
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->excute($params);
|
|
|
|
}
|
|
|
|
catch(\PDOException $e){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2023-12-11 15:32:24 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Löscht ein Kind mit einer gegebenen Id aus der Datenbank
|
|
|
|
*
|
|
|
|
* @param $kindId Die Id des zu löschenden Kindes
|
|
|
|
*
|
|
|
|
*/
|
2023-12-06 08:33:25 +01:00
|
|
|
public function deleteKind($kindId){
|
|
|
|
$pdo = $this->linkDB();
|
|
|
|
|
|
|
|
$params = array();
|
|
|
|
|
|
|
|
$sql = "DELETE FROM Kind WHERE id = :id";
|
|
|
|
|
|
|
|
$params[":id"] = $kindId;
|
|
|
|
|
|
|
|
try{
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->excute($params);
|
|
|
|
}
|
|
|
|
catch(\PDOException $e){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|