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); return json_encode($result);
} }
public function insertInhaltsstoff($data) public function writeInhaltsstoff($data)
{ {
$result = $this->db->insertInhaltsstoff($data); $result = $this->db->insertInhaltsstoff($data);
return json_encode($result); return json_encode($result);

View File

@ -1,8 +1,11 @@
<?php <?php
// Erstellt durch Stefan Groß // Erstellt durch Stefan Groß - Nicht getestet
namespace kinderverwaltung\Controller; namespace ppb\Controller;
class istTeilController { use ppb\Model\IstTeilModel;
class istTeilController
{
private $db; private $db;
public function __construct() public function __construct()
@ -12,10 +15,26 @@ class istTeilController {
} }
public function getBestellung(){ public function getIstTeil()
$result = $this->db->getBestellung(); {
$result = $this->db->selectIstTeil();
return json_encode($result); 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 <?php
// Getestet von Samuel Wolff
namespace ppb\Model; namespace ppb\Model;
@ -26,14 +27,14 @@ class InhaltsstoffModel extends Database
{ {
$pdo = $this->linkDB(); $pdo = $this->linkDB();
$params = array(); $params = array();
$sql = "INSERT INTO Inhaltsstoff "; $sql = "INSERT INTO Inhaltsstoff (";
foreach ($data as $index => $value) { foreach ($data as $index => $value) {
$sql .= "" . $index . ","; $sql .= "" . $index . ",";
} }
$sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES ("; $sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES (";
foreach ($data as $index => $value) { foreach ($data as $index => $value) {
$sql .= "':" . $index . "',"; $sql .= ":" . $index . ",";
$params[":" . $index] = $value; $params[":" . $index] = $value;
} }
@ -44,6 +45,7 @@ class InhaltsstoffModel extends Database
$stmt->execute($params); $stmt->execute($params);
return true; return true;
} catch (\PDOException $e) { } catch (\PDOException $e) {
echo $sql;
return false; return false;
} }
} }
@ -52,13 +54,14 @@ class InhaltsstoffModel extends Database
{ {
$pdo = $this->linkDB(); $pdo = $this->linkDB();
$params = array(); $params = array();
$sql = "DELETE FROM Inhalsstoff WHERE id=:id"; $sql = "DELETE FROM Inhaltsstoff WHERE id=:id";
$params[":id"] = $id; $params[":id"] = $id;
try { try {
$stmt = $pdo->prepare($sql); $stmt = $pdo->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
return true; return true;
} catch (\PDOException $e) { } catch (\PDOException $e) {
echo $sql;
return false; return false;
} }
} }

View File

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

View File

@ -1,45 +1,74 @@
<?php <?php
namespace kinderverwaltung\Model; namespace ppb\Model;
use kinderverwaltung\Library\Msg; //Programmiert von Stefan Groß
use ppb\Model\Database; //getestet von Samuel Wolff
class IstTeilModel extends Database{ class istTeilModel extends Database
{
public function getBestellung(){ public function selectIstTeil()
{
$pdo = $this->linkDB(); $pdo = $this->linkDB();
$sql = "SELECT bid FROM istTeil"; $sql = "SELECT * FROM istTeil";
try { try {
$stmt = $pdo->prepare($sql); $stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) { } catch (\PDOException $e) {
//nur zum Testen:
//new Msg(true,null,$e);
//echo $e;
return false; 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(); $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 { try {
$stmt = $pdo->prepare($sql); $stmt = $pdo->prepare($sql);
$stmt->execute($params);
} catch (\PDOException $e) { } catch (\PDOException $e) {
//nur zum Testen:
//new Msg(true,null,$e);
//echo $e;
return false; 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;
} }
} }
?> ?>