VPR_Schnittstelle/Model/TagesplanModel.php

92 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2023-12-20 09:12:15 +01:00
<?php
//Programmiert von: Max Heer, Getestet von: Samuel Wolff
2023-12-20 09:12:15 +01:00
namespace ppb\Model;
2023-12-20 09:12:15 +01:00
use ppb\Library\Msg;
class TagesplanModel extends Database
{
public function getTagesplan()
{
$pdo = $this->linkDB();
2023-12-20 09:12:15 +01:00
$sql = "SELECT * FROM Tagesplan";
try {
2023-12-20 09:12:15 +01:00
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
2023-12-20 09:12:15 +01:00
return false;
}
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
public function insertTagesplan($data)
{
$pdo = $this->linkDB();
2023-12-20 09:12:15 +01:00
$params = array();
$sql = "INSERT INTO Tagesplan (";
foreach ($data as $index => $value) {
$sql .= "" . $index . ",";
2023-12-20 09:12:15 +01:00
}
$sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES (";
2023-12-20 09:12:15 +01:00
foreach ($data as $index => $value) {
$sql .= ":" . $index . ",";
$params[":" . $index] = $value;
2023-12-20 09:12:15 +01:00
}
$sql = substr($sql, 0, strlen($sql) - 1) . ");";
2023-12-20 09:12:15 +01:00
try {
2023-12-20 09:12:15 +01:00
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
echo $sql;
2023-12-20 09:12:15 +01:00
return false;
}
}
public function deleteTagesplan($id)
{
$pdo = $this->linkDB();
2023-12-20 09:12:15 +01:00
$params = array();
$sql = "DELETE FROM Tagesplan WHERE id=:id";
$params[":id"] = $id;
try {
2023-12-20 09:12:15 +01:00
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
2023-12-20 09:12:15 +01:00
return false;
}
2024-01-18 10:02:29 +01:00
}
public function getGerichteOnTag()
{
2024-01-18 10:12:14 +01:00
$pdo = $this->linkDB();
$datum = $_GET["datum"];
2024-01-18 10:02:29 +01:00
2024-01-18 10:21:52 +01:00
$sql = "SELECT Gericht.id, Gericht.name, Gericht.preis, Gericht.beschreibung FROM Gericht LEFT JOIN GibtsAm ON Gericht.id = GibtsAm.gid LEFT JOIN Tagesplan ON GibtsAm.tid = Tagesplan.id WHERE Tagesplan.datum = '$datum'";
2024-01-18 10:12:14 +01:00
try {
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
echo $sql . " This do be faulty";
return false;
}
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $result;
2024-01-18 10:02:29 +01:00
2023-12-20 09:12:15 +01:00
}
}
2023-12-20 09:12:15 +01:00
?>