Replace old structure with new structure

This commit is contained in:
MosLaptop\Not.Reda
2025-08-28 09:28:59 +02:00
parent ea58af4fcc
commit 69dd02eb91
28 changed files with 552 additions and 62 deletions

View 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;
});
}
}

View 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;
}
}