This commit is contained in:
GuillaumeH-Cci 2026-02-20 11:14:45 +01:00
parent 747bc76de2
commit e6c64912c3
8 changed files with 203 additions and 334 deletions

View file

@ -25,7 +25,7 @@
public function home(){ public function home(){
$intCategory = 0; $intCategory = 0;
if (!empty($_GET['filter_cat'])) { if (!empty($_GET['filter_cat'])) {
$intCategory = (int) $_GET['filter_cat']; $intCategory = (int) $_GET['filter_cat'];
} }
@ -93,87 +93,196 @@
/** /**
* Fonction d'affichage de la page projet * Fonction d'affichage de la page projet
* @author Christel adapter par Guillaume
*/ */
public function project (){ public function addedit_project() {
if (!isset($_SESSION['user'])){ // Pas d'utilisateur connecté
$objCategoryModel = new CategoryModel; header("Location:index.php?ctrl=error&action=error_403");
$arrCategory = $objCategoryModel->findAllCategory(); exit;
$objProjectModel = new ProjectModel;
$arrProject = $objProjectModel->findAll(4);
$arrProjectToDisplay = array();
foreach($arrProject as $arrDetProject){
$objProject = new Project;
$objProject->hydrate($arrDetProject);
$arrProjectToDisplay[] = $objProject;
}
$objImageModel = new ImageModel;
$arrImage = $objImageModel->findAllImage(4);
$arrImageToDisplay = array();
foreach($arrImage as $arrDetImage){
$objImage = new Image;
$objImage->hydrate($arrDetImage);
$arrImageToDisplay[] = $objImage;
}
//Variable data
$_SESSION['title'] = $_POST['titleProject']??"";
$_SESSION['description'] = $_POST['descProject']??"";
$_SESSION['content'] = $_POST['textProject']??"";
$_SESSION['category']= $_POST['category']??0;
$_SESSION['thumbnail'] = $_FILES['imageThumbnail']['name']??"";
$_SESSION['images'] = $_FILES['imageProject']['name']??"";
$_SESSION['status'] = 'en_attente';
$_SESSION['user_id'] = $_SESSION['user']['user_id']??null;
$objProject = new Project();
/**
* Créer par Besnik le GOAT et Guillaume
*
* @return bool pour savoir si le fichier existe,
* puis déplace vers le fichier uploads avec les images projet des utilisateurs
* Communication avec la BDD
*/
if (($_SESSION['thumbnail'] != null)){
$strDest = "";
if ((count($_FILES) > 0) && ($_FILES['imageProject']['error'] != 4)){
$strDest = 'uploads/projects/' . $_FILES['imageProject']['name'];
move_uploaded_file($_FILES['imageProject']['tmp_name'], $strDest);
}
}
/** En cas d'appuis sur le bouton d'envoie ou celui de remettre a plus tard
* 1. Changement de status
* 2. Hydratation avec les informations récupéré de l'utilisateur
* 3. Envoie des données à la BDD
*/
if (isset($_POST['sendProject'])) {
$objProject->hydrate($_SESSION);
$objProject->setThumbnail($strDest);
$objProjectModel->insert($objProject);
// header("Location:index.php");
// exit;
var_dump($_SESSION);
var_dump($objProject);
} }
// } else if (isset($_POST['toContinue'])) {
// $objProject->hydrate($_SESSION);
// $objProject->setThumbnail($strDest);
//$objProjectModel->insert($objProject);
// header("Location: index.php");
// exit;
// }
$this->_arrData['arrCategory'] = $arrCategory;
$this->_arrData['arrProjectToDiplay'] = $arrProjectToDisplay;
$this->_arrData['arrImageToDiplay'] = $arrImageToDisplay;
$this->_display("project"); // <A changer pour récupérer l'ancien formulaire $objProject = new Project;
// $this->_display('addedit_project'); // <A changer pour récupérer le nouveau formulaire $objProjectModel = new ProjectModel;
} $objCategoryModel = new CategoryModel;
// dans la cas de modif
if (isset($_GET['id'])){
$arrProject = $objProjectModel->find($_GET['id']);
$objProject->hydrate($arrProject); // BDD
}
// Tester le formulaire
$arrError = [];
if (count($_POST) > 0) {
$objProject->hydrate($_POST); // Formulaire
if ($objProject->getTitle() == ""){
$arrError['title'] = "Le titre est obligatoire";
}
if ($objProject->getDescription() == ""){
$arrError['description'] = "La description est obligatoire";
}
if ($objProject->getContent() == ""){
$arrError['content'] = "Le contenu est obligatoire";
}
// Vérification de l'image
$arrTypeAllowed = array('image/jpeg', 'image/png', 'image/webp');
if ($_FILES['imageThumbnail']['error'] != 4){
if (!in_array($_FILES['imageThumbnail']['type'], $arrTypeAllowed)){
$arrError['imageThumbnail'] = "Le type de fichier n'est pas autorisé";
}else{
// Vérification des codes d'erreur
switch ($_FILES['imageThumbnail']['error']){
case 0 :
// Renommage de l'image
$strImageName = uniqid().".webp";
/* uniquement si on veut garder l'extension du fichier originel */
/*switch ($_FILES['img']['type']){
case 'image/jpeg' :
$strImageName .= '.jpg';
break;
case 'image/png' :
$strImageName .= '.png';
break;
}*/
// Récupère le nom de l'image avant changement
$strOldImg = $objProject->getThumbnail();
// Mise à jour du nom de l'image dans l'objet
$objProject->setThumbnail($strImageName);
break;
case 1 :
$arrError['imageThumbnail'] = "Le fichier est trop volumineux";
break;
case 2 :
$arrError['imageThumbnail'] = "Le fichier est trop volumineux";
break;
case 3 :
$arrError['imageThumbnail'] = "Le fichier a été partiellement téléchargé";
break;
case 6 :
$arrError['imageThumbnail'] = "Le répertoire temporaire est manquant";
break;
default :
$arrError['imageThumbnail'] = "Erreur sur l'image";
break;
}
}
}else{
// Est-ce que le fichier existe ?
if (is_null($objProject->getThumbnail())){
$arrError['imageThumbnail'] = "L'image est obligatoire";
}
}
// Si le formulaire est rempli correctement
if (count($arrError) == 0){
if (is_null($objProject->getId())){
// => Ajout dans la base de données
$boolOk = $objProjectModel->insert($objProject);
}else{
$boolOk = $objProjectModel->updateProject($objProject);
}
if ($boolOk === true){
if (isset($strImageName)){
// Création du chemin de destination
$strDest = $_ENV['IMG_PATH'].$strImageName;
// Récupération de la source de l'image
$strSource = $_FILES['imageThumbnail']['tmp_name'];
// Récupération des dimensions de l'image source
list($intWidth, $intHeight) = getimagesize($strSource);
// Dimensions de destination
$intDestWidth = 200;
$intDestHeight = 250;
// Calcul du ratio de destination
$fltDestRatio = $intDestWidth / $intDestHeight;
// Calcul du ratio de la source
$fltSourceRatio = $intWidth / $intHeight;
// Détermination de la zone à cropper
if ($fltSourceRatio > $fltDestRatio) {
// L'image source est plus large → on crop en largeur
$intCropHeight = $intHeight;
$intCropWidth = round($intHeight * $fltDestRatio);
$intCropX = ($intWidth - $intCropWidth) / 2; // Centrage horizontal
$intCropY = 0;
} else {
// L'image source est plus haute → on crop en hauteur
$intCropWidth = $intWidth;
$intCropHeight = round($intWidth / $fltDestRatio);
$intCropX = 0;
$intCropY = ($intHeight - $intCropHeight) / 2; // Centrage vertical
}
// Création d'une image 'vide'
$objDest = imagecreatetruecolor($intDestWidth, $intDestHeight);
// Création d'un objet image à partir de la source (attention au type de fichier)
switch ($_FILES['imageThumbnail']['type']){
case 'image/jpeg' :
$objSource = imagecreatefromjpeg($strSource);
break;
case 'image/png' :
$objSource = imagecreatefrompng($strSource);
break;
case 'image/webp' :
$objSource = imagecreatefromwebp($strSource);
break;
}
// Mise à jour de l'image 'vide' avec les informations de dimension
//imagecopyresized($objDest, $objSource, 0, 0, 0, 0, 200, 250, $intWidth, $intHeight);
imagecopyresampled($objDest, $objSource,
0, 0, $intCropX, $intCropY,
$intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight);
// Si la copie de l'image a bien été effectuée à la destination voulue
$boolOk = imagewebp($objDest, $strDest);
}
if ($boolOk === true){
//if (move_uploaded_file($_FILES['img']['tmp_name'], $strDest)){
// suppression de l'ancienne image
$strOldFile = $_ENV['IMG_PATH'].$strOldImg;
if (file_exists($strOldFile)){
unlink($strOldFile);
}
if (is_null($objProject->getId())){
$_SESSION['success'] = "Le projet a bien été créé";
}else{
$_SESSION['success'] = "Le projet a bien été modifié";
}
header("Location:index.php");
exit;
}else{
$arrError['imageThumbnail'] = "Erreur dans le traitement de l'image";
}
}else{
$arrError[] = "Erreur lors de l'ajout";
}
}
}
var_dump($_SESSION);
var_dump($objProject);
var_dump($arrError);
// Données pour la vue
$this->_arrData['arrCategory'] = $objCategoryModel->findAllCategory();
$this->_arrData['objProject'] = $objProject; // On passe l'objet à la vue pour pré-remplir les champs
$this->_arrData['arrError'] = $arrError;
$this->_display('addedit_project');
}
public function display() { public function display() {
@ -326,16 +435,4 @@
header("Location: index.php?ctrl=project&action=addedit_project&id=".$intId); header("Location: index.php?ctrl=project&action=addedit_project&id=".$intId);
exit; exit;
} }
public function addedit_project() {
$objCategoryModel = new CategoryModel;
$arrCategory = $objCategoryModel->findAllCategory();
$_SESSION['category']= $_POST['category']??0;
$this->_arrData['arrCategory'] = $arrCategory;
$this->_display('addedit_project');
}
} }

View file

@ -1,69 +0,0 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-06 08:21:14
from 'file:views/home.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'version' => '5.7.0',
'unifunc' => 'content_6985a47abcda40_19846426',
'has_nocache_code' => false,
'file_dependency' =>
array (
'299f75d7692a19207f23bf5795a2721f507c3fc6' =>
array (
0 => 'views/home.tpl',
1 => 1770365364,
2 => 'file',
),
),
'includes' =>
array (
'file:views/_partial/preview.tpl' => 1,
),
))) {
function content_6985a47abcda40_19846426 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'C:\\wamp64\\www\\projetphp\\views';
$_smarty_tpl->getInheritance()->init($_smarty_tpl, false);
?>
<?php
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_3150142016985a47abb6c29_00747518', "content");
?>
<?php }
/* {block "content"} */
class Block_3150142016985a47abb6c29_00747518 extends \Smarty\Runtime\Block
{
public function callBlock(\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'C:\\wamp64\\www\\projetphp\\views';
?>
<section class="container mt-5 p-5 d-flex flex-column align-items-center text-center">
<h1 class="logo">Folliow</h1>
<h2> 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 class="container" aria-label="Articles récents">
<h2 class="visually-hidden">Les 4 derniers articles</h2>
<div class="row mb-2">
<?php
$_from = $_smarty_tpl->getSmarty()->getRuntime('Foreach')->init($_smarty_tpl, $_smarty_tpl->getValue('arrProjectToDisplay'), 'objProject');
$foreach0DoElse = true;
foreach ($_from ?? [] as $_smarty_tpl->getVariable('objProject')->value) {
$foreach0DoElse = false;
?>
<?php $_smarty_tpl->renderSubTemplate("file:views/_partial/preview.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), (int) 0, $_smarty_current_dir);
?>
<?php
}
$_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore($_smarty_tpl, 1);?>
</section>
<?php
}
}
/* {/block "content"} */
}

View file

@ -1,66 +0,0 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-06 08:21:14
from 'file:views/_partial/preview.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'version' => '5.7.0',
'unifunc' => 'content_6985a47ad585d5_25749521',
'has_nocache_code' => false,
'file_dependency' =>
array (
'c724044e55872f26030b02de6dcd14dc34a20b16' =>
array (
0 => 'views/_partial/preview.tpl',
1 => 1770365554,
2 => 'file',
),
),
'includes' =>
array (
),
))) {
function content_6985a47ad585d5_25749521 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'C:\\wamp64\\www\\projetphp\\views\\_partial';
?><article class="col-md-3 mb-4">
<div class="card h-100 shadow-sm article-card">
<div class="ratio ratio-16x9">
<img src=".<?php echo $_smarty_tpl->getValue('objProject')->getThumbnail();?>
"
class="w-100 h-100 object-fit-cover"
alt=""
loading="lazy">
</div>
<div class="d-flex align-items-start gap-3">
<img src=".<?php echo $_smarty_tpl->getValue('objProject')->getUser_image();?>
"
class="rounded-circle flex-shrink-0 mt-2 ml-5"
style="width: 48px; height: 48px; object-fit: cover;"
alt="Photo de profil">
<div class="flex-grow-1 card-body p-3">
<h3 class="h6 mb-1"><?php echo $_smarty_tpl->getValue('objProject')->getTitle();?>
</h3>
<small class="text-body-secondary d-block mb-1">
<time><?php echo $_smarty_tpl->getValue('objProject')->getCreation_date();?>
</time>
<?php echo $_smarty_tpl->getValue('objProject')->getCreatorname();?>
</small>
<a href="?id=<?php echo $_smarty_tpl->getValue('objProject')->getId();?>
"
class="stretched-link small">
Lire la suite
</a>
</div>
</div>
</div>
</article><?php }
}

View file

@ -2,11 +2,11 @@
require_once("mother_entity.php"); require_once("mother_entity.php");
/**
* Classe d'un objet Projet
* @author Laura
*/
/**
* Classe d'un objet Projet
* @author Laura
*/
class Image extends Entity{ class Image extends Entity{
private int $_id; private int $_id;

View file

@ -7,11 +7,11 @@ require_once("mother_entity.php");
class Project extends Entity{ class Project extends Entity{
private int $_id; private ?int $_id = null;
private string $_title; private string $_title = "";
private string $_description; private string $_description = "";
private string $_thumbnail; private string $_thumbnail = "";
private string $_content; private string $_content = "";
private string $_creation_date; private string $_creation_date;
private string $_status; private string $_status;
private int $_user; private int $_user;

View file

@ -182,7 +182,8 @@
$strRq = "UPDATE project $strRq = "UPDATE project
SET project_title = :title, project_description = :description, project_content = :content SET project_title = :title, project_description = :description, project_content = :content
WHERE project_id = :id"; WHERE project_id = :id";
//Requête préparé
$rqPrep = $this->_db->prepare($strRq); $rqPrep = $this->_db->prepare($strRq);
$rqPrep->bindValue(":title", $objProject->getTitle(), PDO::PARAM_STR); $rqPrep->bindValue(":title", $objProject->getTitle(), PDO::PARAM_STR);

View file

@ -3,21 +3,21 @@
{block name="content"} {block name="content"}
<section class="container mt-4"> <section class="container mt-4">
{if isset($smarty.session.user)} {if isset($smarty.session.user)}
<form class="m-2" method="post" enctype="multipart/form-data" onsubmit="return confirm('Êtes-vous certain de vouloir poster votre projet ?')"> <form class="m-2" method="POST" enctype="multipart/form-data" onsubmit="return confirm('Êtes-vous certain de vouloir poster votre projet ?')">
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Titre</label> <label class="form-label">Titre</label>
<input type="text" name="titleProject" class="form-control {if (isset($arrError['title'])) } is-invalid {/if} " value="{$objProject->getTitle()}" required> <input type="text" name="titleProject" class="form-control {if (isset($arrError['title'])) } is-invalid {/if} " value="" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Description (courte)</label> <label class="form-label">Description (courte)</label>
<textarea name="descProject" class="form-control {if (isset($arrError['descProject'])) } is-invalid {/if} " rows="2">{$objProject->getDescription()}</textarea> <textarea name="descProject" class="form-control {if (isset($arrError['descProject'])) } is-invalid {/if} " rows="2"></textarea>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Texte complet du Portfolio</label> <label class="form-label">Texte complet du Portfolio</label>
<textarea name="textProject" class="form-control {if (isset($arrError['content'])) } is-invalid {/if}" rows="5">{$objProject->getContent()}</textarea> <textarea name="textProject" class="form-control {if (isset($arrError['content'])) } is-invalid {/if}" rows="5"></textarea>
</div> </div>
<div class="col-6 mb-3"> <div class="col-6 mb-3">
@ -46,7 +46,6 @@
<div class="mt-4"> <div class="mt-4">
<button type="submit" class="btn btn-primary btn-md" name="sendProject">Envoyer</button> <button type="submit" class="btn btn-primary btn-md" name="sendProject">Envoyer</button>
{* <button type="submit" class="btn btn-outline-warning btn-md" name="toContinue">Sauvegarder en brouillon</button> *}
</div> </div>
</form> </form>
{else} {else}

View file

@ -1,93 +0,0 @@
{extends file="views/layout.tpl"}
{block name="content"}
<body>
<section class="container mt-5 p-5 d-flex flex-column align-items-center">
<div>
<h2>Alimenter votre projet</h2>
<form method="post">
<button type="submit" class="btn btn-primary btn-lg" name="showForm">+</button>
{if isset($smarty.post.toContinue)}
<button type="submit" class="btn btn-warning btn-lg" name="showFormContinue">Reprendre</button>
{/if}
</form>
{* Affichage d'un formulaire en cas d'appuie sur le bouton "+" *}
{if isset($smarty.post.showForm) || isset($smarty.post.showFormContinue)}
{if isset($smarty.session.user)}
<form class="m-2" method="post" enctype="multipart/form-data" onsubmit="return confirm('Êtes-vous certain de vouloir poster votre projet ? (Vous pourrez toujours le modifier plus tard)')">
<div>
<label>Titre</label>
<input type="text" name="titleProject">
</div>
<div>
<label>Description</label>
<input type="text" name="descProject">
</div>
<div>
<label>Texte Portfolio</label>
<input type="text" name="textProject">
</div>
<div class="col-6">
<fieldset>
<legend class="form-label">Type de recherche par catégories</legend>
<div class="col-md-6">
<label for="author" class="form-label">Catégorie</label>
<select class="form-select" id="category" name="category">
<option value="0" {if $intCategory == 0}selected{/if}>Toutes les catégories</option>
{foreach $arrCategory as $arrDetCategory}
<option value="{$arrDetCategory['category_id']}"
{if $intCategory == $arrDetCategory['category_id']}selected{/if}
>
{$arrDetCategory['category_name']}
</option>
{/foreach}
</select>
</div>
</fieldset>
</div>
<div>
<h3>Image thumbnail</h3>
<input name="imageThumbnail" class="form-control" type="file">
</div>
<div>
<h3>Image du projet</h3>
<input name="imageProject" class="form-control" type="file">
</div>
<div class="mt-2">
<button type="submit" class="btn btn-primary btn-md" name="sendProject">Envoyer</button>
<button type="submit" class="btn btn-warning btn-md" name="toContinue">Remettre à plus tard</button>
</div>
</form>
{else}
<div class="border rounded mt-5">
<p class="text-danger p-2">Vous devez vous connecter pour accéder à cette fonctionnalité</p>
</div>
{/if}
{/if}
</div>
<div>
<h3>Description</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div>
<h3>Photos behind the scene</h3>
<div class="row mb-2">
<img>
</div>
</div>
<div>
<h3>Other projects</h3>
<div class="row mb-2">
{foreach $arrProjectToDisplay as $objProject}
{include file="../app/views/partials/preview.tpl"}
{/foreach}
</div>
</div>
</div>
<section>
</body>
{/block}