Merge branch 'main' into yass
This commit is contained in:
commit
6ae6dff302
64 changed files with 1465 additions and 670 deletions
|
|
@ -23,14 +23,14 @@
|
|||
}
|
||||
|
||||
/**
|
||||
Pour passer sur le serveur de YASS:
|
||||
*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
|
||||
*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
|
||||
*/
|
||||
|
|
@ -16,72 +16,90 @@
|
|||
* @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, bool $bool6Months=false):array{
|
||||
int $intPeriod=0, string $strDate='', string $strStartDate='',
|
||||
string $strEndDate='', int $intCategory=0, bool $boolOlderThan6Months=false): array {
|
||||
|
||||
|
||||
$strRq = "SELECT project.*,
|
||||
user_pseudo AS 'project_creatorname',
|
||||
user_image
|
||||
FROM project
|
||||
INNER JOIN users ON user_id = project_user_id";
|
||||
|
||||
$strWhere = " WHERE ";
|
||||
INNER JOIN users ON user_id = project_user_id
|
||||
WHERE 1=1";
|
||||
|
||||
// Recherche par mot clé avec quote pour éviter bug du '
|
||||
if ($strKeywords != '') {
|
||||
|
||||
$strSafeKeywords = $this->_db->quote("%" . $strKeywords . "%");
|
||||
|
||||
$strRq .= " WHERE (project_title LIKE ".$strSafeKeywords."
|
||||
OR project_content LIKE ".$strSafeKeywords.") ";
|
||||
|
||||
//$boolWhere = true;
|
||||
$strWhere = " AND ";
|
||||
$strRq .= " AND (project_title LIKE :keywords OR project_content LIKE :keywords)";
|
||||
}
|
||||
|
||||
// Recherche par auteur
|
||||
|
||||
if ($intAuthor > 0){
|
||||
$strRq .= $strWhere." user_id = ".$intAuthor;
|
||||
$strWhere = " AND ";
|
||||
$strRq .= " AND project_user_id = :author";
|
||||
}
|
||||
|
||||
// Recherche par catégorie
|
||||
if ($intCategory > 0){
|
||||
$strRq .= $strWhere." project_category = ".$intCategory;
|
||||
$strWhere = " AND ";
|
||||
$strRq .= " AND project_category = :category";
|
||||
}
|
||||
|
||||
//recherche par ancienneté
|
||||
if ($bool6Months === true) {
|
||||
$strRq .= $strWhere . " project_creation_date <= DATE_SUB(NOW(), INTERVAL 6 MONTH) ";
|
||||
$strWhere = " AND ";
|
||||
if ($boolOlderThan6Months === true) {
|
||||
$strRq .= " AND project_creation_date <= DATE_SUB(NOW(), INTERVAL 6 MONTH)";
|
||||
}
|
||||
|
||||
// Recherche par dates
|
||||
|
||||
if ($intPeriod == 0){
|
||||
if ($strDate != ''){
|
||||
$strRq .= $strWhere." project_creation_date = '".$strDate."'";
|
||||
$strRq .= " AND project_creation_date = :date_exacte";
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
if ($strStartDate != '' && $strEndDate != ''){
|
||||
$strRq .= $strWhere." project_creation_date BETWEEN '".$strStartDate."' AND '".$strEndDate."'";
|
||||
}else{
|
||||
$strRq .= " AND project_creation_date BETWEEN :date_debut AND :date_fin";
|
||||
} else {
|
||||
if ($strStartDate != ''){
|
||||
$strRq .= $strWhere." project_creation_date >= '".$strStartDate."'";
|
||||
}else if ($strEndDate != ''){
|
||||
$strRq .= $strWhere." project_creation_date <= '".$strEndDate."'";
|
||||
$strRq .= " AND project_creation_date >= :date_debut";
|
||||
} else if ($strEndDate != ''){
|
||||
$strRq .= " AND project_creation_date <= :date_fin";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$strRq .= " ORDER BY project_creation_date DESC";
|
||||
|
||||
if ($intLimit > 0){
|
||||
$strRq .= " LIMIT ".$intLimit;
|
||||
$strRq .= " LIMIT :limit";
|
||||
}
|
||||
|
||||
return $this->_db->query($strRq)->fetchAll();
|
||||
$rqPrep = $this->_db->prepare($strRq);
|
||||
|
||||
if ($strKeywords != '') {
|
||||
$rqPrep->bindValue(':keywords', '%' . $strKeywords . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if ($intAuthor > 0){
|
||||
$rqPrep->bindValue(':author', $intAuthor, PDO::PARAM_INT);
|
||||
}
|
||||
if ($intCategory > 0){
|
||||
$rqPrep->bindValue(':category', $intCategory, PDO::PARAM_INT);
|
||||
}
|
||||
if ($intPeriod == 0){
|
||||
if ($strDate != ''){
|
||||
$rqPrep->bindValue(':date_exacte', $strDate, PDO::PARAM_STR);
|
||||
}
|
||||
} else {
|
||||
if ($strStartDate != '' && $strEndDate != ''){
|
||||
$rqPrep->bindValue(':date_debut', $strStartDate, PDO::PARAM_STR);
|
||||
$rqPrep->bindValue(':date_fin', $strEndDate, PDO::PARAM_STR);
|
||||
} else {
|
||||
if ($strStartDate != ''){
|
||||
$rqPrep->bindValue(':date_debut', $strStartDate, PDO::PARAM_STR);
|
||||
} else if ($strEndDate != ''){
|
||||
$rqPrep->bindValue(':date_fin', $strEndDate, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($intLimit > 0){
|
||||
$rqPrep->bindValue(':limit', $intLimit, PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
$rqPrep->execute();
|
||||
return $rqPrep->fetchAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fonction d'insertion d'un nouveau projet dans la bdd
|
||||
|
|
@ -103,7 +121,16 @@
|
|||
$rqPrep->bindValue(":project_user_id", $objProject->getUser_id(), PDO::PARAM_STR);
|
||||
$rqPrep->bindValue(":project_category", $objProject->getCategory(), PDO::PARAM_STR);
|
||||
|
||||
return $rqPrep->execute();
|
||||
// On met une variable boolOk pour récupérer l'id du projet
|
||||
$boolOk = $rqPrep->execute();
|
||||
|
||||
// Si boolOk est remplis
|
||||
if ($boolOk) {
|
||||
// On récupère l'ID auto-incrémenté et on l'injecte dans l'objet
|
||||
$objProject->setId($this->_db->lastInsertId());
|
||||
}
|
||||
|
||||
return $boolOk;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -113,7 +140,7 @@
|
|||
*/
|
||||
public function findOne(int $intId) :array{
|
||||
$strRq = "SELECT project.*,
|
||||
CONCAT(users.user_firstname, ' ', users.user_name) AS 'project_creatorname',
|
||||
users.user_pseudo AS 'project_creatorname',
|
||||
users.user_image,
|
||||
category.category_name
|
||||
FROM project
|
||||
|
|
@ -136,12 +163,10 @@
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -200,10 +225,16 @@
|
|||
return $rqPrep->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction de récupération d'image d'un projet en BDD
|
||||
* @author Guillaume
|
||||
* @param int $objProject L'Id du projet choisit
|
||||
* @return array Un tableau avec les informations de la bdd
|
||||
*/
|
||||
public function getImagesByProjectId(int $projectId): array {
|
||||
$strRq = "SELECT image_id, image_name, image_alt
|
||||
$strRq = "SELECT image_id, image_name, image_alt, image_status
|
||||
FROM image
|
||||
WHERE image_project = :id AND image_status = 1";
|
||||
WHERE image_project = :id";
|
||||
|
||||
$rqPrep = $this->_db->prepare($strRq);
|
||||
$rqPrep->bindValue(":id", $projectId, PDO::PARAM_INT);
|
||||
|
|
@ -212,6 +243,56 @@
|
|||
return $rqPrep->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction de récupération d'image d'un projet en BDD
|
||||
* @author Guillaume
|
||||
* @param int $id L'Id de l'image choisit
|
||||
* @return array Un tableau avec les informations de la bdd
|
||||
*/
|
||||
public function deleteImage(int $id): bool {
|
||||
$strRq = "DELETE FROM image WHERE image_id = :id";
|
||||
$rqPrep = $this->_db->prepare($strRq);
|
||||
$rqPrep->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
return $rqPrep->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction de modifications de status de l'image d'un projet en BDD
|
||||
* @author Guillaume
|
||||
* @param int $id L'Id de l'image choisit, string $status le status choisit
|
||||
* @return array Un tableau avec les informations de la bdd
|
||||
*/
|
||||
public function updateImageStatus(int $id, string $status): bool {
|
||||
$strRq = "UPDATE image SET image_status = :status WHERE image_id = :id";
|
||||
$rqPrep = $this->_db->prepare($strRq);
|
||||
$rqPrep->bindValue(':status', $status, PDO::PARAM_STR);
|
||||
$rqPrep->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
return $rqPrep->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction de récupération d'image d'un projet en BDD
|
||||
* @author Guillaume
|
||||
* @param int $id L'Id de l'image choisit
|
||||
* @return array Un tableau avec les informations de la bdd
|
||||
*/
|
||||
public function findImage(int $id): array|bool {
|
||||
$strRq = "SELECT * FROM image WHERE image_id = :id";
|
||||
$rqPrep = $this->_db->prepare($strRq);
|
||||
$rqPrep->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$rqPrep->execute();
|
||||
return $rqPrep->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ajoute une image liée à un projet dans la table 'image'
|
||||
* @author Guillaume
|
||||
* @param string $fileName Nom du fichier image
|
||||
* @param int $projectId ID du projet parent
|
||||
* @param string $alt Texte alternatif
|
||||
* @return bool
|
||||
*/
|
||||
public function addImageInProject(string $fileName, int $projectId, string $alt = "Image projet"): bool {
|
||||
$strRq = "INSERT INTO image (
|
||||
image_name,
|
||||
|
|
@ -225,9 +306,10 @@
|
|||
|
||||
$rqPrep->bindValue(":name", $fileName, PDO::PARAM_STR);
|
||||
$rqPrep->bindValue(":alt", $alt, PDO::PARAM_STR);
|
||||
$rqPrep->bindValue(":status", "en_attente", PDO::PARAM_STR); // Valeur string brute
|
||||
// On met le statut par défaut en "en_attente" pour la modération
|
||||
$rqPrep->bindValue(":status", "en_attente", PDO::PARAM_STR);
|
||||
$rqPrep->bindValue(":project", $projectId, PDO::PARAM_INT);
|
||||
|
||||
return $rqPrep->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue