diff --git a/class/dureefield.php b/class/dureefield.php index 9b3aab6dcdcb2987fb8a18a644e1ea371925d5ca..cad90c0bed0a440119d6995096e67f2e737bd01d 100644 --- a/class/dureefield.php +++ b/class/dureefield.php @@ -14,7 +14,7 @@ class DureeField extends Field public function validate() { $this->value = $_POST[$this->name]; - if (this->value > -1) { + if ($this->value > -1) { return true; } return false; @@ -23,8 +23,10 @@ class DureeField extends Field public function show() { $heures = (int)$this->value / 60; + $heure = intval($heures); $minutes = (int)$this->value % 60; - $html = $heures.'h '.$minutes.'min'; + $minute = intval($minutes); + $html = $heure.'h '.$minute.'min'; return $html; } } diff --git a/class/listview.php b/class/listview.php index ad789616f489bb473f5d76ec2830b32f7d3ebcb8..4c66fea55dbab9bd49b9c946d84927864b2e328d 100644 --- a/class/listview.php +++ b/class/listview.php @@ -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; } diff --git a/class/objet.php b/class/objet.php index 9198e5802fc054344c025edd5f41e63ba8b8cbb1..b5f3f1d9158e3b3c578e9ae742d704e5d412880d 100644 --- a/class/objet.php +++ b/class/objet.php @@ -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); } } diff --git a/class/stats.php b/class/stats.php index 67412dbce41bd57215ef1fcfa29186a0279d64a2..c98edb0c138073c7a1e509d3ec381bb16d525e60 100644 --- a/class/stats.php +++ b/class/stats.php @@ -170,14 +170,15 @@ class Stats { $bdd = new Db(); - $requete_prepare = $bdd->db->prepare(" SELECT r.nom, count(*) + $requete_prepare = $bdd->db->prepare(" SELECT r.nom, count(*) AS count FROM animal a, race r WHERE a.race = r.id GROUP BY r.nom, r.id + ORDER BY count DESC LIMIT 10" ); // on prépare notre requête $requete_prepare->execute(); - $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC); + $ligne = $requete_prepare->fetchAll(PDO::FETCH_ASSOC); return $ligne; } @@ -187,15 +188,16 @@ class Stats $bdd = new Db(); - $requete_prepare = $bdd->db->prepare(" SELECT e.nom, count(*) + $requete_prepare = $bdd->db->prepare(" SELECT e.nom, count(*) AS count FROM animal a, race r, espece e WHERE a.race = r.id AND e.id = r.espece GROUP BY e.nom, e.id + ORDER BY count DESC LIMIT 10" ); // on prépare notre requête $requete_prepare->execute(); - $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC); + $ligne = $requete_prepare->fetchAll(PDO::FETCH_ASSOC); return $ligne; } diff --git a/controller/fact.php b/controller/fact.php index 40a08d46c71baa118a1d18a5b673c86ff3824a5d..06152d7be9afa6cb05396c8bee55ba9298361335 100644 --- a/controller/fact.php +++ b/controller/fact.php @@ -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: diff --git a/view/stats.php b/view/stats.php index 6547cd185ffea12c8d49ad3b489c22e492107314..0582c1ee94eada68cfde7f8273d68b823b89445f 100644 --- a/view/stats.php +++ b/view/stats.php @@ -116,4 +116,40 @@ </tbody> </table> + <br/> + <hr/> + <h4>Top 10 des espèces clientes</h4> + <table class="table"> + <thead> + <th>Nom </th> + <th>Nombre d'individu </th> + </thead> + <tbody> + <?php foreach ($stats->top10Espece() as $ligne): ?> + <tr> + <td><?php echo $ligne["nom"]; ?> </td> + <td><?php echo $ligne["count"]; ?> </td> + </tr> + <?php endforeach; ?> + </tbody> + </table> + + <br/> + <hr/> + <h4>Top 10 des races clientes</h4> + <table class="table"> + <thead> + <th>Nom </th> + <th>Nombre d'individu </th> + </thead> + <tbody> + <?php foreach ($stats->top10Race() as $ligne): ?> + <tr> + <td><?php echo $ligne["nom"]; ?> </td> + <td><?php echo $ligne["count"]; ?> </td> + </tr> + <?php endforeach; ?> + </tbody> + </table> + </div> \ No newline at end of file