Added Dummy.php for mocking DB
This commit is contained in:
parent
20cb808935
commit
37b0807cde
1 changed files with 105 additions and 0 deletions
105
class/Dummy.php
Normal file
105
class/Dummy.php
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Eichehome
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Klasse um die Datenbank beim Testen zu simulieren
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Dummy extends DBClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Diese Methode prüft, ob das Loginpasswort und -name mit den Werten in der Datenbank übereinstimmen
|
||||||
|
* @param string $name Loginname
|
||||||
|
* @param string $passwort Loginpasswort
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function checkLogin(string $name, string $passwort)
|
||||||
|
{
|
||||||
|
if ($name == "christian.brueggen" && $passwort == "123") {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diese Methode prüft, ob ein Nutzer sich schon eingetragen hat
|
||||||
|
* @param string $name
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function hasAlredySelected(string $name)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT * FROM Test_v2 WHERE Name=:name AND Kurs IS NOT NULL AND Kurs2 IS NOT NULL AND Kurs3 IS NOT NULL ';
|
||||||
|
|
||||||
|
$params = array(
|
||||||
|
'name' => $name
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->select($sql, $params);
|
||||||
|
|
||||||
|
if (count($result) == 1) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diese Methode gibt alle verfügbaren Kurse aus
|
||||||
|
* @return Countable|array
|
||||||
|
*/
|
||||||
|
public function selectKurse()
|
||||||
|
{
|
||||||
|
$sql = 'SELECT name, stunde FROM Kurse';
|
||||||
|
|
||||||
|
return $this->select($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diese Methode trägt die Auswahl eines Benutzers in die Datenbank ein
|
||||||
|
* @param string Loginname
|
||||||
|
* @param array[strings] Die ausgewählten Kurse
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function insertSelection(string $name, array $kurse)
|
||||||
|
{
|
||||||
|
if (count($kurse) == 3) {
|
||||||
|
$sql = 'UPDATE Test_v2 SET Kurs=:kurs1, Kurs2=:kurs2, Kurs3=:kurs3 WHERE name =:name';
|
||||||
|
|
||||||
|
$params = array(
|
||||||
|
'name' => $name,
|
||||||
|
'kurs1' => $kurse[0],
|
||||||
|
'kurs2' => $kurse[1],
|
||||||
|
'kurs3' => $kurse[2]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->query($sql, $params);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nicht mehr nötig
|
||||||
|
* @param string $name
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
/*public function updateHasAlredySelected(string $name)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}*/
|
||||||
|
}
|
Loading…
Reference in a new issue