Skip to content
Snippets Groups Projects
Commit cfcdc3a3 authored by Matthieu Guffroy's avatar Matthieu Guffroy
Browse files

filter view

parent d1c859b4
No related branches found
No related tags found
No related merge requests found
......@@ -6,10 +6,10 @@ class ListView
protected $objArray;
public $class;
public function __construct($class, $title, $id=null)
public function __construct($class, $title, $arr=Array())
{
$this->title = $title;
$this->objArray = $class::getAll($id);
$this->objArray = $class::getAll($arr);
$this->class = $class;
}
......
......@@ -23,18 +23,22 @@ class Objet
return $dbName;
}
public static function getAll($id = null)
public static function getAll($arr = array())
{
$className = get_called_class();
$dbName = self::dbName();
$bdd = new Db();
$result = Array();
if($id == null) {
if(count($arr) == 0) {
$requete_prepare = $bdd->db->prepare("SELECT * FROM ".$dbName); // on prépare notre requête
$requete_prepare->execute();
} else {
$requete_prepare = $bdd->db->prepare("SELECT * FROM ".$dbName." WHERE id = :id");
$requete_prepare->execute(array("id" => $id));
$req = "SELECT * FROM ".$dbName." WHERE 1=1";
foreach($arr as $k => $a) {
$req .= " AND $k = :$k";
}
$requete_prepare = $bdd->db->prepare($req);
$requete_prepare->execute($arr);
}
while($ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC)) {
......@@ -160,7 +164,7 @@ class Objet
return self::dbName()." #".$this->{$this->_primaryAttr};
}
public function getList($title, $id=null) {
return new ListView(get_called_class(), $title, $id);
public function getList($title, $arr=array()) {
return new ListView(get_called_class(), $title, $arr);
}
}
......@@ -47,7 +47,7 @@ switch($action) {
echo ' <a href="'.$base_url.$page.'/addProduit'.'?factId='.$_GET["id"].'" type="button" class="btn btn-success">Ajouter un Produit</a>';
echo ' <a href="'.$base_url.$page.'/addOrd'.'?factId='.$_GET["id"].'" type="button" class="btn btn-success">Ajouter une Ordonnance</a>';
echo '</div>';
$list = LigneFacture::getList("Détails de la facture", $_GET["id"]);
$list = LigneFacture::getList("Détails de la facture", array("facture" => $_GET["id"]));
include 'view/list.php';
break;
default:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment