TestsDone

This commit is contained in:
Samuel Wolff 2024-01-14 17:51:11 +01:00
parent c47abaf4bb
commit 215ddf86cb
5 changed files with 95 additions and 44 deletions

View File

@ -23,7 +23,7 @@ class InhaltsstoffController
return json_encode($result);
}
public function insertInhaltsstoff($data)
public function writeInhaltsstoff($data)
{
$result = $this->db->insertInhaltsstoff($data);
return json_encode($result);

View File

@ -1,8 +1,11 @@
<?php
// Erstellt durch Stefan Groß
namespace kinderverwaltung\Controller;
// Erstellt durch Stefan Groß - Nicht getestet
namespace ppb\Controller;
class istTeilController {
use ppb\Model\IstTeilModel;
class istTeilController
{
private $db;
public function __construct()
@ -12,10 +15,26 @@ class istTeilController {
}
public function getBestellung(){
$result = $this->db->getBestellung();
public function getIstTeil()
{
$result = $this->db->selectIstTeil();
return json_encode($result);
}
public function writeIstTeil($data)
{
$result = $this->db->insertIstTeil($data);
return json_encode($result);
}
public function deleteIstTeil($id)
{
$result = $this->db->deleteIstTeil($id);
return json_encode($result);
}
}
?>

View File

@ -1,4 +1,5 @@
<?php
// Getestet von Samuel Wolff
namespace ppb\Model;
@ -26,14 +27,14 @@ class InhaltsstoffModel extends Database
{
$pdo = $this->linkDB();
$params = array();
$sql = "INSERT INTO Inhaltsstoff ";
$sql = "INSERT INTO Inhaltsstoff (";
foreach ($data as $index => $value) {
$sql .= "" . $index . ",";
}
$sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES (";
foreach ($data as $index => $value) {
$sql .= "':" . $index . "',";
$sql .= ":" . $index . ",";
$params[":" . $index] = $value;
}
@ -44,6 +45,7 @@ class InhaltsstoffModel extends Database
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
echo $sql;
return false;
}
}
@ -52,13 +54,14 @@ class InhaltsstoffModel extends Database
{
$pdo = $this->linkDB();
$params = array();
$sql = "DELETE FROM Inhalsstoff WHERE id=:id";
$sql = "DELETE FROM Inhaltsstoff WHERE id=:id";
$params[":id"] = $id;
try {
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
echo $sql;
return false;
}
}

View File

@ -1,7 +1,7 @@
<?php
// Programmiert durch Samuel Wolff
// Getestet durch: Nicht getestet
// Getestet durch: Samuel Wolff
namespace ppb\Model;

View File

@ -1,45 +1,74 @@
<?php
namespace kinderverwaltung\Model;
namespace ppb\Model;
use kinderverwaltung\Library\Msg;
use ppb\Model\Database;
//Programmiert von Stefan Groß
//getestet von Samuel Wolff
class IstTeilModel extends Database{
class istTeilModel extends Database
{
public function getBestellung(){
public function selectIstTeil()
{
$pdo = $this->linkDB();
$sql = "SELECT bid FROM istTeil";
$sql = "SELECT * FROM istTeil";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
//nur zum Testen:
//new Msg(true,null,$e);
//echo $e;
return false;
}
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
$results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($results as $key => $value) {
$results[$key]["bid"] += 0;
$results[$key]["gid"] += 0;
$results[$key]["id"] += 0;
}
return $results;
}
public function InsertIstTeil($data){
public function insertIstTeil($data)
{
$pdo = $this->linkDB();
$sql = "INSERT INTO istTeil(bid, gid)";
$params = array();
$sql = "INSERT INTO istTeil (bid, gid) VALUES (:bid, :gid)";
foreach ($data as $key => $value) {
$params[":" . $key] = $value;
}
try {
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
} catch (\PDOException $e) {
//nur zum Testen:
//new Msg(true,null,$e);
//echo $e;
return false;
}
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
return true;
}
public function deleteIstTeil($id)
{
$pdo = $this->linkDB();
$params = array();
$sql = "DELETE FROM istTeil WHERE id = :id";
$params[":id"] = $id;
try {
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
} catch (\PDOException $e) {
return false;
}
return true;
}
}
?>