VPR_Schnittstelle/Model/BenutzerModel.php

100 lines
2.0 KiB
PHP
Raw Normal View History

2023-12-06 08:33:25 +01:00
<?php
// Programmiert durch Samuel Wolff
2024-01-08 11:14:17 +01:00
// Getestet durch: Samuel Wolff
2023-12-06 08:33:25 +01:00
2023-12-18 08:19:27 +01:00
namespace ppb\Model;
2023-12-06 08:33:25 +01:00
use ppb\Library\Msg;
2023-12-06 08:33:25 +01:00
2023-12-18 08:16:21 +01:00
class BenutzerModel extends Database
{
2023-12-06 08:33:25 +01:00
2023-12-11 15:34:55 +01:00
/**
*
* Updated einen Benutzer
*
* @param $elternId Die Id des Elternaccounts
* @param $data Die gegebenen Daten
*
*/
2023-12-18 08:16:21 +01:00
public function updateBenutzer($elternId, $data)
{
2023-12-06 08:33:25 +01:00
$pdo = $this->linkDB();
$params = array();
2024-01-08 11:14:17 +01:00
$sql = "UPDATE Benutzerkonto SET";
2023-12-06 08:33:25 +01:00
2023-12-18 08:16:21 +01:00
foreach ($data as $index => $value) {
2024-01-08 11:14:17 +01:00
$sql .= " " . $index . " = :" . $index . ",";
2023-12-18 08:16:21 +01:00
$params[":" . $index] = $value;
2023-12-06 08:33:25 +01:00
}
2024-01-08 11:14:17 +01:00
$sql = substr($sql, 0, strlen($sql) - 1) . " WHERE id = :benutzerId;";
2023-12-06 08:33:25 +01:00
2023-12-18 08:16:21 +01:00
$params[":benutzerId"] = $elternId;
2023-12-06 08:33:25 +01:00
2023-12-18 08:16:21 +01:00
try {
2023-12-06 08:33:25 +01:00
$stmt = $pdo->prepare($sql);
2023-12-18 08:19:27 +01:00
$stmt->execute($params);
2023-12-18 08:16:21 +01:00
} catch (\PDOException $e) {
2024-01-08 11:14:17 +01:00
echo $sql;
echo json_encode($params);
2023-12-06 08:33:25 +01:00
return false;
}
2023-12-18 08:16:21 +01:00
2023-12-06 08:33:25 +01:00
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
2023-12-18 08:16:21 +01:00
2023-12-06 08:33:25 +01:00
return $result;
}
2023-12-11 15:34:55 +01:00
/**
*
* Fügt einen neuen Benutzer in der Datenbank hinzu
*
* @param $data Die gegebenen Daten
*
*/
2023-12-18 08:16:21 +01:00
public function insertBenutzer($data)
{
2023-12-06 08:33:25 +01:00
$pdo = $this->linkDB();
$params = array();
2023-12-18 08:16:21 +01:00
2024-01-08 11:14:17 +01:00
$sql = "INSERT INTO Benutzerkonto (";
2023-12-18 08:16:21 +01:00
foreach ($data as $index => $value) {
$sql .= $index . ", ";
2024-01-08 11:14:17 +01:00
$params[":" . $index] = $index;
2023-12-06 08:33:25 +01:00
}
2023-12-18 08:16:21 +01:00
$sql = substr($sql, 0, strlen($sql) - 2) . ") VALUES (";
2024-01-08 11:14:17 +01:00
foreach ($data as $index => $value) {
$sql .= ":" . $index . " ,";
$params[":" . $index] = $value;
2023-12-06 08:33:25 +01:00
}
2023-12-18 08:16:21 +01:00
$sql = substr($sql, 0, strlen($sql) - 2) . ");";
2024-01-08 11:14:17 +01:00
echo $sql;
2023-12-18 08:16:21 +01:00
try {
2023-12-06 08:33:25 +01:00
$stmt = $pdo->prepare($sql);
2023-12-18 08:19:27 +01:00
$stmt->execute($params);
2023-12-18 08:16:21 +01:00
} catch (\PDOException $e) {
2023-12-06 08:33:25 +01:00
return false;
}
2023-12-18 08:16:21 +01:00
2023-12-06 08:33:25 +01:00
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
2023-12-18 08:16:21 +01:00
2023-12-06 08:33:25 +01:00
return $result;
}
2023-12-18 08:16:21 +01:00
2023-12-06 08:33:25 +01:00
}
2023-12-18 08:16:21 +01:00
?>