Initial commit: new project structure and scripts
This commit is contained in:
49
Model/ProjectModel.php
Normal file
49
Model/ProjectModel.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace ppb\Model;
|
||||
use ppb\Library\Msg;
|
||||
|
||||
class ProjectModel extends Database
|
||||
{
|
||||
public function readProject()
|
||||
{
|
||||
$pdo = $this->linkDB();
|
||||
$sql = "SELECT * FROM users";
|
||||
|
||||
try {
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
} catch (\PDOException $e) {
|
||||
new Msg(true, null, $e);
|
||||
}
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
|
||||
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$sth->closeCursor();
|
||||
$pdo = null;
|
||||
// fetch all
|
||||
return $result;
|
||||
|
||||
}
|
||||
public function insertNewMediaType($data)
|
||||
{
|
||||
$pdo = $this->linkDB();
|
||||
|
||||
try {
|
||||
// it should add an new type and it is Files
|
||||
$sql = "INSERT INTO media_types (id, type)
|
||||
VALUES (:id, :type)";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth-> execute([
|
||||
':id' => $this->createUUID(),
|
||||
':type' => $data['Files']
|
||||
]);
|
||||
|
||||
$pdo = null;
|
||||
|
||||
new Msg(false, "Medientyp erfolgreich eingefügt.");
|
||||
} catch (\PDOException $e) {
|
||||
new Msg(true, 'Fehler beim Einfügen des Medientyps', $e);
|
||||
}
|
||||
}
|
||||
}
|
37
Model/TaskModel.php
Normal file
37
Model/TaskModel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace ppb\Model;
|
||||
|
||||
use ppb\Library\Msg;
|
||||
|
||||
class TaskModel extends Database {
|
||||
|
||||
public function insertTask($data) {
|
||||
$pdo = $this->linkDB();
|
||||
|
||||
try {
|
||||
|
||||
$sql = "INSERT INTO task (id, userId, projectId, title, expense, dueDate, priorityId, done )
|
||||
VALUES (:id,:userId,:projectId, :title, :expense, :dueDate, :priorityId, :done)";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth-> execute([
|
||||
':id' => $this->createUUID(),
|
||||
':userId' => '4f141df7-3c0a-11e8-b046-2c4d544f8fe0',
|
||||
':projectId' => $data['projectId'],
|
||||
':title' => $data['title'],
|
||||
':expense' => str_replace("," , "." ,$data['expense']),
|
||||
':dueDate' => date("Y-m-d", strtotime($data['dueDate'])),
|
||||
':priorityId' => $data['priorityId'],
|
||||
':done' => 0
|
||||
]);
|
||||
|
||||
|
||||
$pdo = null;
|
||||
|
||||
new Msg(false, "Task erfolgreich eingefügt.");
|
||||
} catch (\PDOException $e) {
|
||||
new Msg(true, 'Fehler beim Einfügen des Tasks', $e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
46
Model/database.php
Normal file
46
Model/database.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace ppb\Model;
|
||||
|
||||
use ppb\Library\Msg;
|
||||
|
||||
abstract class Database {
|
||||
|
||||
/**
|
||||
* Zugangsdaten für die Datenbank
|
||||
*/
|
||||
private $dbName = "vpr_pbat3h23a"; //Datenbankname
|
||||
private $linkName = "mysql.pb.bib.de"; //Datenbank-Server
|
||||
private $user = "vpr_pbat3h23a"; //Benutzername
|
||||
private $pw = "SBHwIWNqmMevnlqt"; //Passwort
|
||||
|
||||
/**
|
||||
* Stellt eine Verbindung zur Datenbank her
|
||||
*
|
||||
* @return \PDO Gibt eine Datenbankverbindung zurueck
|
||||
*/
|
||||
public function linkDB() {
|
||||
try {
|
||||
$pdo = new \PDO("mysql:dbname=$this->dbName;host=$this->linkName"
|
||||
, $this->user
|
||||
, $this->pw
|
||||
, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
|
||||
return $pdo;
|
||||
} catch (\PDOException $e) {
|
||||
new Msg(true, null, $e);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zum serverseitigen generieren einer UUID
|
||||
*
|
||||
* @return string Liefert eine UUID
|
||||
*/
|
||||
public function createUUID()
|
||||
{
|
||||
$data = openssl_random_pseudo_bytes(16);
|
||||
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
|
||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
||||
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user