Create User & Media models/controllers, remove Task & Project

# Created:

#  - UserModel + UserController

#  - MediaModel + MediaController

# Removed:

#  - TaskModel + TaskController

#  - ProjectModel + ProjectController
This commit is contained in:
MosLaptop\Not.Reda
2025-09-05 12:04:18 +02:00
parent 69dd02eb91
commit 4efea20fae
18 changed files with 405 additions and 227 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace ppb\Controller;
use ppb\Model\MediaModel;
class MediaController {
public function __construct() {}
// GET all media
public function get($data = null): void
{
$model = new MediaModel();
$result = $model->getAll();
header('Content-Type: application/json');
echo json_encode($result);
}
// ADD new media
public function add($data): void
{
$model = new MediaModel();
$result = $model->insert($data);
header('Content-Type: application/json');
echo json_encode($result);
}
// REMOVE media by id
public function remove($data): void
{
$model = new MediaModel();
$result = $model->remove($data);
header('Content-Type: application/json');
echo json_encode($result);
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace ppb\Controller;
use ppb\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>';
}
public function addNewMediaType($data): void
{
$model = new ProjectModel();
$model->insertNewMediaType($data);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace ppb\Controller;
use ppb\Model\TaskModel;
class TaskController {
public function __construct()
{
}
public function writeTask($data): void
{
$model = new TaskModel();
$model->insertTask($data);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace ppb\Controller;
use ppb\Model\UserModel;
class UserController {
public function __construct() {}
// GET all users
public function get($data = null): void
{
$model = new UserModel();
$result = $model->getAll();
header('Content-Type: application/json');
echo json_encode($result);
}
// CREATE new user
public function create($data): void
{
$model = new UserModel();
$result = $model->insert($data);
header('Content-Type: application/json');
echo json_encode($result);
}
// UPDATE user info
public function set($data): void
{
$model = new UserModel();
$result = $model->update($data);
header('Content-Type: application/json');
echo json_encode($result);
}
}