Replace old structure with new structure
This commit is contained in:
parent
ea58af4fcc
commit
69dd02eb91
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/taskit.iml" filepath="$PROJECT_DIR$/.idea/taskit.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/taskit.iml
generated
Normal file
8
.idea/taskit.iml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
51
.idea/workspace.xml
generated
Normal file
51
.idea/workspace.xml
generated
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="360c9ff4-7de6-49cd-b9ec-a9902cf1f16f" name="Default Changelist" comment="" />
|
||||||
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="ComposerSettings">
|
||||||
|
<execution>
|
||||||
|
<executable />
|
||||||
|
</execution>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectId" id="23bHx34BX3bHQmyhRciEy7lgdW2" />
|
||||||
|
<component name="PropertiesComponent">
|
||||||
|
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||||
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="RunDashboard">
|
||||||
|
<option name="ruleStates">
|
||||||
|
<list>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="StatusDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="SvnConfiguration">
|
||||||
|
<configuration />
|
||||||
|
</component>
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="360c9ff4-7de6-49cd-b9ec-a9902cf1f16f" name="Default Changelist" comment="" />
|
||||||
|
<created>1641996109010</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1641996109010</updated>
|
||||||
|
<workItem from="1641996110260" duration="763000" />
|
||||||
|
<workItem from="1642156491065" duration="3282000" />
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="1" />
|
||||||
|
</component>
|
||||||
|
</project>
|
3
.vs/ProjectSettings.json
Normal file
3
.vs/ProjectSettings.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"CurrentProjectSetting": null
|
||||||
|
}
|
BIN
.vs/VPR_Backend/CopilotIndices/17.12.53.23981/CodeChunks.db
Normal file
BIN
.vs/VPR_Backend/CopilotIndices/17.12.53.23981/CodeChunks.db
Normal file
Binary file not shown.
BIN
.vs/VPR_Backend/CopilotIndices/17.12.53.23981/SemanticSymbols.db
Normal file
BIN
.vs/VPR_Backend/CopilotIndices/17.12.53.23981/SemanticSymbols.db
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.vs/VPR_Backend/v17/.wsuo
Normal file
BIN
.vs/VPR_Backend/v17/.wsuo
Normal file
Binary file not shown.
39
.vs/VPR_Backend/v17/DocumentLayout.json
Normal file
39
.vs/VPR_Backend/v17/DocumentLayout.json
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"Version": 1,
|
||||||
|
"WorkspaceRootPath": "C:\\Bib Unterlagen\\SEN\\VPR\\VPR_Backend\\",
|
||||||
|
"Documents": [],
|
||||||
|
"DocumentGroupContainers": [
|
||||||
|
{
|
||||||
|
"Orientation": 0,
|
||||||
|
"VerticalTabListWidth": 256,
|
||||||
|
"DocumentGroups": [
|
||||||
|
{
|
||||||
|
"DockedWidth": 200,
|
||||||
|
"SelectedChildIndex": -1,
|
||||||
|
"Children": [
|
||||||
|
{
|
||||||
|
"$type": "Bookmark",
|
||||||
|
"Name": "ST:0:0:{b1e99781-ab81-11d0-b683-00aa00a3ee26}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Bookmark",
|
||||||
|
"Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Bookmark",
|
||||||
|
"Name": "ST:0:0:{3ae79031-e1bc-11d0-8f78-00a0c9110057}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Bookmark",
|
||||||
|
"Name": "ST:0:0:{1c64b9c2-e352-428e-a56d-0ace190b99a6}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Bookmark",
|
||||||
|
"Name": "ST:0:0:{40ea2e6b-2121-4bb8-a43e-c83c04b51041}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
7
.vs/VSWorkspaceState.json
Normal file
7
.vs/VSWorkspaceState.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"ExpandedNodes": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"SelectedNode": "\\C:\\Bib Unterlagen\\SEN\\VPR\\VPR_Backend",
|
||||||
|
"PreviewInSolutionExplorer": false
|
||||||
|
}
|
BIN
.vs/slnx.sqlite
Normal file
BIN
.vs/slnx.sqlite
Normal file
Binary file not shown.
20
Tests/connectionTest.php
Normal file
20
Tests/connectionTest.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
<?php
|
||||||
|
use App\Config\Database;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../App/Config/Database.php'; // Adjusted to use a relative path
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create an instance of the Database class
|
||||||
|
$db = new class extends Database {};
|
||||||
|
|
||||||
|
// Establish a connection using the linkDB method
|
||||||
|
$pdo = $db->linkDB();
|
||||||
|
|
||||||
|
// If the connection is successful
|
||||||
|
echo "Connected successfully using PDO";
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Handle connection error
|
||||||
|
error_log($e->getMessage()); // Log the error message
|
||||||
|
echo "An error occurred while connecting to the database. Please try again later.";
|
||||||
|
}
|
40
Tests/controllersTest.php
Normal file
40
Tests/controllersTest.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ControllerTester
|
||||||
|
{
|
||||||
|
public function testController($controllerPath, $methodName, $params = [])
|
||||||
|
{
|
||||||
|
if (!file_exists($controllerPath)) {
|
||||||
|
return "Error: Controller file not found at path: $controllerPath";
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once $controllerPath;
|
||||||
|
|
||||||
|
// Extract the class name from the file path
|
||||||
|
$className = basename($controllerPath, '.php');
|
||||||
|
|
||||||
|
if (!class_exists($className)) {
|
||||||
|
return "Error: Class $className not found in the controller file.";
|
||||||
|
}
|
||||||
|
|
||||||
|
$controller = new $className();
|
||||||
|
|
||||||
|
if (!method_exists($controller, $methodName)) {
|
||||||
|
return "Error: Method $methodName not found in class $className.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the method with parameters
|
||||||
|
return call_user_func_array([$controller, $methodName], $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example usage
|
||||||
|
$tester = new ControllerTester();
|
||||||
|
$controllerPath = '../App/Controller/ProjectController.php'; // Path to the controller file
|
||||||
|
$methodName = 'getAllRecords'; // Replace with the method you want to test
|
||||||
|
$params = []; // Replace with the parameters for the method
|
||||||
|
|
||||||
|
$result = $tester->testController($controllerPath, $methodName, $params);
|
||||||
|
echo '<pre>';
|
||||||
|
print_r($result);
|
||||||
|
echo '</pre>';
|
128
Tests/test.php
Normal file
128
Tests/test.php
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
define('API', 'restAPI.php'); // NICHT VERAENDERN!!!
|
||||||
|
$url = "http://localhost/VPR_Backend/" . API;
|
||||||
|
// $filepath = "c:\\xampp\\htdocs\\2022_BEE_PBAT3H19AB\\taskit\\";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for get all projetcs
|
||||||
|
*/
|
||||||
|
$defaults = array(
|
||||||
|
CURLOPT_URL => $url . '/project',
|
||||||
|
// CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// CURLOPT_COOKIEJAR => $filepath . 'cookie.txt', // set same file as cookie jar
|
||||||
|
CURLOPT_CUSTOMREQUEST => "GET"
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for get all tasks
|
||||||
|
*/
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/task',
|
||||||
|
// CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// CURLOPT_COOKIEJAR => $filepath . 'cookie.txt', // set same file as cookie jar
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "GET"
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for get tasks filtered
|
||||||
|
*/
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/task/getFilteredTasks?dueDate=1%20DAY',
|
||||||
|
// CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// CURLOPT_COOKIEJAR => $filepath . 'cookie.txt', // set same file as cookie jar
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "GET"
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for insert new task
|
||||||
|
*/
|
||||||
|
// $params = json_encode(array(
|
||||||
|
// "projectId" => '72f7cc6e-3717-11eb-add7-2c4d544f8fe0'
|
||||||
|
// , 'title' => 'Neuer Task 5'
|
||||||
|
// , 'expense' => '0,25'
|
||||||
|
// , 'dueDate' => '15.03.2022'
|
||||||
|
// , 'priorityId' => 1));
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/task',
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "POST",
|
||||||
|
// // CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// // CURLOPT_COOKIEJAR => $filepath . 'cookie.txt', // set same file as cookie jar
|
||||||
|
// CURLOPT_POSTFIELDS => $params
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for Update Task OHNE Login
|
||||||
|
*/
|
||||||
|
// $params = json_encode(array("done" => '0'));
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/task/1b2d4564-3718-11eb-add7-2c4d544f8fe0',
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "PUT",
|
||||||
|
// CURLOPT_POSTFIELDS => $params
|
||||||
|
// );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for Delete Task OHNE Login
|
||||||
|
*/
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/task/01b169aa-3718-11eb-add7-2c4d544f8fe0',
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "DELETE"
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for Delete Task MIT Login
|
||||||
|
*/
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/task/cbdb169f-e0da-11e7-a056-2c4d544f8fe0',
|
||||||
|
// CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// CURLOPT_COOKIEJAR => $filepath . 'cookie.txt', // set same file as cookie jar
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "DELETE"
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for loginUser
|
||||||
|
*/
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/user/loginUser?username=fiona&pw=12345',
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "GET",
|
||||||
|
// CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
|
||||||
|
// CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// CURLOPT_COOKIEJAR => $filepath . 'cookie.txt' // set same file as cookie jar
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for isLogin
|
||||||
|
*/
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/user/isLogin',
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "GET",
|
||||||
|
// CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
|
||||||
|
// CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// CURLOPT_COOKIEJAR => $filepath . 'cookie.txt' // set same file as cookie jar
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for logout
|
||||||
|
*/
|
||||||
|
// $defaults = array(
|
||||||
|
// CURLOPT_URL => $url . '/user/logout',
|
||||||
|
// CURLOPT_CUSTOMREQUEST => "GET",
|
||||||
|
// CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
|
||||||
|
// CURLOPT_COOKIEFILE => $filepath . 'cookie.txt', // set cookie file to given file
|
||||||
|
// CURLOPT_COOKIEJAR => $filepath . 'cookie.txt' // set same file as cookie jar
|
||||||
|
// );
|
||||||
|
|
||||||
|
// session_write_close();
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt_array($ch, ($defaults));
|
||||||
|
curl_exec($ch);
|
||||||
|
if(curl_error($ch)) {
|
||||||
|
print(curl_error($ch));
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// session_start();
|
||||||
|
|
||||||
|
?>
|
@ -1,20 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
class Database {
|
|
||||||
private $host = "mysql.pb.bib.de";
|
|
||||||
private $db_name = "media_locale";
|
|
||||||
private $username = "vpr_pbat3h23a";
|
|
||||||
private $password = "SBHwIWNqmMevnlqt";
|
|
||||||
public $conn;
|
|
||||||
|
|
||||||
public function getConnection() {
|
namespace App\Config;
|
||||||
$this->conn = null;
|
|
||||||
|
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 {
|
try {
|
||||||
$this->conn = new PDO("mysql:host={$this->host};dbname={$this->db_name}",
|
$pdo = new \PDO("mysql:dbname=$this->dbName;host=$this->linkName"
|
||||||
$this->username, $this->password);
|
, $this->user
|
||||||
$this->conn->exec("set names utf8");
|
, $this->pw
|
||||||
} catch (PDOException $exception) {
|
, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
|
||||||
echo "Connection error: " . $exception->getMessage();
|
return $pdo;
|
||||||
}
|
} catch (\PDOException $e) {
|
||||||
return $this->conn;
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
65
app/Controller/ExampleController.php
Normal file
65
app/Controller/ExampleController.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Controller;
|
||||||
|
use App\Model\ExampleModel;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class ExampleController
|
||||||
|
{
|
||||||
|
private $model;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Initialize the ExampleModel
|
||||||
|
$this->model = new ExampleModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a new record to the database
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function writeRecord(array $data): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->model->insertRecord($data);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log the error or handle it as needed
|
||||||
|
error_log("Error writing record: " . $e->getMessage());
|
||||||
|
throw new Exception("Failed to write record.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all records from the database
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAllRecords(): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->model->fetchAllRecords();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log the error or handle it as needed
|
||||||
|
error_log("Error fetching records: " . $e->getMessage());
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a record by ID
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function deleteRecord(int $id): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->model->removeRecord($id);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log the error or handle it as needed
|
||||||
|
error_log("Error deleting record: " . $e->getMessage());
|
||||||
|
throw new Exception("Failed to delete record.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
app/Controller/ProjectController.php
Normal file
47
app/Controller/ProjectController.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Model\ProjectModel;
|
||||||
|
|
||||||
|
class ProjectController {
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to get all projects
|
||||||
|
// This method is called by the router
|
||||||
|
// and is used to get all projects from the database
|
||||||
|
// and return them as JSON
|
||||||
|
|
||||||
|
public function getProject(): void
|
||||||
|
{
|
||||||
|
echo "This is the Table Project";
|
||||||
|
echo "<br>";
|
||||||
|
$model = new ProjectModel();
|
||||||
|
$data = $model->readProject();
|
||||||
|
|
||||||
|
echo "<br>";
|
||||||
|
|
||||||
|
|
||||||
|
// Display the data in a table format
|
||||||
|
echo '<table border="1" cellpadding="5" cellspacing="0">';
|
||||||
|
// Table header
|
||||||
|
echo '<tr>';
|
||||||
|
foreach (array_keys($data[0]) as $header) {
|
||||||
|
echo '<th>' . htmlspecialchars($header) . '</th>';
|
||||||
|
}
|
||||||
|
echo '</tr>';
|
||||||
|
// Table rows
|
||||||
|
foreach ($data as $row) {
|
||||||
|
echo '<tr>';
|
||||||
|
foreach ($row as $cell) {
|
||||||
|
echo '<td>' . htmlspecialchars($cell) . '</td>';
|
||||||
|
}
|
||||||
|
echo '</tr>';
|
||||||
|
}
|
||||||
|
echo '</table>';
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once __DIR__ . '/../Models/Project.php';
|
|
||||||
|
|
||||||
class ProjectController {
|
|
||||||
private $project;
|
|
||||||
|
|
||||||
public function __construct($db) {
|
|
||||||
$this->project = new Project($db);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllProjects() {
|
|
||||||
return $this->project->fetchAll();
|
|
||||||
}
|
|
||||||
}
|
|
55
app/Model/ExampleModel.php
Normal file
55
app/Model/ExampleModel.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
class ExampleModel
|
||||||
|
{
|
||||||
|
private $records = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Initialize with some example data
|
||||||
|
$this->records = [
|
||||||
|
['id' => 1, 'name' => 'Example 1', 'value' => 100],
|
||||||
|
['id' => 2, 'name' => 'Example 2', 'value' => 200],
|
||||||
|
['id' => 3, 'name' => 'Example 3', 'value' => 300],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a new record into the example data
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function insertRecord(array $data): void
|
||||||
|
{
|
||||||
|
$this->records[] = [
|
||||||
|
'id' => count($this->records) + 1,
|
||||||
|
'name' => $data['name'] ?? 'Unnamed',
|
||||||
|
'value' => $data['value'] ?? 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all records from the example data
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function fetchAllRecords(): array
|
||||||
|
{
|
||||||
|
return $this->records;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a record by ID from the example data
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function removeRecord(int $id): void
|
||||||
|
{
|
||||||
|
$this->records = array_filter($this->records, function ($record) use ($id) {
|
||||||
|
return $record['id'] !== $id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
30
app/Model/ProjectModel.php
Normal file
30
app/Model/ProjectModel.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
use App\Config\Database;
|
||||||
|
use ppb\Library\Msg;
|
||||||
|
|
||||||
|
class ProjectModel extends Database
|
||||||
|
{
|
||||||
|
public function readProject()
|
||||||
|
{
|
||||||
|
$pdo = $this->linkDB();
|
||||||
|
$sql = "SELECT id, name FROM project";
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
class Project {
|
|
||||||
private $conn;
|
|
||||||
private $table = "projects";
|
|
||||||
|
|
||||||
public function __construct($db) {
|
|
||||||
$this->conn = $db;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchAll() {
|
|
||||||
$query = "SELECT * FROM " . $this->table;
|
|
||||||
$stmt = $this->conn->prepare($query);
|
|
||||||
$stmt->execute();
|
|
||||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once __DIR__ . '/../app/Config/database.php';
|
|
||||||
require_once __DIR__ . '/../routes/api.php';
|
|
||||||
|
|
||||||
echo "Media Locale Backend is running.";
|
|
@ -17,10 +17,10 @@
|
|||||||
$alias = false;
|
$alias = false;
|
||||||
|
|
||||||
if (isset($endpoint[1])) {
|
if (isset($endpoint[1])) {
|
||||||
if (preg_match('/\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/', $endpoint2)) {
|
if (preg_match('/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/', $endpoint[1])) {
|
||||||
$id = $endpoint2;
|
$id = $endpoint[1];
|
||||||
} else {
|
} else {
|
||||||
$alias = $endpoint2;
|
$alias = $endpoint[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once __DIR__ . '/../app/Config/database.php';
|
|
||||||
require_once __DIR__ . '/../app\Controllers\ProjectController.php';
|
|
||||||
|
|
||||||
$db = (new Database())->getConnection();
|
|
||||||
$controller = new ProjectController($db);
|
|
||||||
|
|
||||||
header("Content-Type: application/json");
|
|
||||||
echo json_encode($controller->getAllProjects());
|
|
Loading…
x
Reference in New Issue
Block a user