141 lines
2.7 KiB
PHP
141 lines
2.7 KiB
PHP
<?php
|
|
|
|
// Programmiert durch Samuel Wolff
|
|
// Getestet durch: Nicht getestet
|
|
|
|
namespace kindergartenverwaltung\Model;
|
|
|
|
use kindergartenverwaltung\Library\Msg;
|
|
|
|
|
|
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.
|
|
id($parentId !== false){
|
|
$sql. = " WHERE bid=:id;";
|
|
$params[":id"] = $parentId;
|
|
}
|
|
|
|
try{
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->excute($params);
|
|
}
|
|
catch(\PDOException $e){
|
|
return false;
|
|
}
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* @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;
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
?>
|