Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Classe ClientManager
- * @author Anycee Martin
- * @version 1.0
- */
- class ClientManager
- {
- private $db; // Instance de PDO
- public function __construct()
- {
- $this->db = db::getInstance();
- }
- public function add(Client $client)
- {
- $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');
- $q->bindValue(':id_ville', $client->__get('id_ville'));
- $q->bindValue(':etat_adhesion', $client->__get('etat_adhesion'));
- $q->bindValue(':nom_client', $client->__get('nom_client'));
- $q->bindValue(':prenom', $client->__get('prenom'));
- $q->bindValue(':adresse_client', $client->__get('adresse_client'));
- $q->bindValue(':tel', $client->__get('tel'));
- $q->execute();
- return $this->db->lastInsertId();
- }
- public function count()
- {
- return $this->db->query('SELECT COUNT(*) FROM client')->fetchColumn();
- }
- public function delete(Client $client)
- {
- $this->db->exec('DELETE FROM client WHERE id = '.$client->id());
- }
- public function exists($id_client)
- {
- return (bool) $this->db->query('SELECT COUNT(*) FROM client WHERE id_client = '.$id_client)->fetchColumn();
- }
- public function check_adhesion($id_client)
- {
- return (bool) $this->db->query("SELECT COUNT(*) FROM client WHERE etat_adhesion=1 and id_client = $id_client")->fetchColumn();
- }
- public function update(Client $client)
- {
- $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');
- $q->bindValue(':id_client', $client->__get('id_client'));
- $q->bindValue(':etat_adhesion', $client->__get('etat_adhesion'));
- $q->bindValue(':id_ville', $client->__get('id_ville'));
- $q->bindValue(':nom_client', $client->__get('nom_client'));
- $q->bindValue(':prenom', $client->__get('prenom'));
- $q->bindValue(':adresse_client', $client->__get('adresse_client'));
- $q->bindValue(':tel', $client->__get('tel'));
- $nb_line = $q->execute();
- return $nb_line;
- }
- public function get($id_client)
- {
- return new Client(
- $this->db->query('SELECT * FROM client WHERE id_client = '.$id_client)
- ->fetch(PDO::FETCH_ASSOC)
- );
- }
- public function getList()
- {
- $q = $this->db->prepare('SELECT * FROM client');
- $q->execute();
- while ($donnees = $q->fetch(PDO::FETCH_ASSOC))
- $clients[] = new Client($donnees);
- return $clients;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement