🥸Dự án Feature Link Study
Last updated
Last updated
composer.json
{
"name": "futurelink/main",
"type": "project",
"license": "MIT",
"autoload": {
"psr-4": {
"Futurelink\\Main\\": "src/"
}
}
}
public\index.php
<?php
use Futurelink\Main\Core\Bootstrap;
require_once realpath(path: dirname(path: __DIR__)."/vendor/autoload.php");
$bootstrap = new Bootstrap();
src\Core\Bootstrap.php
<?php
namespace Futurelink\Main\Core;
class Bootstrap {
private $controllers;
private $method;
private $params;
public function __construct() {
$this->url();
$this->render();
}
private function url(): void {
$url = trim(string: $_SERVER['REQUEST_URI'], characters: "/");
$url = explode(separator: "/", string: $url, limit: 3);
$this->controllers = (!empty($url[0])) ? $url[0] : "Home";
$this->method = (!empty($url[1])) ? $url[1] : "default";
$this->params = (!empty($url[2])) ? explode(separator: "/", string: $url[2]) : [];
}
private function render() {
$controller = "Futurelink\\Main\\Controllers\\" . $this->controllers . "Controller";
if (!class_exists(class: $controller)) {
$controller = "Futurelink\\Main\\Controllers\\NotFoundController";
}
$controller = new $controller();
$controller->setController($this->controllers);
$controller->setMethod($this->method);
$controller->setParams($this->params);
$this->method = $this->method . "Method";
if (!method_exists(object_or_class: $controller, method: $this->method)) {
$this->method = "notFoundMethod";
}
call_user_func_array(callback: [$controller, $this->method], args: $this->params);
}
}
src\Controllers\HomeController.php
<?php
namespace Futurelink\Main\Controllers;
class HomeController extends AbstractController {
public function defaultMethod() {
echo "HomeController";
}
}
src\Controllers\NotFoundController.php
<?php
namespace Futurelink\Main\Controllers;
class NotFoundController {
public function __construct() {
echo "NotFoundController";
}
}
src\Controllers\AbstractController.php
<?php
namespace Futurelink\Main\Controllers;
class AbstractController {
protected $controller;
protected $method;
protected $params;
public function notFoundMethod(): void
{
$this->controller = "notound";
$this->method = "notFound";
}
public function setController($controllerName): void
{
$this->controller = $controllerName;
}
public function setMethod($methodName): void
{
$this->method = $methodName;
}
public function setParams($paramsName): void
{
$this->params = $paramsName;
}
}
src\Controllers\AbstractController.php
<?php
namespace Futurelink\Main\Controllers;
class AbstractController {
protected $controller;
protected $method;
protected $params;
protected $data = [];
public function notFoundMethod(): void
{
$this->controller = "notound";
$this->method = "notFound";
$this->view();
}
public function setController($controllerName): void
{
$this->controller = $controllerName;
}
public function setMethod($methodName): void
{
$this->method = $methodName;
}
public function setParams($paramsName): void
{
$this->params = $paramsName;
}
protected function view(): void {
$file = dirname(path: __DIR__) . "\\views\\{$this->controller}\\{$this->method}.view.php";
if (file_exists(filename: $file)) {
extract($this->data);
if ($this->method == 'login') {
require_once($file);
}else {
$header = dirname(path: __DIR__) . "\\setting\\header.php";
require_once($file);
$footer = dirname(path: __DIR__) . "\\setting\\footer.php";
}
}else {
die("Not Found File" . $file);
}
}
}
src\Controllers\HomeController.php
<?php
namespace Futurelink\Main\Controllers;
class HomeController extends AbstractController {
public function defaultMethod() {
$this->view();
}
}
src\setting\header.php
<?php
@session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="/assets/images/icon.png"/>
<!-- Google Font: Source Sans Pro -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
<!-- Font Awesome -->
<link rel="stylesheet" href="/assets/plugins/fontawesome-free/css/all.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="/assets/dist/css/adminlte.css">
<link rel="stylesheet" href="/assets/dist/css/main.css">
<script src="/assets/plugins/jquery/jquery.min.js"></script>
</head>
<body class="hold-transition sidebar-mini">
<!-- Site wrapper -->
<div class="wrapper">
<!-- Navbar -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
<!-- Left navbar links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="/" class="nav-link">Home page</a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="/orders" class="nav-link">Maintenance requests</a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="/clients" class="nav-link">Clients</a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="/payments/orders" class="nav-link">Request collections</a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="/payments/" class="nav-link">Basic expenses</a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="/payments/notmain" class="nav-link">Unnoticed expenses</a>
</li>
</ul>
<!-- Right navbar links -->
</nav>
<!-- /.navbar -->
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="/home" class="brand-link text-center">
<img src="/assets/images/Group 5.png" alt="Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
<span class="brand-text font-weight-light">Future Link</span>
</a>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user (optional) -->
<div class="user-panel my-3 pb-3 text-center">
<div class="image px-0">
<i class="fas fa-user " style="color: #C2C7D0; font-size:24px; margin-right:15px;"></i>
<!-- <img src="/assets/dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image"> -->
</div>
<div class="info pb-0 pt-2 ">
<a href="/user/" class="d-block">
<?php
if(isset($_SESSION['name'] )) {
echo $_SESSION['name'];
}
?>
</a>
</div>
</div>
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-cog"></i>
<p>
Maintenance request management
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/orders/" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>View open orders</p>
</a>
</li>
<li class="nav-item">
<a href="/orders/closed" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>View closed orders</p>
</a>
</li>
<li class="nav-item">
<a href="/orders/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add a request</p>
</a>
</li>
<li class="nav-item">
<a href="/orders/closeview" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Clash request</p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-user-friends"></i>
<p>
Customer management
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/clients/" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Show all customers</p>
</a>
</li>
<li class="nav-item">
<a href="/clients/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add a customer</p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-users-cog"></i>
<p>
Personnel management
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/employees/" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Show all employees</p>
</a>
</li>
<li class="nav-item">
<a href="/employees/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add an employee</p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-money-bill-wave"></i>
<p>
Financial matters
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/payments/orders" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>View request collections</p>
</a>
</li>
<li class="nav-item">
<a href="/payments/" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Basic expenses</p>
</a>
</li>
<li class="nav-item">
<a href="/payments/notmain" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Unnoticed expenses</p>
</a>
</li>
<li class="nav-item">
<a href="/payments/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>addition </p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-toolbox"></i>
<p>
Spare parts
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/parts/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add a piece</p>
</a>
</li>
<li class="nav-item">
<a href="/parts/edit" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Modify a piece</p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-desktop"></i>
<p>
Types of devices
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/devicesType/" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Show all devices</p>
</a>
</li>
<li class="nav-item">
<a href="/devicesType/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add a device</p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-layer-group"></i>
<p>
All brand
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/devicesBrand/" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Show all brand</p>
</a>
</li>
<li class="nav-item">
<a href="/devicesBrand/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add Brand</p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fas fa-tools"></i>
<p>
Maintenance breakdowns
<i class="right fas fa-angle-down"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/problems/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add a malfunction</p>
</a>
</li>
<li class="nav-item">
<a href="/problems/edit" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Malfunction</p>
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item mt-3">
<form action="#" method="post"><a><button type="submit" class="btn btn-block btn-info btn-sm" style="white-space: break-spaces;" name="logout">Log Out</button></a></form>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>
src\setting\footer.php
<!-- <footer class="main-footer">
<div class="float-right d-none d-sm-block">
</div>
<strong> All rights reserved © 2022 <a href="https://adminlte.io">Abdullah Al -Rahmani</a></strong>
</footer> -->
<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
<!-- Control sidebar content goes here -->
</aside>
<!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<!-- jQuery -->
<!-- Bootstrap 4 -->
<script src="/assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="/assets/dist/js/adminlte.min.js"></script>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<!-- AdminLTE for demo purposes -->
</body>
</html>
src\views\Home\default.view.php
default.view.php
src\Controllers\HomeController.php
<?php
namespace Futurelink\Main\Controllers;
use Futurelink\Main\Models\OrdersModel;
class HomeController extends AbstractController {
public function defaultMethod() {
$today = date('Y-m-d');
$month = date('m');
$orders = new OrdersModel();
$this->data['todayOrders'] = $orders->getOrdersByDate("'$today'");
$this->data['montOrders'] = $orders->getOrdersByDate("'$month'");
$this->data['todayClosedOrders'] = $orders->getOrdersByDateClosed("'$today'");
$this->view();
}
}
src\Models\AbstractModel.php
<?php
namespace Futurelink\Main\Models;
use PDO;
use PDOException;
class AbstractModel {
public $connection;
public $query;
public $sql;
public $error;
public function __construct() {
$dsn = "mysql:host=localhost;dbname=lva2;";
$options = array(
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
try {
$this->connection = new PDO($dsn, "root", "", $options);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
$this->error = $e->getMessage();
}
}
public function select($table, $column)
{
$this->sql = "SELECT {$column} FROM `{$table}`";
return $this;
}
public function whereFilter($column, $compare, $data)
{
if ($data == 'off') {
$this->sql .= " WHERE `$column` >= 0 ";
} else {
$this->sql .= " WHERE $column $compare $data ";
}
return $this;
}
public function query()
{
// echo $this->sql;
$this->query = $this->connection->prepare(query: $this->sql);
return $this;
}
public function executeQuery()
{
// echo $this->sql;
if ($this->query->execute()) {
return 1;
} else {
return 'error';
}
}
public function getAll()
{
$this->query();
$this->executeQuery();
$rows = $this->query->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
}
src\Models\OrdersModel.php
<?php
namespace Futurelink\Main\Models;
class OrdersModel extends AbstractModel {
public function getOrdersByDate($date)
{
return $this->select("orders", "count(orderId) as ordersNum")->whereFilter("openDate", "=", $date)->getAll();
}
public function getOrdersByDateClosed($date)
{
return $this->select("orders", "count(orderId) as ordersNum")->whereFilter("closeDate", "=", $date)->getAll();
}
}
src\views\Home\default.view.php
<?php
echo '<pre>';
var_export($todayOrders);
echo '</pre>';
src\Models\PaymentsModel.php
<?php
namespace Futurelink\Main\Models;
class PaymentsModel extends AbstractModel {
public function getPaymentsByMonth($month)
{
return $this->select("payments", "SUM(cost) as paymentsCost")->whereFilter("MONTH(createdAt)", "=", $month)->getAll();
}
}
src\Controllers\HomeController.php
<?php
namespace Futurelink\Main\Controllers;
use Futurelink\Main\Models\OrdersModel;
use Futurelink\Main\Models\PaymentsModel;
class HomeController extends AbstractController {
public function defaultMethod() {
$today = date('Y-m-d');
$month = date('m');
$orders = new OrdersModel();
$payment = new PaymentsModel();
$this->data['todayOrders'] = $orders->getOrdersByDate("'$today'");
$this->data['todayClosedOrders'] = $orders->getOrdersByDateClosed("'$today'");
$this->data['monthPaymentCost'] = $payment->getPaymentsByMonth("'$month'");
$this->view();
}
}
src\views\Home\default.view.php
<?php
echo '<pre>';
var_export($monthPaymentCost);
echo '</pre>';
src\Controllers\OrdersController.php
<?php
namespace Futurelink\Main\controllers;
use Futurelink\Main\Models\OrdersModel;
class OrdersController extends AbstractController {
public function defaultMethod($params = []) {
$status = ['status' => 0];
$orders = new OrdersModel();
$this->data['orders'] = $orders->getAllOrdersStatus($status, 'openDate');
$this->view();
}
}
Edit src\Core\Bootstrap.php
<?php
namespace Futurelink\Main\Core;
class Bootstrap {
private $controllers;
private $method;
private $params;
public function __construct() {
$this->url();
$this->render();
}
private function url(): void {
$url = trim(string: $_SERVER['REQUEST_URI'], characters: "/");
$url = explode(separator: "/", string: $url, limit: 3);
$this->controllers = (!empty($url[0])) ? $url[0] : "Home";
$this->method = (!empty($url[1])) ? $url[1] : "default";
$this->params = (!empty($url[2])) ? explode(separator: "/", string: $url[2]) : [];
}
private function render() {
$controller = "Futurelink\\Main\\Controllers\\" . $this->controllers . "Controller";
if (!class_exists(class: $controller)) {
$controller = "Futurelink\\Main\\Controllers\\NotFoundController";
}
$controller = new $controller();
$controller->setController($this->controllers);
$controller->setMethod($this->method);
$controller->setParams($this->params);
$this->method = $this->method . "Method";
if (!method_exists(object_or_class: $controller, method: $this->method)) {
$this->method = "notFoundMethod";
}
call_user_func_array(callback: [$controller, $this->method], args: $this->params);
}
}
src\Controllers\AbstractController.php
<?php
namespace Futurelink\Main\Controllers;
class AbstractController {
protected $controller;
protected $method;
protected $params;
protected $data = [];
public function notFoundMethod(): void
{
$this->controller = "notound";
$this->method = "notFound";
$this->view();
}
public function setController($controllerName): void
{
$this->controller = $controllerName;
}
public function setMethod($methodName): void
{
$this->method = $methodName;
}
public function setParams($paramsName): void
{
$this->params = $paramsName;
}
protected function view(): void {
$file = dirname(path: __DIR__) . "\\views\\".ucfirst($this->controller)."\\{$this->method}.view.php";
if (file_exists(filename: $file)) {
extract($this->data);
if ($this->method == 'login') {
require_once($file);
}else {
$header = dirname(path: __DIR__) . "\\setting\\header.php";
require_once($file);
$footer = dirname(path: __DIR__) . "\\setting\\footer.php";
}
}else {
die("Not Found File" . $file);
}
}
}
src\Models\OrdersModel.php
<?php
namespace Futurelink\Main\Models;
class OrdersModel extends AbstractModel {
public function getOrdersByDate($date): array|bool
{
return $this->select("orders", "count(orderId) as ordersNum")->whereFilter("openDate", "=", $date)->getAll();
}
public function getOrdersByDateClosed($date): array|bool
{
return $this->select("orders", "count(orderId) as ordersNum")->whereFilter("closeDate", "=", $date)->getAll();
}
public function getAllOrdersStatus($status, $order): array
{
return $this->select("order_details", "*")->where("status", "=", $status)->orderBy($order, 'DESC')->getAllWe();
}
}
src\Models\AbstractModel.php
<?php
namespace Futurelink\Main\Models;
use PDO;
use PDOException;
class AbstractModel {
public $connection;
public $query;
public $sql;
public $error;
public function __construct() {
$dsn = "mysql:host=localhost;dbname=lva1;";
$options = array(
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
try {
$this->connection = new PDO($dsn, "root", "", $options);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
$this->error = $e->getMessage();
}
}
public function select($table, $column)
{
$this->sql = "SELECT {$column} FROM `{$table}`";
return $this;
}
public function whereFilter($column, $compare, $data): static
{
if ($data == 'off') {
$this->sql .= " WHERE `$column` >= 0 ";
} else {
$this->sql .= " WHERE $column $compare $data ";
}
return $this;
}
public function query()
{
// echo $this->sql;
$this->query = $this->connection->prepare(query: $this->sql);
return $this;
}
public function executeQuery(): int|string
{
if ($this->query->execute()) {
return 1;
} else {
return 'error';
}
}
public function getAll(): array|bool
{
$this->query();
$this->executeQuery();
$rows = $this->query->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
public function setData($data): static
{
$this->query();
foreach ($data as $key => $val) {
$key = ":" . $key;
$this->query->bindValue($key, $val);
}
return $this;
}
public function orderBy($column, $type): static
{
$this->sql .= "ORDER BY `$column` $type ";
return $this;
}
public function getAllWe(): array|bool
{
$this->executeQuery();
$rows = $this->query->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
public function where($column, $compare, $data): static
{
$this->sql .= " WHERE $column $compare:$column";
$this->setData($data);
return $this;
}
}
src\views\Orders\default.view.php
<?php
echo '<pre>';
var_export($orders);
echo '</pre>';