From 7e8ed66cb7572ba6122cd9fe42b32ef2c27005d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 1 Apr 2021 12:16:03 +0200 Subject: [PATCH] =?UTF-8?q?Die=20Tests=20f=C3=BCr=20das=20Lesen=20der=20Da?= =?UTF-8?q?ten=20sind=20erfolgreich.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/WorkingHoursRepository.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 api/src/Repositories/WorkingHoursRepository.php diff --git a/api/src/Repositories/WorkingHoursRepository.php b/api/src/Repositories/WorkingHoursRepository.php new file mode 100644 index 0000000..72b07de --- /dev/null +++ b/api/src/Repositories/WorkingHoursRepository.php @@ -0,0 +1,107 @@ + + * @implements RepositoryWriterInterface + */ +class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWriterInterface +{ + + protected PDO $database; + + /** + * WorkingHoursRepository constructor. + * + * @param PDO $database + */ + public function __construct(PDO $database) + { + $this->database = $database; + $this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + /** + * + * Gibt alle vorhandenen Einträge zurück + * + * @return WorkingHours[] + * @throws Exception + * @throws PDOException + */ + public function findAll(): array + { + $models = []; + $stmt = $this->database->prepare('SELECT "Datum" as workingDay, "Arbeitszeit" as workingTime FROM public."Arbeitszeiten"'); + $stmt->execute(); + while ($row = $stmt->fetch()) { + $model = new WorkingHours(); + $model + ->setWorkingDay(new DateTime($row['workingday'])) + ->setWorkingTime(new DateInterval('P0000-00-00T'.$row['workingtime'])); + $models[] = $model; + } + return $models; + } + + /** + * Gibt den Eintrag zurück, der durch die ID + * + * @param mixed $primary_key + * + * @return WorkingHours + * @throws RepositoryRecordNotFoundException + * @throws Exception + * @throws PDOException + */ + public function findByKey(mixed $primary_key): WorkingHours + { + $stmt = $this->database->prepare('SELECT "Datum" as workingDay, "Arbeitszeit" as workingTime FROM public."Arbeitszeiten" WHERE "Datum" = ?'); + $stmt->bindParam(1, $primary_key); + $stmt->execute(); + $row = $stmt->fetch(); + if ($row === false) { + throw new RepositoryRecordNotFoundException(); + } + $model = new WorkingHours(); + $model + ->setWorkingDay(new DateTime($row['workingday'])) + ->setWorkingTime(new DateInterval('P0000-00-00T'.$row['workingtime'])); + return $model; + } + + /** + * @param WorkingHours|ModelInterface $model + */ + public function insert(mixed $model): void + { + // TODO: Implement insert() method. + } + + /** + * @param WorkingHours|ModelInterface $model + */ + public function update(mixed $model): void + { + // TODO: Implement update() method. + } + + /** + * @param WorkingHours|ModelInterface $model + */ + public function delete(mixed $model): void + { + // TODO: Implement delete() method. + } +} \ No newline at end of file