VPR_Schnittstelle/Model/BenutzerModel.php

96 lines
1.9 KiB
PHP
Raw Normal View History

2023-12-06 08:33:25 +01:00
<?php
// Programmiert durch Samuel Wolff
// Getestet durch: Nicht getestet
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();
2023-12-18 08:16:21 +01:00
$sql = "UPDATE Benutzer SET";
2023-12-06 08:33:25 +01:00
2023-12-18 08:16:21 +01:00
foreach ($data as $index => $value) {
$sql .= " " . $index . " = :" . $index;
$params[":" . $index] = $value;
2023-12-06 08:33:25 +01:00
}
$sql .= " WHERE id = :benutzerId;";
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) {
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
2023-12-06 08:33:25 +01:00
$sql = "INSERT INTO Benutzer (";
2023-12-18 08:16:21 +01:00
foreach ($data as $index => $value) {
$sql .= $index . ", ";
$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 (";
foreach ($data as $value) {
$sql .= ":" . $value . " ,";
$params[":" + $value] = $value;
2023-12-06 08:33:25 +01:00
}
2023-12-18 08:16:21 +01:00
$sql = substr($sql, 0, strlen($sql) - 2) . ");";
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
?>