Début de la fonctionnalité de dépôt de Img dans le projet
This commit is contained in:
parent
4e9b27772b
commit
1df2ed36a5
35 changed files with 2014 additions and 168 deletions
28
models/authorisation_model.php
Normal file
28
models/authorisation_model.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
require_once('mother_model.php');
|
||||
|
||||
|
||||
/**
|
||||
* Traitement des requêtes pour le status de l'utilisateur
|
||||
* @author : Laura
|
||||
*/
|
||||
|
||||
class AuthorisationModel extends Connect{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* fonction de récupération des infos d'authorisation
|
||||
* @return array
|
||||
*/
|
||||
public function findAllAuthorisation():array{
|
||||
|
||||
$strRq = "SELECT *
|
||||
FROM authorisation";
|
||||
|
||||
return $this->_db->query($strRq)->fetchAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
/**
|
||||
* Fonction de récupération des images
|
||||
* @param int $intLimit
|
||||
* @return array
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -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=localhost;dbname=projet_folliow", // Serveur et BDD mysql:host=boulayoune.com;dbname=projet_folliow
|
||||
"root", //Nom d'utilisateur de la base de données projet_user
|
||||
"",// Mot de passe de la base de données F0lliowRules!
|
||||
array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC) // Mode de renvoi
|
||||
);
|
||||
// Pour résoudre les problèmes d’encodage
|
||||
|
|
|
|||
|
|
@ -8,12 +8,17 @@
|
|||
*/
|
||||
|
||||
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
|
||||
|
|
@ -21,6 +26,7 @@
|
|||
INNER JOIN users ON user_id = project_user";
|
||||
|
||||
$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,37 +73,39 @@
|
|||
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction de recherche d'un seul projet
|
||||
* @param int $intId
|
||||
* @return
|
||||
*/
|
||||
public function findOne(int $intId) {
|
||||
$strRq = "SELECT project.*,
|
||||
CONCAT(users.user_firstname, ' ', users.user_name) AS 'project_creatorname',
|
||||
|
|
|
|||
|
|
@ -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,54 @@
|
|||
$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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue