Améloration de la structure du code
This commit is contained in:
parent
5218b016f4
commit
fc234e4438
8 changed files with 320 additions and 31 deletions
33
app/controllers/project_controller.php
Normal file
33
app/controllers/project_controller.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
require("../app/models/project_model.php");
|
||||||
|
require("../app/entities/project_entity.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Le controler des article
|
||||||
|
* @author Yasser
|
||||||
|
*/
|
||||||
|
class ProjectCtrl{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fonction d'affichage de la page d'acceuil
|
||||||
|
*/
|
||||||
|
public function home(){
|
||||||
|
|
||||||
|
$objProjectModel = new ProjectModel;
|
||||||
|
$arrProject = $objProjectModel->findAll(4);
|
||||||
|
$arrProjectToDiplay = array();
|
||||||
|
foreach($arrProject as $arrDetProject){
|
||||||
|
$objProject = new Project;
|
||||||
|
$objProject->hydrate($arrDetProject);
|
||||||
|
var_dump($objProject);
|
||||||
|
$arrProjectToDiplay[] = $objProject;
|
||||||
|
}
|
||||||
|
|
||||||
|
include('../app/views/partials/header.php');
|
||||||
|
include('../app/views/home.php');
|
||||||
|
include('../app/views/partials/footer.php');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
app/entities/mother_entity.php
Normal file
22
app/entities/mother_entity.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe d'un Mere de tout objet
|
||||||
|
* @author Yass
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Entity{
|
||||||
|
|
||||||
|
protected string $_prefix = '';
|
||||||
|
|
||||||
|
|
||||||
|
public function hydrate(array $arrData){
|
||||||
|
foreach($arrData as $key=>$value){
|
||||||
|
$strMethodName = "set".ucfirst(str_replace($this->_prefix,'',$key));
|
||||||
|
if (method_exists($this,$strMethodName)){
|
||||||
|
$this->$strMethodName($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
203
app/entities/project_entity.php
Normal file
203
app/entities/project_entity.php
Normal file
|
|
@ -0,0 +1,203 @@
|
||||||
|
<?php
|
||||||
|
require_once("mother_entity.php");
|
||||||
|
/**
|
||||||
|
* Classe d'un objet Projet
|
||||||
|
* @author Yass
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Project extends Entity{
|
||||||
|
|
||||||
|
private int $_id;
|
||||||
|
private string $_title;
|
||||||
|
private string $_description;
|
||||||
|
private string $_thumbnail;
|
||||||
|
private string $_content;
|
||||||
|
private string $_creation_date;
|
||||||
|
private string $_status;
|
||||||
|
private int $_user;
|
||||||
|
private int $_category;
|
||||||
|
private string $_creatorname;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur (logique mdrr)
|
||||||
|
*/
|
||||||
|
public function __construct(){
|
||||||
|
$this->_prefix = 'project_';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode Getter et Setter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récuperation de l'id du Projet
|
||||||
|
* @return int l'id du projet
|
||||||
|
*/
|
||||||
|
public function getId():int{
|
||||||
|
return $this->_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour de l'id du projet
|
||||||
|
* @param int le nouvelle id
|
||||||
|
*/
|
||||||
|
public function setId($id){
|
||||||
|
$this->_id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récuperation du titre
|
||||||
|
* @return string tite du projet
|
||||||
|
*/
|
||||||
|
public function getTitle(){
|
||||||
|
return $this->_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour du titre
|
||||||
|
* @param string le nouveau titre
|
||||||
|
*/
|
||||||
|
public function setTitle($title){
|
||||||
|
$this->_title = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récuperation de la description
|
||||||
|
* @return string description du projet
|
||||||
|
*/
|
||||||
|
public function getDescription(){
|
||||||
|
return $this->_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour de la description
|
||||||
|
* @param string la nouvelle description
|
||||||
|
*/
|
||||||
|
public function setDescription($description){
|
||||||
|
$this->_description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récuperation de l'image
|
||||||
|
* @return string chemin vers l'image
|
||||||
|
*/
|
||||||
|
public function getThumbnail(){
|
||||||
|
return $this->_thumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour de l'image
|
||||||
|
* @param string chemin vers nouvelle image
|
||||||
|
*/
|
||||||
|
public function setThumbnail($thumbnail){
|
||||||
|
$this->_thumbnail = $thumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récuperation du contenue
|
||||||
|
* @return string contenue du projet
|
||||||
|
*/
|
||||||
|
public function getContent(){
|
||||||
|
return $this->_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour du contenue
|
||||||
|
* @param string le nouveau contenue
|
||||||
|
*/
|
||||||
|
public function setContent($content){
|
||||||
|
$this->_content = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupération de la date de création
|
||||||
|
* @param string lang de formatage de la date (par défaut = "fr_FR")
|
||||||
|
* @return string date de création formatter
|
||||||
|
*/
|
||||||
|
public function getCreation_date(string $strFormat = "fr_FR"){
|
||||||
|
$objDate = new DateTime($this->_creation_date);
|
||||||
|
|
||||||
|
$objDateFormatter = new IntlDateFormatter(
|
||||||
|
$strFormat,
|
||||||
|
IntlDateFormatter::LONG,
|
||||||
|
IntlDateFormatter::NONE,
|
||||||
|
|
||||||
|
);
|
||||||
|
$strFormat = $objDateFormatter->format($objDate);
|
||||||
|
return $strFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour de la date de création
|
||||||
|
* @param string la nouvelle date de création
|
||||||
|
*/
|
||||||
|
public function setCreation_date($creation_date){
|
||||||
|
$this->_creation_date = $creation_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupération du statut
|
||||||
|
* @return string statut
|
||||||
|
*/
|
||||||
|
public function getStatus(){
|
||||||
|
return $this->_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour du statut
|
||||||
|
* @param string le nouveau statut
|
||||||
|
*/
|
||||||
|
public function setStatus($status){
|
||||||
|
$this->_status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupération de l'utilisateur
|
||||||
|
* @return int id de l'utilisateur
|
||||||
|
*/
|
||||||
|
public function getUser(){
|
||||||
|
return $this->_user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour de l'utilisateur
|
||||||
|
* @param int id de l'utilisateur
|
||||||
|
*/
|
||||||
|
public function setUser($user){
|
||||||
|
$this->_user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupération de la catégorie
|
||||||
|
* @return int id de la catégorie
|
||||||
|
*/
|
||||||
|
public function getCategory(){
|
||||||
|
return $this->_category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour de la catégorie
|
||||||
|
* @param int id de la catégorie
|
||||||
|
*/
|
||||||
|
public function setCategory($category){
|
||||||
|
$this->_category = $category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupération du nom du créateur
|
||||||
|
* @return string nom du créateur
|
||||||
|
*/
|
||||||
|
public function getCreatorName(){
|
||||||
|
return $this->_creatorname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mise à jour du nom du créateur
|
||||||
|
* @param string le nom du créateur
|
||||||
|
*/
|
||||||
|
public function setCreatorName($creatorname){
|
||||||
|
$this->_creatorname = $creatorname;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
require(__DIR__ . '/../../config/database.php');
|
require('../config/database.php');
|
||||||
/**
|
|
||||||
* Traitement des requêtes pour les project
|
|
||||||
* @author : Yass
|
|
||||||
* @version : V0.01
|
|
||||||
*/
|
|
||||||
class ProjectModel extends Connect{
|
class ProjectModel extends Connect{
|
||||||
|
|
||||||
public function findAll(int $intLimit=0, string $strKeywords='', int $intAuthor=0,
|
public function findAll(int $intLimit=0, string $strKeywords='', int $intAuthor=0,
|
||||||
|
|
|
||||||
17
app/views/home.php
Normal file
17
app/views/home.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<section class="container mt-5 p-5 d-flex flex-column align-items-center text-center">
|
||||||
|
<h1 class="logo">Folliow</h1>
|
||||||
|
<h2>Là où les talents rencontrent leur avenir</h2>
|
||||||
|
<p class="col-6">Une plateforme de portfolio adapté à vos besoins et aux besoins des entreprises.
|
||||||
|
Créer un portfolio réellement pertinent aux exigences du marché et rentrez
|
||||||
|
directement en contact avec les entreprises.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section aria-label="Articles récents">
|
||||||
|
<h2 class="visually-hidden">Les 4 derniers articles</h2>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<?php
|
||||||
|
foreach($arrProjectToDiplay as $objProject){
|
||||||
|
include("../app/views/partials/project.php");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</section>
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
|
||||||
19
app/views/partials/project.php
Normal file
19
app/views/partials/project.php
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<article class="col-md-6 mb-4">
|
||||||
|
<div class="row g-0 border rounded overflow-hidden flex-md-row shadow-sm h-md-250 position-relative">
|
||||||
|
<div class="col p-4 d-flex flex-column position-static">
|
||||||
|
<h3 class="mb-2"><?php echo $objProject->getTitle(); ?></h3>
|
||||||
|
<div class="mb-2 text-body-secondary">
|
||||||
|
<time datetime="2017-05-11"><?php echo $objProject->getCreation_date(); ?></time>
|
||||||
|
<span> - <?php echo $objProject->getCreatorname(); ?></span>
|
||||||
|
</div>
|
||||||
|
<p class="mb-auto"><?php echo $objProject->getDescription(); ?></p>
|
||||||
|
<a href="article-javascript.html" class="icon-link gap-1 icon-link-hover stretched-link" aria-label="Lire l'article complet sur le devenir du JavaScript">
|
||||||
|
Lire la suite
|
||||||
|
<i class="fas fa-arrow-right" aria-hidden="true"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto d-none d-lg-block">
|
||||||
|
<img class="bd-placeholder-img" width="200" height="250" src="<?php echo $objProject->getThumbnail(); ?>" alt="" loading="lazy">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
|
@ -1,30 +1,28 @@
|
||||||
<?php
|
<?php
|
||||||
require_once '../app/views/partials/header.php' ;
|
$strCtrl = $_GET['ctrl']??'project';
|
||||||
|
$strMethod = $_GET['action']??'home';
|
||||||
|
|
||||||
require "../app/models/project_model.php";
|
$boolError = false;
|
||||||
$objProjectModel = new ProjectModel;
|
$strFileName = "../app/controllers/".$strCtrl."_controller.php";
|
||||||
$arrArticle = $objProjectModel->findAll(4);
|
|
||||||
|
|
||||||
var_dump($arrArticle);
|
if(file_exists($strFileName)){
|
||||||
|
require($strFileName);
|
||||||
|
$strClassName = ucfirst($strCtrl)."Ctrl";
|
||||||
|
if(class_exists($strClassName)){
|
||||||
|
$objController = new $strClassName();
|
||||||
|
if(method_exists($objController,$strMethod)){
|
||||||
|
$objController->$strMethod();
|
||||||
|
}else{
|
||||||
|
$boolError = true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$boolError = true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$boolError = true;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
if($boolError){
|
||||||
|
echo "error 404 - la page elle existe pas batard";
|
||||||
|
}
|
||||||
|
|
||||||
<section class="container mt-5 p-5 d-flex flex-column align-items-center text-center">
|
|
||||||
<h1 class="logo">Folliow</h1>
|
|
||||||
<h2>Là où les talents rencontrent leur avenir</h2>
|
|
||||||
<p class="col-6">Une plateforme de portfolio adapté à vos besoins et aux besoins des entreprises.
|
|
||||||
Créer un portfolio réellement pertinent aux exigences du marché et rentrez
|
|
||||||
directement en contact avec les entreprises.</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section aria-label="Articles récents">
|
|
||||||
<h2 class="visually-hidden">Les 4 derniers articles</h2>
|
|
||||||
<div class="row mb-2">
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
|
||||||
require_once '../app/views/partials/footer.php' ;
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue