modif recherche requete préparée et ajout confirmation suppression projet
This commit is contained in:
parent
e627063ad8
commit
c62302dc37
5 changed files with 72 additions and 53 deletions
|
|
@ -17,7 +17,7 @@ class Project extends Entity{
|
||||||
private int $_user;
|
private int $_user;
|
||||||
private int $_category;
|
private int $_category;
|
||||||
private string $_creatorname;
|
private string $_creatorname;
|
||||||
private string $_user_image;
|
private ?string $_user_image;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
6
env
6
env
|
|
@ -4,4 +4,8 @@ DB_CONNECTION=mysql
|
||||||
DB_HOSTNAME=boulayoune.com
|
DB_HOSTNAME=boulayoune.com
|
||||||
DB_DATABASE=projet_folliow
|
DB_DATABASE=projet_folliow
|
||||||
DB_USERNAME=
|
DB_USERNAME=
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
|
|
||||||
|
# image path
|
||||||
|
IMG_PROJECT_PATH = uploads/projects/
|
||||||
|
IMG_USER_PATH = uploads/profiles/
|
||||||
|
|
@ -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
|
*"mysql:host=boulayoune.com;dbname=projet_folliow", // Serveur et BDD
|
||||||
"projet_user", //Nom d'utilisateur de la base de données
|
*"projet_user", //Nom d'utilisateur de la base de données
|
||||||
"F0lliowRules!",// Mot de passe 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
|
*Site pour BDD: https://phpmyadmin.boulayoune.com/index.php?route=/sql&pos=0&db=projet_folliow&table=project
|
||||||
|
|
||||||
Pour passer en local:
|
*Pour passer en local:
|
||||||
"mysql:host=localhost;dbname=projet_folliow", // Serveur et BDD
|
*"mysql:host=localhost;dbname=projet_folliow", // Serveur et BDD
|
||||||
"root", //Nom d'utilisateur de la base de données
|
*"root", //Nom d'utilisateur de la base de données
|
||||||
"",// Mot de passe de la base de données
|
*"",// Mot de passe de la base de données
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,72 +16,90 @@
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function findAll(int $intLimit=0, string $strKeywords='', int $intAuthor=0,
|
public function findAll(int $intLimit=0, string $strKeywords='', int $intAuthor=0,
|
||||||
int $intPeriod=0, string $strDate='', string $strStartDate='',
|
int $intPeriod=0, string $strDate='', string $strStartDate='',
|
||||||
string $strEndDate='', int $intCategory=0, bool $bool6Months=false):array{
|
string $strEndDate='', int $intCategory=0, bool $boolOlderThan6Months=false): array {
|
||||||
|
|
||||||
|
|
||||||
$strRq = "SELECT project.*,
|
$strRq = "SELECT project.*,
|
||||||
CONCAT(user_firstname, ' ', user_name) AS 'project_creatorname',
|
CONCAT(user_firstname, ' ', user_name) AS 'project_creatorname',
|
||||||
user_image
|
user_image
|
||||||
FROM project
|
FROM project
|
||||||
INNER JOIN users ON user_id = project_user_id";
|
INNER JOIN users ON user_id = project_user_id
|
||||||
|
WHERE 1=1";
|
||||||
$strWhere = " WHERE ";
|
|
||||||
|
|
||||||
// Recherche par mot clé avec quote pour éviter bug du '
|
|
||||||
if ($strKeywords != '') {
|
if ($strKeywords != '') {
|
||||||
|
$strRq .= " AND (project_title LIKE :keywords OR project_content LIKE :keywords)";
|
||||||
$strSafeKeywords = $this->_db->quote("%" . $strKeywords . "%");
|
|
||||||
|
|
||||||
$strRq .= " WHERE (project_title LIKE ".$strSafeKeywords."
|
|
||||||
OR project_content LIKE ".$strSafeKeywords.") ";
|
|
||||||
|
|
||||||
//$boolWhere = true;
|
|
||||||
$strWhere = " AND ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recherche par auteur
|
|
||||||
if ($intAuthor > 0){
|
if ($intAuthor > 0){
|
||||||
$strRq .= $strWhere." user_id = ".$intAuthor;
|
$strRq .= " AND project_user_id = :author";
|
||||||
$strWhere = " AND ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recherche par catégorie
|
|
||||||
if ($intCategory > 0){
|
if ($intCategory > 0){
|
||||||
$strRq .= $strWhere." project_category = ".$intCategory;
|
$strRq .= " AND project_category = :category";
|
||||||
$strWhere = " AND ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//recherche par ancienneté
|
if ($boolOlderThan6Months === true) {
|
||||||
if ($bool6Months === true) {
|
$strRq .= " AND project_creation_date <= DATE_SUB(NOW(), INTERVAL 6 MONTH)";
|
||||||
$strRq .= $strWhere . " project_creation_date <= DATE_SUB(NOW(), INTERVAL 6 MONTH) ";
|
|
||||||
$strWhere = " AND ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recherche par dates
|
|
||||||
if ($intPeriod == 0){
|
if ($intPeriod == 0){
|
||||||
if ($strDate != ''){
|
if ($strDate != ''){
|
||||||
$strRq .= $strWhere." project_creation_date = '".$strDate."'";
|
$strRq .= " AND project_creation_date = :date_exacte";
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if ($strStartDate != '' && $strEndDate != ''){
|
if ($strStartDate != '' && $strEndDate != ''){
|
||||||
$strRq .= $strWhere." project_creation_date BETWEEN '".$strStartDate."' AND '".$strEndDate."'";
|
$strRq .= " AND project_creation_date BETWEEN :date_debut AND :date_fin";
|
||||||
}else{
|
} else {
|
||||||
if ($strStartDate != ''){
|
if ($strStartDate != ''){
|
||||||
$strRq .= $strWhere." project_creation_date >= '".$strStartDate."'";
|
$strRq .= " AND project_creation_date >= :date_debut";
|
||||||
}else if ($strEndDate != ''){
|
} else if ($strEndDate != ''){
|
||||||
$strRq .= $strWhere." project_creation_date <= '".$strEndDate."'";
|
$strRq .= " AND project_creation_date <= :date_fin";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$strRq .= " ORDER BY project_creation_date DESC";
|
$strRq .= " ORDER BY project_creation_date DESC";
|
||||||
|
|
||||||
if ($intLimit > 0){
|
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
|
* Fonction d'insertion d'un nouveau projet dans la bdd
|
||||||
|
|
@ -128,12 +146,10 @@
|
||||||
|
|
||||||
public function accept(int $id){
|
public function accept(int $id){
|
||||||
|
|
||||||
//SQL pour changer le status en accept
|
|
||||||
$strRq = "UPDATE project
|
$strRq = "UPDATE project
|
||||||
SET project_status= 'publié'
|
SET project_status= 'publié'
|
||||||
WHERE project_id =".$id;
|
WHERE project_id =".$id;
|
||||||
|
|
||||||
//retourne la commande
|
|
||||||
return $this->_db->query($strRq);
|
return $this->_db->query($strRq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,8 +187,6 @@
|
||||||
$rqPrep->bindValue(":description", $objProject->getDescription(), PDO::PARAM_STR);
|
$rqPrep->bindValue(":description", $objProject->getDescription(), PDO::PARAM_STR);
|
||||||
$rqPrep->bindValue(":content", $objProject->getContent(), PDO::PARAM_STR);
|
$rqPrep->bindValue(":content", $objProject->getContent(), PDO::PARAM_STR);
|
||||||
|
|
||||||
|
|
||||||
// Executer la requête
|
|
||||||
return $rqPrep->execute();
|
return $rqPrep->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +61,8 @@
|
||||||
<div class="border rounded text-center">
|
<div class="border rounded text-center">
|
||||||
<a class="btn btn-sm m-1 btn-success" href="?ctrl=project&action=accept&id={$objProject->getId()}" name="toPublished">Accepter</a>
|
<a class="btn btn-sm m-1 btn-success" href="?ctrl=project&action=accept&id={$objProject->getId()}" name="toPublished">Accepter</a>
|
||||||
<a class="btn btn-sm m-1 btn-warning" href="?ctrl=project&action=refuse&id={$objProject->getId()}" name="toRefused">Refuser</a>
|
<a class="btn btn-sm m-1 btn-warning" href="?ctrl=project&action=refuse&id={$objProject->getId()}" name="toRefused">Refuser</a>
|
||||||
<a class="btn btn-sm m-1 btn-danger" href="?ctrl=project&action=delete&id={$objProject->getId()}" name="toDelete">Supprimer</a>
|
<a class="btn btn-sm m-1 btn-danger" href="?ctrl=project&action=delete&id={$objProject->getId()}" name="toDelete" onclick="return confirm('Attention ! Êtes-vous sûr de vouloir supprimer ce projet ? Cette action est irréversible.');">
|
||||||
|
Supprimer l'utilisateur>Supprimer</a>
|
||||||
</div>
|
</div>
|
||||||
{elseif $projectStatus eq "refusé"}
|
{elseif $projectStatus eq "refusé"}
|
||||||
<p class="text-danger fw-bold">Portfolio refusé</p>
|
<p class="text-danger fw-bold">Portfolio refusé</p>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue