diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
new file mode 100644
index 0000000..db60a95
--- /dev/null
+++ b/.github/workflows/deploy.yml
@@ -0,0 +1,36 @@
+name: Deploy production (servyass)
+
+on:
+ push:
+ branches:
+ - main
+
+jobs:
+ deploy:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Deploy via SSH
+ uses: appleboy/ssh-action@master
+ with:
+ host: boulayoune.com
+ username: yass
+ key: ${{ secrets.SSH_KEY }}
+ port: 22
+ script: |
+ set -e
+ echo "➡️ Connexion réussie !"
+ cd /var/www/projet_php
+
+ echo "➡️ Mise à jour du code..."
+ # On enlève le SUDO ici pour que Git utilise la clé de l'utilisateur yass
+ git fetch origin main
+ git reset --hard origin/main
+
+ echo "➡️ Correction des permissions et nettoyage..."
+ # On garde le SUDO ici car ces commandes touchent au système
+ sudo chown -R yass:www-data /var/www/projet_php
+ sudo chmod -R 775 /var/www/projet_php/templates_c
+ sudo rm -rf /var/www/projet_php/templates_c/*
+
+ echo "✅ Déploiement terminé ! (Shin-en no Egotisu)"
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2196147
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/templates_c/
+/templates_c/**
\ No newline at end of file
diff --git a/assests/img/Logo.png b/assests/img/logo.png
similarity index 100%
rename from assests/img/Logo.png
rename to assests/img/logo.png
diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php
index 63e92a1..8e4a509 100644
--- a/controllers/admin_controller.php
+++ b/controllers/admin_controller.php
@@ -8,6 +8,8 @@
require("./entities/image_entity.php");
require("./models/user_model.php");
require("./entities/user_entity.php");
+ require("./models/authorisation_model.php");
+ require("./entities/authorisation_entity.php");
require("mother_controller.php");
/**
@@ -18,33 +20,33 @@
class AdminCtrl extends MotherCtrl{
public function admin(){
- /*accès à la page admin
+
if (!isset($_SESSION['user']) && ($_SESSION['user']['user_status'] != 1 )){
header("Location:index.php?ctrl=error&action=error_403");
exit;
- }*/
+ }
+
+ //gestion de l'user
$objCategoryModel = new CategoryModel;
if (!empty($_POST['new_category'])) {
- $objNewCategory = new Category;
- if (!empty($objNewCategory->getName())) {
- $objNewCategory = $_POST['new_category'];
- $objCategoryModel->insertCategory($objNewCategory);
- header("Location:index.php?ctrl=admin&action=admin");
- exit;
- }
+ $newCat = new Category();
+ $newCat->setName($_POST['new_category']);
+ $objCategoryModel->insertCategory($newCat);
+ header('Location: index.php?ctrl=admin&action=admin');
+ exit;
}
- if (!empty($_POST['edit_category'])) {
- $objEditCategory = new Category;
- if ($objEditCategory->getId() > 0) {
- $objEditCategory = $_POST['edit_category'];
- $objCategoryModel->editCategory($objEditCategory);
- header("Location:index.php?ctrl=admin&action=admin");
- exit;
- }
+ if (!empty($_POST['id_to_edit']) && !empty($_POST['new_name'])) {
+ $editCat = new Category();
+ $editCat->setId($_POST['id_to_edit']);
+ $editCat->setName($_POST['new_name']);
+ $objCategoryModel->editCategory($editCat);
+ header('Location: index.php?ctrl=admin&action=admin');
+ exit;
}
+ //affichage select des catégories
$arrCategory = $objCategoryModel->findAllCategory();
$arrCategoryToDisplay = array();
@@ -53,10 +55,56 @@
$objCategory->hydrate($arrDetCategory);
$arrCategoryToDisplay[] = $objCategory;
}
+
+ //gestion de l'user
+ $objUserModel = new UserModel;
+
+ if (!empty($_POST['action'])) {
+ $intUserId = (int)$_POST['user_id'];
+
+ if ($intUserId > 0) {
+ if ($_POST['action'] === 'update_status' && !empty($_POST['new_status'])) {
+ $objUser = new User();
+ $objUser->setId($intUserId);
+ $objUser->setStatus((int)$_POST['new_status']);
+ if ($objUserModel->editStatus($objUser)) {
+ $_SESSION['message_success'] = "Le statut a bien été modifié !";
+ }
+ }
+ elseif ($_POST['action'] === 'delete_user') {
+ $objUserModel->delete_soft($intUserId);
+ $_SESSION['message_success'] = "L'utilisateur a été supprimé.";
+ }
+ header("Location: index.php?ctrl=admin&action=admin");
+ exit;
+ }
+ }
+
+ //affichage select des users
+ $arrUser = $objUserModel->findAllUsers();
+ $arrUserToDisplay = array();
+
+ foreach($arrUser as $arrDetUser){
+ $objUser = new User;
+ $objUser->hydrate($arrDetUser);
+ $arrUserToDisplay[] = $objUser;
+ }
+
+ //affichage select des authorisations
+ $objAuthorisationModel = new AuthorisationModel;
+ $arrAuthorisation = $objAuthorisationModel->findAllAuthorisation();
+ $arrAuthorisationToDisplay = array();
+
+ foreach($arrAuthorisation as $arrDetAuthorisation){
+ $objAuthorisation = new Authorisation;
+ $objAuthorisation->hydrate($arrDetAuthorisation);
+ $arrAuthorisationToDisplay[] = $objAuthorisation;
+ }
- // Il faudra donner à maman et gérer l'affichage quand Smarty sera prêt
- $this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay;
- //$this->_arrData['intCategory'] = $objCategoryModel->;
+ //gérer l'affichage
+ $this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay;
+ $this->_arrData['arrUserToDisplay'] = $arrUserToDisplay;
+ $this->_arrData['arrAuthorisationToDisplay'] = $arrAuthorisationToDisplay;
$this->_display("admin");
}
}
diff --git a/controllers/project_controller.php b/controllers/project_controller.php
index af2e9fa..47f9372 100644
--- a/controllers/project_controller.php
+++ b/controllers/project_controller.php
@@ -23,9 +23,20 @@
*/
public function home(){
+
+
+ $intCategory = 0;
+ if (!empty($_GET['filter_cat'])) {
+ $intCategory = (int) $_GET['filter_cat'];
+ }
+
+ $boolOld = false;
+ if (!empty($_GET['filter_old']) && $_GET['filter_old'] == 'true') {
+ $boolOld = true;
+ }
$objProjectModel = new ProjectModel;
- $arrProject = $objProjectModel->findAll();
+ $arrProject = $objProjectModel->findAll(0,'',0,0,'','','',$intCategory,$boolOld);
$arrProjectToDisplay = array();
foreach($arrProject as $arrDetProject){
$objProject = new Project;
@@ -34,8 +45,6 @@
}
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
-
-
$this->_display("home");
}
@@ -43,8 +52,8 @@
/**
* Fonction d'affichage de la barre de recherche
*/
-
public function search(){
+
//Récupérer les informations du formulaire
$strKeywords = $_POST['keywords']??'';
$intAuthor = $_POST['author']??0;
@@ -76,6 +85,7 @@
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
$this->_arrData['arrCategory'] = $arrCategory;
+ $this->_arrData['arrProject'] = $arrProject;
$this->_arrData['arrUser'] = $arrUser;
@@ -87,62 +97,62 @@
/**
* Fonction d'affichage de la page projet
*/
-
-
public function project (){
$objProjectModel = new ProjectModel;
$arrProject = $objProjectModel->findAll(4);
- $arrProjectToDiplay = array();
+ $arrProjectToDisplay = array();
foreach($arrProject as $arrDetProject){
$objProject = new Project;
$objProject->hydrate($arrDetProject);
- $arrProjectToDiplay[] = $objProject;
+ $arrProjectToDisplay[] = $objProject;
}
$objImageModel = new ImageModel;
$arrImage = $objImageModel->findAllImage(4);
- $arrImageToDiplay = array();
+ $arrImageToDisplay = array();
foreach($arrImage as $arrDetImage){
$objImage = new Image;
$objImage->hydrate($arrDetImage);
- $arrImageToDiplay[] = $objImage;
+ $arrImageToDisplay[] = $objImage;
}
//Variable data
$_SESSION['title'] = $_POST['titleProject']??"";
$_SESSION['description'] = $_POST['descProject']??"";
$_SESSION['content'] = $_POST['textProject']??"";
- $_SESSION['thumbnail'] = $_FILES['imageProject']['name']??"";
+ $_SESSION['thumbnail'] = $_FILES['imageThumbnail']['name']??"";
$_SESSION['status'] = 'en_attente';
+ $_SESSION['user_id'] = $_SESSION['user']['user_id'];
$objProject = new Project();
/**
- /* Créer par Besnik le GOAT et l'autre GOAT de 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
+ * Créer par Besnik le GOAT et l'autre GOAT de 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 = '../public/uploads/projects/'.$_FILES['imageProject']['name'];
- var_dump($strDest);
+ $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
- */
+ * 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['sendMessage'])) {
$_SESSION['status'] = 'publié';
$objProject->hydrate($_SESSION);
- $objProject->setThumbnail($strDest);
+ $objProject->setThumbnail($strDest);
+ var_dump($strDest);
+ var_dump($objProject);
$objProjectModel->insert($objProject);
} else if (isset($_POST['toContinue'])) {
@@ -151,14 +161,12 @@
$objProjectModel->insert($objProject);
}
- //Débuggage
var_dump($_SESSION);
var_dump($objProject);
- $this->_arrData['arrProjectToDiplay'] = $arrProjectToDiplay;
- $this->_arrData['arrImageToDiplay'] = $arrImageToDiplay;
+ $this->_arrData['arrProjectToDiplay'] = $arrProjectToDisplay;
+ $this->_arrData['arrImageToDiplay'] = $arrImageToDisplay;
$this->_display("project");
-
}
@@ -174,7 +182,7 @@
$objProject->hydrate($arrProject);
$this->_arrData["objProject"] = $objProject;
- $this->_display("projet_display");
+ $this->_display("project_display");
} else {
header("Location: index.php?ctrl=project&action=home");
exit;
@@ -185,8 +193,7 @@
}
}
- public function sendEmail()
- {
+ public function sendEmail(){
if (count($_POST) > 0) {
$projectId = (int)($_POST['project_id'] ?? 0);
@@ -217,6 +224,7 @@
$objMail->SMTPDebug = 0;
+
$objMail->SMTPAuth = TRUE;
$objMail->SMTPSecure = "tls";
$objMail->Port = 587;
@@ -256,4 +264,46 @@
header("Location: index.php?ctrl=project&action=home");
exit;
}
+
+ public function accept(){
+
+ //Récupéré l'id dans l'url
+ $intId = $_GET['id'];
+
+ //Je créer un nouveau model pour exec la commande SQL
+ $objProjectModel = new ProjectModel;
+ $objProjectModel->accept($intId);
+
+ //Redirection vers la page
+ header("Location: index.php");
+ exit;
+ }
+
+ public function refuse(){
+
+ //Récupéré l'id dans l'url
+ $intId = $_GET['id'];
+
+ //Je créer un nouveau model pour exec la commande SQL
+ $objProjectModel = new ProjectModel;
+ $objProjectModel->refuse($intId);
+
+ //Redirection vers la page
+ header("Location: index.php");
+ exit;
+ }
+
+ public function delete(){
+
+ //Récupéré l'id dans l'url
+ $intId = $_GET['id'];
+
+ //Je créer un nouveau model pour exec la commande SQL
+ $objProjectModel = new ProjectModel;
+ $objProjectModel->delete($intId);
+
+ //Redirection vers la page
+ header("Location: index.php");
+ exit;
+ }
}
\ No newline at end of file
diff --git a/controllers/templates_c/299f75d7692a19207f23bf5795a2721f507c3fc6_0.file_home.tpl.php b/controllers/templates_c/299f75d7692a19207f23bf5795a2721f507c3fc6_0.file_home.tpl.php
deleted file mode 100644
index 208dcfd..0000000
--- a/controllers/templates_c/299f75d7692a19207f23bf5795a2721f507c3fc6_0.file_home.tpl.php
+++ /dev/null
@@ -1,69 +0,0 @@
-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);
-?>
-
-getInheritance()->instanceBlock($_smarty_tpl, 'Block_3150142016985a47abb6c29_00747518', "content");
-?>
-
-
-
-
-
Folliow
-
Là où les talents rencontrent leur avenir
-
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.
-_arrData['arrError'] = $arrError;
-
-
-
$this->_display("login");
-
}
@@ -125,7 +123,6 @@ class UserCtrl extends MotherCtrl {
// Si pas d'erreurs => insertion
if (count($arrError) === 0) {
$objUserModel = new UserModel();
- $boolInsert = $objUserModel->insert($objUser);
if ($objUserModel->mailExists($objUser->getMail())) {
@@ -145,9 +142,46 @@ class UserCtrl extends MotherCtrl {
}
// Affichage de la vue inscription
+ $this->_arrData["arrError"] = $arrError;
$this->_display("inscription");
}
+ /**
+ * le controlleur affichage de la page user
+ */
+ public function user(){
+ $intId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
+ if ($intId <= 0) {
+ header("Location: index.php");
+ exit;
+ }
+
+ //affichage info utilisateur
+ $objUserModel = new UserModel;
+ $arrUserData = $objUserModel->findUserById($intId);
+
+ if ($arrUserData === false) {
+ header("Location: index.php");
+ exit;
+ }
+ $objUser = new User;
+ $objUser->hydrate($arrUserData);
+
+ //affichage projet de l'utilisateur
+ $objProjectModel = new ProjectModel;
+ $arrProjects = $objProjectModel->findAll(0,'',$intId);
+
+ $arrProjectToDisplay = array();
+ foreach($arrProjects as $projectData) {
+ $objProject = new Project();
+ $objProject->hydrate($projectData);
+ $arrProjectToDisplay[] = $objProject;
+ }
+
+ $this->_arrData['user'] = $objUser;
+ $this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
+ $this->_display("user");
+ }
}
diff --git a/entities/authorisation_entity.php b/entities/authorisation_entity.php
new file mode 100644
index 0000000..1cb600b
--- /dev/null
+++ b/entities/authorisation_entity.php
@@ -0,0 +1,24 @@
+_prefix = 'authorisation_';
+ }
+
+ public function getId():int{
+ return $this->_id;
+ }
+ public function setId(int $id){
+ $this->_id = $id;
+ }
+
+ public function getName():string{
+ return $this->_name;
+ }
+
+ }
\ No newline at end of file
diff --git a/entities/project_entity.php b/entities/project_entity.php
index ab9047e..cb8548a 100644
--- a/entities/project_entity.php
+++ b/entities/project_entity.php
@@ -157,7 +157,7 @@ class Project extends Entity{
* Récupération de l'utilisateur
* @return int id de l'utilisateur
*/
- public function getUser(){
+ public function getUser_id(){
return $this->_user;
}
@@ -165,7 +165,7 @@ class Project extends Entity{
* Mise à jour de l'utilisateur
* @param int id de l'utilisateur
*/
- public function setUser($user){
+ public function setUser_id($user){
$this->_user = $user;
}
@@ -200,6 +200,7 @@ class Project extends Entity{
public function setCreatorName($creatorname){
$this->_creatorname = $creatorname;
}
+
/**
* Récupération du chemin photo profil
* @return string nom du chemin photo profil
diff --git a/models/authorisation_model.php b/models/authorisation_model.php
new file mode 100644
index 0000000..010660b
--- /dev/null
+++ b/models/authorisation_model.php
@@ -0,0 +1,28 @@
+_db->query($strRq)->fetchAll();
+ }
+
+ }
\ No newline at end of file
diff --git a/models/category_model.php b/models/category_model.php
index 6432a9a..6c48379 100644
--- a/models/category_model.php
+++ b/models/category_model.php
@@ -10,6 +10,7 @@
/**
* Fonction de récupération des catégories
+ * @param int $intLimit
* @return array
*/
@@ -27,21 +28,56 @@
/**
* fonction d'insertion d'une nouvelle catégorie dans la bdd
- * @param object $objUser L'objet utilisateur
- * @return bool Est-ce que la requête s'est bien passée (true/false)
+ * @param object $objCategory l'objet catégorie
+ * @return bool Est-ce que la requête s'est bien passée
*/
+ public function insertCategory(object $objCategory):bool{
- public function insert(object $objCategory):bool{
-
- $strRq = "INSERT INTO category (category_name, category_parent)
- VALUES (:name, :parent)";
+ $strRq = "INSERT INTO category (category_name)
+ VALUES (:name)";
$rqPrep = $this->_db->prepare($strRq);
$rqPrep->bindValue(":name", $objCategory->getName(), PDO::PARAM_STR);
- $rqPrep->bindValue(":parent", $objCategory->getParent(), PDO::PARAM_STR);
return $rqPrep->execute();
}
- }
\ No newline at end of file
+
+ /**
+ * fonction de suppression d'une catégorie dans la bdd
+ * @param object $objCategory l'objet catégorie
+ * @return bool Est-ce que la requête s'est bien passée
+ */
+ public function deleteCategory(object $objCategory):bool{
+
+ $strRq = "DELETE FROM category
+ WHERE category_id= :id";
+
+ $rqPrep = $this->_db->prepare($strRq);
+
+ $rqPrep->bindValue(":id", $objCategory->getId(), PDO::PARAM_INT);
+
+ return $rqPrep->execute();
+ }
+
+ /**
+ * fonction de modification d'une catégorie dans la bdd
+ * @param object $objCategory l'objet catégorie
+ * @return bool Est-ce que la requête s'est bien passée
+ */
+ public function editCategory(object $objCategory):bool{
+
+ $strRq = "UPDATE category
+ SET category_name = :name
+ WHERE category_id = :id";
+
+ $rqPrep = $this->_db->prepare($strRq);
+
+ $rqPrep->bindValue(":id", $objCategory->getId(), PDO::PARAM_INT);
+ $rqPrep->bindValue(":name", $objCategory->getName(), PDO::PARAM_STR);
+
+ return $rqPrep->execute();
+ }
+ }
+
\ No newline at end of file
diff --git a/models/image_model.php b/models/image_model.php
index 2511f06..39e8158 100644
--- a/models/image_model.php
+++ b/models/image_model.php
@@ -11,6 +11,7 @@
/**
* Fonction de récupération des images
+ * @param int $intLimit
* @return array
*/
diff --git a/models/mother_model.php b/models/mother_model.php
index c259719..59eea4f 100644
--- a/models/mother_model.php
+++ b/models/mother_model.php
@@ -7,9 +7,9 @@
try{
// Connexion à la base de données
$this->_db = new PDO(
- "mysql:host=boulayoune.com;dbname=projet_folliow", // Serveur et BDD
- "projet_user", //Nom d'utilisateur de la base de données
- "F0lliowRules!",// Mot de passe de la base de données
+ "mysql:host=boulayoune.com;dbname=projet_folliow", // Serveur et BDD "mysql:host=localhost;dbname=projet_folliow",
+ "projet_user", //Nom d'utilisateur de la base de données root
+ "F0lliowRules!",// Mot de passe de la base de données
array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC) // Mode de renvoi
);
// Pour résoudre les problèmes d’encodage
@@ -20,4 +20,17 @@
echo "Échec : " . $e->getMessage();
}
}
- }
\ No newline at end of file
+ }
+
+ /**
+ Pour passer sur le serveur de YASS:
+ *"mysql:host=boulayoune.com;dbname=projet_folliow", // Serveur et BDD
+ "projet_user", //Nom d'utilisateur de la base de données
+ "F0lliowRules!",// Mot de passe de la base de données
+ Site pour BDD: https://phpmyadmin.boulayoune.com/index.php?route=/sql&pos=0&db=projet_folliow&table=project
+
+ Pour passer en local:
+ "mysql:host=localhost;dbname=projet_folliow", // Serveur et BDD
+ "root", //Nom d'utilisateur de la base de données
+ "",// Mot de passe de la base de données
+ */
\ No newline at end of file
diff --git a/models/project_model.php b/models/project_model.php
index d88e02d..9ca240f 100644
--- a/models/project_model.php
+++ b/models/project_model.php
@@ -8,19 +8,25 @@
*/
class ProjectModel extends Connect{
-
+
+
+ /**
+ * Fonction de recherche des projets
+ * @param type string, int et bool
+ * @return array
+ */
public function findAll(int $intLimit=0, string $strKeywords='', int $intAuthor=0,
int $intPeriod=0, string $strDate='', string $strStartDate='',
- string $strEndDate='', int $intCategory=0):array{
+ string $strEndDate='', int $intCategory=0, bool $bool6Months=false):array{
- // Ecrire la requête
$strRq = "SELECT project.*,
CONCAT(user_firstname, ' ', user_name) AS 'project_creatorname',
user_image
FROM project
- INNER JOIN users ON user_id = project_user";
+ INNER JOIN users ON user_id = project_user_id";
$strWhere = " WHERE ";
+
// Recherche par mot clé
if ($strKeywords != '') {
$strRq .= " WHERE (project_title LIKE '%".$strKeywords."%'
@@ -41,23 +47,25 @@
$strRq .= $strWhere." project_category = ".$intCategory;
$strWhere = " AND ";
}
+
+ //recherche par ancienneté
+ if ($bool6Months === true) {
+ $strRq .= $strWhere . " project_creation_date <= DATE_SUB(NOW(), INTERVAL 6 MONTH) ";
+ $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 != ''){
$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."'";
}
}
@@ -65,44 +73,46 @@
$strRq .= " ORDER BY project_creation_date DESC";
-
if ($intLimit > 0){
$strRq .= " LIMIT ".$intLimit;
}
- // Lancer la requête et récupérer les résultats
return $this->_db->query($strRq)->fetchAll();
}
- //Fonction d'insertion d'information dans la BDD (Repris de la partie BLOG vu en cours..)
+ /**
+ * Fonction d'insertion d'un nouveau projet dans la bdd
+ * @param object $objProject l'objet projet
+ * @return bool Est-ce que la requête s'est bien passée
+ */
public function insert(object $objProject):bool{
- //Construire la requête
$strRq = "INSERT INTO project (project_title, project_description, project_thumbnail, project_content, project_status, project_creation_date)
VALUES (:title, :description, :thumbnail, :content, :status, DATE(NOW()))";
- // Préparer la requête
$rqPrep = $this->_db->prepare($strRq);
- // Donne les informations
+
$rqPrep->bindValue(":title", $objProject->getTitle(), PDO::PARAM_STR);
$rqPrep->bindValue(":description", $objProject->getDescription(), PDO::PARAM_STR);
$rqPrep->bindValue(":thumbnail", $objProject->getThumbnail(), PDO::PARAM_STR);
$rqPrep->bindValue(":content", $objProject->getContent(), PDO::PARAM_STR);
$rqPrep->bindValue(":status", $objProject->getStatus(), PDO::PARAM_STR);
- //Executer la requête
- //var_dump($strRq);die;
- //return $db->exec($strRq);
return $rqPrep->execute();
}
- public function findOne(int $intId) {
+ /**
+ * Fonction de recherche d'un seul projet
+ * @param int $intId
+ * @return array
+ */
+ public function findOne(int $intId) :array{
$strRq = "SELECT project.*,
CONCAT(users.user_firstname, ' ', users.user_name) AS 'project_creatorname',
users.user_image,
category.category_name
FROM project
- INNER JOIN users ON users.user_id = project.project_user
+ INNER JOIN users ON users.user_id = project.project_user_id
LEFT JOIN category ON category.category_id = project.project_category
WHERE project.project_id = :id";
@@ -112,4 +122,54 @@
return $rqPrep->fetch();
}
+
+ public function accept(int $id){
+
+ //SQL pour changer le status en accept
+ $strRq = "UPDATE project
+ SET project_status= 'publié'
+ WHERE project_id =".$id;
+
+ //retourne la commande
+ return $this->_db->query($strRq);
+ }
+
+ public function refuse(int $id){
+
+ $strRq = "UPDATE project
+ SET project_status= 'refusé'
+ WHERE project_id =".$id;
+
+ return $this->_db->query($strRq);
+ }
+
+ public function delete(int $id){
+
+ $strRq = "DELETE FROM project
+ WHERE project_id =".$id;
+
+ return $this->_db->query($strRq);
+ }
+
+ /**
+ * Fonction de mise à jour d'un projet en BDD
+ * @param object $objProject L'objet utilisateur
+ * @return bool Est-ce que la requête s'est bien passée
+ */
+ public function updateProject(object $objProject):bool{
+
+ $strRq = "UPDATE project
+ SET project_title = :title, project_description = :description, project_content = :content
+ WHERE project_id = :id";
+
+ $rqPrep = $this->_db->prepare($strRq);
+
+ $rqPrep->bindValue(":title", $objProject->getTitle(), PDO::PARAM_STR);
+ $rqPrep->bindValue(":description", $objProject->getDescription(), PDO::PARAM_STR);
+ $rqPrep->bindValue(":content", $objProject->getContent(), PDO::PARAM_STR);
+
+
+ // Executer la requête
+ return $rqPrep->execute();
+ }
}
\ No newline at end of file
diff --git a/models/user_model.php b/models/user_model.php
index 72f1ada..baa46dd 100644
--- a/models/user_model.php
+++ b/models/user_model.php
@@ -5,66 +5,58 @@
/**
* Traitement des requêtes pour les utilisateurs
* @author : meilleurGroup
- * @version : V0.5
*/
+
class UserModel extends Connect{
- // Attributs
-
-
- // Méthodes
+
public function __construct(){
parent::__construct();
}
/**
+ * Fonction de recherche des utilisateurs et leur niveau d'autorisation
* @return array
*/
public function findAllUsers():array{
- // Ecrire la requête
$strRq = "SELECT user_id, user_firstname, user_name, user_image, user_status, authorisation_name
- FROM users INNER JOIN authorisation ON authorisation.authorisation_id = users.user_status";
- // Lancer la requête et récupérer les résultats
+ FROM users INNER JOIN authorisation ON authorisation.authorisation_id = users.user_status
+ WHERE user_deleted_at IS NULL";
return $this->_db->query($strRq)->fetchAll();
}
/**
+ * Fonction de vérification des utilisateurs
* @param string $strMail
* @param string $strPwd
* @return array|bool
*/
public function verifUser(string $strMail, string $strPwd):array|bool{
- // 2. Construire la requête
+
$strRq = "SELECT user_id, user_name, user_firstname, user_password, user_image, user_status, authorisation_name
FROM users INNER JOIN authorisation ON authorisation.authorisation_id = users.user_status
WHERE user_mail = '".$strMail."'";
- // Récupère mon utilisateur
- // Executer la requête et récupérer les résultats
+
$arrUser = $this->_db->query($strRq)->fetch();
- // Vérification du mot de passe haché
if (password_verify($strPwd, $arrUser['user_password'])){
- // Renvoi l'utilisateur
- unset($arrUser['user_password']); // on enlève le pwd
+ unset($arrUser['user_password']);
return $arrUser;
}else{
return false;
}
}
- //public function insert(string $strName, string $strFirstname, string $strMail, string $strPwd):int{
/**
* Fonction d'insertion d'un utilisateur en BDD
* @param object $objUser L'objet utilisateur
- * @return bool Est-ce que la requête s'est bien passée (true/false)
+ * @return bool Est-ce que la requête s'est bien passée
*/
public function insert(object $objUser):bool{
-
- // 2. Construire la requête
$strRq = "INSERT INTO users (user_name, user_firstname, user_pseudo, user_mail, user_password, user_phone, user_work, user_location, user_description)
VALUES (:name, :firstname, :pseudo,:mail, :pwd, :phone, :work, :location,:description)";
- // Préparer la requête
+
$rqPrep = $this->_db->prepare($strRq);
- // Donne les informations
+
$rqPrep->bindValue(":name", $objUser->getName(), PDO::PARAM_STR);
$rqPrep->bindValue(":firstname", $objUser->getFirstname(), PDO::PARAM_STR);
$rqPrep->bindValue(":pseudo", $objUser->getPseudo(), PDO::PARAM_STR);
@@ -75,19 +67,70 @@
$rqPrep->bindValue(':location', $objUser->getLocation() ?? "", PDO::PARAM_STR);
$rqPrep->bindValue(':description', $objUser->getDescription() ?? "", PDO::PARAM_STR);
-
-
- // 3. Executer la requête
- //var_dump($strRq);die;
- //return $db->exec($strRq);
return $rqPrep->execute();
}
- public function mailExists(string $mail): bool
- {
+
+ /**
+ * Fonction de vérification de mail
+ * @param string $mail
+ * @return bool Est-ce que la requête s'est bien passée
+ */
+ public function mailExists(string $mail): bool{
+
$rq = $this->_db->prepare("SELECT 1 FROM users WHERE user_mail = :mail LIMIT 1");
$rq->bindValue(":mail", $mail);
$rq->execute();
return (bool)$rq->fetchColumn();
}
+
+ /**
+ * Fonction de changement de status d'un utilisateur
+ * @param object $objUser L'objet utilisateur
+ * @return bool Est-ce que la requête s'est bien passée
+ */
+
+ public function editStatus(object $objUser):bool{
+
+ $strRq = "UPDATE users
+ SET user_status = :status
+ WHERE user_id = :id";
+
+ $rqPrep = $this->_db->prepare($strRq);
+ $rqPrep->bindValue(":id", $objUser->getId(), PDO::PARAM_INT);
+ $rqPrep->bindValue(":status", $objUser->getStatus(), PDO::PARAM_INT);
+ return $rqPrep->execute();
+ }
+
+ /**
+ * Fonction permettant de supprimer un utilisateur avec une date de suppression
+ * @param int $intId L'identifiant de l'utilisateur
+ * @return bool Est-ce que la requête s'est bien passée
+ */
+ public function delete_soft(int $intId):bool{
+
+ $strRq = "UPDATE users
+ SET user_deleted_at = NOW()
+ WHERE user_id = :id";
+
+ $rqPrep = $this->_db->prepare($strRq);
+ $rqPrep->bindValue(":id", $intId, PDO::PARAM_INT);
+ return $rqPrep->execute();
+ }
+
+ /**
+ * Récupère les informations d'un utilisateur par son ID
+ * @param int $intId L'identifiant de l'utilisateur
+ * @return array Tableau associatif (ou false si pas trouvé)
+ */
+ public function findUserById(int $intId): array|bool {
+
+ $strRq = "SELECT * FROM users WHERE user_id = :id";
+
+ $prep = $this->_db->prepare($strRq);
+ $prep->bindValue(':id', $intId, PDO::PARAM_INT);
+ $prep->execute();
+
+ return $prep->fetch();
+ }
}
diff --git a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php
index 76d88b5..ed1df75 100644
--- a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php
+++ b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php
@@ -1,18 +1,18 @@
getCompiled()->isFresh($_smarty_tpl, array (
'version' => '5.7.0',
- 'unifunc' => 'content_6989b403135214_06797903',
+ 'unifunc' => 'content_698ce8475ca6c5_70769879',
'has_nocache_code' => false,
'file_dependency' =>
array (
'0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68' =>
array (
0 => 'views/home.tpl',
- 1 => 1770579251,
+ 1 => 1770721453,
2 => 'file',
),
),
@@ -21,20 +21,20 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'file:views/_partial/preview.tpl' => 1,
),
))) {
-function content_6989b403135214_06797903 (\Smarty\Template $_smarty_tpl) {
+function content_698ce8475ca6c5_70769879 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'D:\\projetphp\\views';
$_smarty_tpl->getInheritance()->init($_smarty_tpl, true);
?>
getInheritance()->instanceBlock($_smarty_tpl, 'Block_8519413186989b403131000_39935260', "content");
+$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_1240817329698ce8475c5f82_37934128', "content");
?>
getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir);
}
/* {block "content"} */
-class Block_8519413186989b403131000_39935260 extends \Smarty\Runtime\Block
+class Block_1240817329698ce8475c5f82_37934128 extends \Smarty\Runtime\Block
{
public function callBlock(\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'D:\\projetphp\\views';
@@ -48,6 +48,19 @@ $_smarty_current_dir = 'D:\\projetphp\\views';
directement en contact avec les entreprises.
+
+