Advertisement
Guest User

Untitled

a guest
Sep 28th, 2010
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.21 KB | None | 0 0
  1. <?php
  2.     /**
  3.      * Classe ClientManager
  4.      * @author Anycee Martin
  5.      * @version 1.0
  6.      */
  7.     class ClientManager
  8.     {
  9.         private $db; // Instance de PDO
  10.        
  11.         public function __construct()
  12.         {
  13.             $this->db = db::getInstance();
  14.         }
  15.        
  16.         public function add(Client $client)
  17.         {
  18.             $q = $this->db->prepare('INSERT INTO client SET id_ville = :id_ville, etat_adhesion = :etat_adhesion, nom_client = :nom_client, prenom = :prenom, adresse_client = :adresse_client, tel = :tel');
  19.            
  20.             $q->bindValue(':id_ville', $client->__get('id_ville'));
  21.             $q->bindValue(':etat_adhesion', $client->__get('etat_adhesion'));
  22.             $q->bindValue(':nom_client', $client->__get('nom_client'));
  23.             $q->bindValue(':prenom', $client->__get('prenom'));
  24.             $q->bindValue(':adresse_client', $client->__get('adresse_client'));
  25.             $q->bindValue(':tel', $client->__get('tel'));
  26.             $q->execute();
  27.             return $this->db->lastInsertId();
  28.                  
  29.         }
  30.        
  31.        
  32.          public function count()
  33.         {
  34.             return $this->db->query('SELECT COUNT(*) FROM client')->fetchColumn();
  35.         }
  36.        
  37.          public function delete(Client $client)
  38.         {
  39.             $this->db->exec('DELETE FROM client WHERE id = '.$client->id());
  40.         }
  41.  
  42.  
  43.          public function exists($id_client)
  44.         {
  45.                
  46.              return (bool) $this->db->query('SELECT COUNT(*) FROM client WHERE id_client = '.$id_client)->fetchColumn();
  47.         }
  48.        
  49.          public function check_adhesion($id_client)
  50.         {
  51.                
  52.              return (bool) $this->db->query("SELECT COUNT(*) FROM client WHERE etat_adhesion=1 and id_client = $id_client")->fetchColumn();
  53.         }
  54.        
  55.        
  56.          public function update(Client $client)
  57.         {
  58.             $q = $this->db->prepare('UPDATE client SET etat_adhesion = :etat_adhesion, id_ville = :id_ville, nom_client = :nom_client, prenom = :prenom, adresse_client = :adresse_client, tel = :tel WHERE id_client = :id_client');
  59.            
  60.             $q->bindValue(':id_client', $client->__get('id_client'));
  61.             $q->bindValue(':etat_adhesion', $client->__get('etat_adhesion'));
  62.             $q->bindValue(':id_ville', $client->__get('id_ville'));
  63.             $q->bindValue(':nom_client', $client->__get('nom_client'));
  64.             $q->bindValue(':prenom', $client->__get('prenom'));
  65.             $q->bindValue(':adresse_client', $client->__get('adresse_client'));
  66.             $q->bindValue(':tel', $client->__get('tel'));  
  67.            $nb_line = $q->execute();
  68.            
  69.             return $nb_line;
  70.         }
  71.  
  72.  
  73.          public function get($id_client)
  74.         {
  75.        
  76.                 return new Client(
  77.                     $this->db->query('SELECT * FROM client WHERE id_client = '.$id_client)
  78.                          ->fetch(PDO::FETCH_ASSOC)
  79.                 );
  80.  
  81.         }
  82.  
  83.          public function getList()
  84.         {
  85.            
  86.            
  87.             $q = $this->db->prepare('SELECT * FROM client');
  88.             $q->execute();
  89.            
  90.             while ($donnees = $q->fetch(PDO::FETCH_ASSOC))
  91.                 $clients[] = new Client($donnees);
  92.            
  93.             return $clients;
  94.         }
  95.  
  96.  
  97.  
  98.        
  99.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement