Début du soft-delete côté projet
This commit is contained in:
parent
a53dffb0fd
commit
80dcaee91c
18 changed files with 610 additions and 64 deletions
|
|
@ -24,80 +24,62 @@
|
|||
user_pseudo AS 'project_creatorname',
|
||||
user_image
|
||||
FROM project
|
||||
INNER JOIN users ON user_id = project_user_id
|
||||
WHERE 1=1";
|
||||
INNER JOIN users ON user_id = project_user_id";
|
||||
|
||||
$strRq .= " WHERE project_deleted_at IS NULL";
|
||||
|
||||
$strAnd = " AND ";
|
||||
|
||||
// Recherche par mot clé avec quote pour éviter bug du '
|
||||
if ($strKeywords != '') {
|
||||
$strRq .= " AND (project_title LIKE :keywords OR project_content LIKE :keywords)";
|
||||
}
|
||||
|
||||
$strSafeKeywords = $this->_db->quote("%" . $strKeywords . "%");
|
||||
|
||||
$strRq .= $strAnd. " (project_title LIKE ".$strSafeKeywords."
|
||||
OR project_content LIKE ".$strSafeKeywords.") ";
|
||||
|
||||
}
|
||||
|
||||
// Recherche par auteur
|
||||
if ($intAuthor > 0){
|
||||
$strRq .= " AND project_user_id = :author";
|
||||
$strRq .= $strAnd." user_id = ".$intAuthor;
|
||||
|
||||
}
|
||||
|
||||
// Recherche par catégorie
|
||||
if ($intCategory > 0){
|
||||
$strRq .= " AND project_category = :category";
|
||||
$strRq .= $strAnd." project_category = ".$intCategory;
|
||||
}
|
||||
|
||||
//recherche par ancienneté
|
||||
if ($boolOlderThan6Months === true) {
|
||||
$strRq .= " AND project_creation_date <= DATE_SUB(NOW(), INTERVAL 6 MONTH)";
|
||||
$strRq .= $strAnd . " project_creation_date <= DATE_SUB(NOW(), INTERVAL 6 MONTH) ";
|
||||
}
|
||||
|
||||
|
||||
// Recherche par dates
|
||||
if ($intPeriod == 0){
|
||||
if ($strDate != ''){
|
||||
$strRq .= " AND project_creation_date = :date_exacte";
|
||||
$strRq .= $strAnd." project_creation_date = '".$strDate."'";
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
if ($strStartDate != '' && $strEndDate != ''){
|
||||
$strRq .= " AND project_creation_date BETWEEN :date_debut AND :date_fin";
|
||||
} else {
|
||||
$strRq .= $strAnd." project_creation_date BETWEEN '".$strStartDate."' AND '".$strEndDate."'";
|
||||
}else{
|
||||
if ($strStartDate != ''){
|
||||
$strRq .= " AND project_creation_date >= :date_debut";
|
||||
} else if ($strEndDate != ''){
|
||||
$strRq .= " AND project_creation_date <= :date_fin";
|
||||
$strRq .= $strAnd." project_creation_date >= '".$strStartDate."'";
|
||||
}else if ($strEndDate != ''){
|
||||
$strRq .= $strAnd." project_creation_date <= '".$strEndDate."'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$strRq .= " ORDER BY project_creation_date DESC";
|
||||
|
||||
if ($intLimit > 0){
|
||||
$strRq .= " LIMIT :limit";
|
||||
$strRq .= " LIMIT ".$intLimit;
|
||||
}
|
||||
|
||||
$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();
|
||||
return $this->_db->query($strRq)->fetchAll();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -146,7 +128,8 @@
|
|||
FROM project
|
||||
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";
|
||||
WHERE project.project_id = :id
|
||||
AND project.project_deleted_at IS NULL";
|
||||
|
||||
$rqPrep = $this->_db->prepare($strRq);
|
||||
$rqPrep->bindValue(":id", $intId, PDO::PARAM_INT);
|
||||
|
|
@ -191,12 +174,15 @@
|
|||
* @param int $id l'id du projet
|
||||
* @return bool Est-ce que la requête s'est bien passée
|
||||
*/
|
||||
public function delete(int $id){
|
||||
public function delete_soft_project(int $intId): bool {
|
||||
$strRq = "UPDATE project
|
||||
SET project_deleted_at = NOW()
|
||||
WHERE project_id = :id";
|
||||
|
||||
$rqPrep = $this->_db->prepare($strRq);
|
||||
$rqPrep->bindValue(":id", $intId, PDO::PARAM_INT);
|
||||
|
||||
$strRq = "DELETE FROM project
|
||||
WHERE project_id =".$id;
|
||||
|
||||
return $this->_db->query($strRq);
|
||||
return $rqPrep->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -312,4 +298,5 @@
|
|||
|
||||
return $rqPrep->execute();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue