version pour laura et besnik

This commit is contained in:
Yass 2026-01-15 18:03:42 +01:00
parent 024cf537ed
commit 4fd89380c0
6 changed files with 174 additions and 120 deletions

View file

@ -3,7 +3,7 @@
require("../app/entities/project_entity.php"); require("../app/entities/project_entity.php");
/** /**
* Le controler des article * Le controler des Project
* @author Yasser * @author Yasser
*/ */
class ProjectCtrl{ class ProjectCtrl{
@ -29,4 +29,35 @@
} }
public function search(){
// inclusion du header
include('../app/views/partials/header.php');
//Récupérer les informations du Formulaire
// Récupération des Projects
$objProjectModel = new ProjectModel;
//$arrProject = findAll(0, $strKeywords, $intAuthor, $intPeriod, $strDate, $strStartDate, $strEndDate);
// Depuis PHP 8 - accès direct aux paramètres
$arrProject = $objProjectModel->findAll();
// Initialisation d'un tableau => objets
$arrProjectToDisplay = array();
// Boucle de transformation du tableau de tableau en tableau d'objets
foreach($arrProject as $arrDetProject){
$objProject = new Project;
$objProject->hydrate($arrDetProject);
$arrProjectToDisplay[] = $objProject;
}
// Récupération des utilisateurs
require("../app/models/user_model.php");
$objUserModel = new UserModel;
$arrUser = $objUserModel->findAllUsers();
include('../app/views/search.php');
include('../app/views/partials/footer.php');
}
} }

View file

@ -52,76 +52,6 @@ class UserCtrl{
} }
public function create(){
// Variables d'affichage
$strH2 = "Créer un compte";
$strP = "Inscrivez-vous";
// Variables technique
$strPage = "create_account";
// inclusion du header
include("views/_partial/header.php");
// Traitement du formulaire
//var_dump($_POST);
$strName = $_POST['name']??"";
$strFirstname = $_POST['firstname']??"";
$strMail = $_POST['mail']??"";
$strPwd = $_POST['pwd']??"";
$strPwdConfirm = $_POST['pwd_confirm']??"";
$objUser = new User;
$objUser->hydrate($_POST);
/*
$objUser->setName($strName);
$objUser->setFirstname($strFirstname);
$objUser->setMail($strMail);
$objUser->setPwd($strPwd);
*/
// Tester le formulaire
$arrError = [];
if (count($_POST) > 0) {
if ($objUser->getName() == ""){
$arrError['name'] = "Le nom est obligatoire";
}
if ($objUser->getFirstname() == ""){
$arrError['firstname'] = "Le prénom est obligatoire";
}
if ($objUser->getMail() == ""){
$arrError['mail'] = "Le mail est obligatoire";
}else if (!filter_var($objUser->getMail(), FILTER_VALIDATE_EMAIL)){
$arrError['mail'] = "Le format du mail n'est pas correct";
}
$strRegex = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{16,}$/";
if ($objUser->getPwd() == ""){
$arrError['pwd'] = "Le mot de passe est obligatoire";
}else if (!preg_match($strRegex, $objUser->getPwd())){
$arrError['pwd'] = "Le mot de passe ne correspond pas aux règles";
}else if($objUser->getPwd() != $strPwdConfirm){
$arrError['pwd_confirm'] = "Le mot de passe et sa confirmation ne sont pas identiques";
}
// Ajouter la vérification du mot de passe par regex
// Si le formulaire est rempli correctement
if (count($arrError) == 0){
// => Ajout dans la base de données
$objUserModel = new UserModel;
//$intNbInsert = $objUserModel->insert($strName, $strFirstname, $strMail, $strPwd);
$boolInsert = $objUserModel->insert($objUser);
if ($boolInsert === true){
$_SESSION['success'] = "Le compte a bien été créé";
//header("Location:index.php");
//exit;
}else{
$arrError[] = "Erreur lors de l'ajout";
}
//var_dump("tout est ok");
}
}
include("views/create_account.php");
include("views/_partial/footer.php");
}
public function logout(){ public function logout(){
session_start(); session_start();

View file

@ -1,11 +1,9 @@
<?php <?php
require('../config/database.php'); require_once('../config/database.php');
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):array{
int $intPeriod=0, string $strDate='', string $strStartDate='',
string $strEndDate=''):array{
// Ecrire la requête // Ecrire la requête
$strRq = "SELECT project.*, $strRq = "SELECT project.*,
@ -13,51 +11,7 @@
user_image user_image
FROM project FROM project
INNER JOIN users ON user_id = project_user"; INNER JOIN users ON user_id = project_user";
// Pour le where (un seul)
//$boolWhere = false; // flag
$strWhere = " WHERE ";
// Recherche par mot clé
if ($strKeywords != '') {
$strRq .= " WHERE (project_title LIKE '%".$strKeywords."%'
OR project_content LIKE '%".$strKeywords."%') ";
//$boolWhere = true;
$strWhere = " AND ";
}
// Recherche par auteur
if ($intAuthor > 0){
/*if ($boolWhere){
$strRq .= " AND ";
}else{
$strRq .= " WHERE ";
}*/
$strRq .= $strWhere." project_creator = ".$intAuthor;
$strWhere = " AND ";
}
// Recherche par dates
if ($intPeriod == 0){
// Par date exacte
if ($strDate != ''){
$strRq .= $strWhere." project_creation_date = '".$strDate."'";
}
}else{
// Par période de dates
if ($strStartDate != '' && $strEndDate != ''){
//if ( ($strStartDate != '') && ($strEndDate != '') ){ Parethèses selon le développeur - pas de changement si que des && - Attention ||
$strRq .= $strWhere." project_creation_date BETWEEN '".$strStartDate."' AND '".$strEndDate."'";
}else{
if ($strStartDate != ''){
// A partir de
$strRq .= $strWhere." project_creation_date >= '".$strStartDate."'";
}else if ($strEndDate != ''){
// Avant le
$strRq .= $strWhere." project_creation_date <= '".$strEndDate."'";
}
}
}
$strRq .= " ORDER BY project_creation_date DESC";
if ($intLimit > 0){ if ($intLimit > 0){
$strRq .= " LIMIT ".$intLimit; $strRq .= " LIMIT ".$intLimit;

View file

@ -1,5 +1,5 @@
<?php <?php
require('../config/database.php'); require_once('../config/database.php');
/** /**
* Traitement des requêtes pour les utilisateurs * Traitement des requêtes pour les utilisateurs

View file

@ -41,6 +41,10 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="?ctrl=''&action=''">À propos</a> <a class="nav-link" href="?ctrl=''&action=''">À propos</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="?ctrl=project&action=search">Rechercher</a>
</li>
</ul> </ul>
<!-- Menu secondaire --> <!-- Menu secondaire -->

135
app/views/search.php Normal file
View file

@ -0,0 +1,135 @@
<section aria-label="Blog">
<h2 class="visually-hidden">Rechercher parmi les articles</h2>
<div class="row mb-2">
<section class="mb-5" aria-labelledby="search-heading">
<form name="formSearch" method="post" action="?ctrl=project&action=search" class="border rounded p-4 bg-light">
<h3 id="search-heading" class="h4 mb-4">
<i class="fas fa-search me-2" aria-hidden="true"></i>
Rechercher des articles
</h3>
<div class="row g-3">
<div class="col-md-6">
<label for="keywords" class="form-label">Mots-clés</label>
<input
value=""
type="text"
class="form-control"
id="keywords"
name="keywords"
placeholder="Ex: JavaScript, CSS..."
aria-describedby="keywords-help">
<small id="keywords-help" class="form-text text-muted">
Recherchez dans les titres et contenus
</small>
</div>
<div class="col-md-6">
<label for="author" class="form-label">Auteur</label>
<select class="form-select" id="author" name="author">
<option value="0">Tous les auteurs</option>
</select>
</div>
<div class="col-12">
<fieldset>
<legend class="form-label">Type de recherche par date</legend>
<div class="form-check form-check-inline">
<input
class="form-check-input"
type="radio"
name="period"
id="period-exact"
value="0"
aria-controls="date-exact date-range">
<label class="form-check-label" for="period-exact">
Date exacte
</label>
</div>
<div class="form-check form-check-inline">
<input
class="form-check-input"
type="radio"
name="period"
id="period-range"
value="1"
aria-controls="date-exact date-range">
<label class="form-check-label" for="period-range">
Période
</label>
</div>
</fieldset>
</div>
<div class="col-md-6" id="date-exact">
<label for="date" class="form-label">Date</label>
<input
type="date"
class="form-control"
id="date"
name="date"
aria-describedby="date-help"
value="" >
<small id="date-help" class="form-text text-muted">
Format: JJ/MM/AAAA
</small>
</div>
<div id="date-range" style="display: none;">
<div class="row g-3">
<div class="col-md-6">
<label for="startdate" class="form-label">Date de début</label>
<input
type="date"
class="form-control"
id="startdate"
name="startdate"
value="" >
</div>
<div class="col-md-6">
<label for="enddate" class="form-label">Date de fin</label>
<input
type="date"
class="form-control"
id="enddate"
name="enddate"
value="" >
</div>
</div>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">
<i class="fas fa-search me-2" aria-hidden="true"></i>
Rechercher
</button>
<button type="reset" class="btn btn-secondary ms-2">
<i class="fas fa-redo me-2" aria-hidden="true"></i>
Réinitialiser
</button>
</div>
</div>
</form>
</section>
<!-- Liste des articles -->
<section aria-labelledby="articles-heading">
<h3 id="articles-heading" class="visually-hidden">Liste des projets</h3>
<div class="row mb-2">
<?php
if (count($arrProject) == 0){
?>
<div class="alert alert-warning">
<p>Pas de résultats</p>
</div>
<?php
}
foreach($arrProjectToDisplay as $objProject){
include("../app/views/partials/project.php");
} ?>
</div>
</section>
</div>
</section>