Copie propre du code final de Folliow (projet d'équipe DWWM)

This commit is contained in:
Yasser Boulayoune 2026-03-06 18:00:00 +01:00
commit eed64cfeb6
67 changed files with 17897 additions and 0 deletions

93
models/CategoryModel.php Normal file
View file

@ -0,0 +1,93 @@
<?php
namespace Models;
use \PDO;
/**
* Traitement des requêtes pour les catégories
* @author : Laura
*/
class CategoryModel extends MotherModel{
/**
* Fonction de récupération des catégories
* @param int $intLimit
* @return array
*/
public function findAllCategory(int $intLimit=0):array{
$strRq = "SELECT category.*
FROM category";
if ($intLimit > 0){
$strRq .= " LIMIT :limit";
}
$rqPrep = $this->_db->prepare($strRq);
if ($intLimit > 0){
$rqPrep->bindValue(":limit", $intLimit, PDO::PARAM_INT);
}
$rqPrep->execute();
return $rqPrep->fetchAll();
}
/**
* fonction d'insertion d'une nouvelle 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 insertCategory(object $objCategory):bool{
$strRq = "INSERT INTO category (category_name)
VALUES (:name)";
$rqPrep = $this->_db->prepare($strRq);
$rqPrep->bindValue(":name", $objCategory->getName(), 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();
}
}