--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoContractManager extends AbstractPdoManager {
+
+ public function createContract($contract) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO contracts (
+ number,
+ state,
+ appliances
+ ) VALUES (
+ :number,
+ :state,
+ :appliances
+ );'
+ );
+ $query -> bindValue(':number', $contract -> getNumber());
+ $query -> bindValue(':state', $contract -> getState());
+ $query -> bindValue(':appliances', implode("|", $contract -> getAppliances()));
+ $query -> execute();
+ }
+
+ public function updateContract($contract) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE contracts
+ SET number = :number,
+ state = :state,
+ appliances = :appliances
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $contract -> getId());
+ $query -> bindValue(':number', $contract -> getNumber());
+ $query -> bindValue(':state', $contract -> getState());
+ $query -> bindValue(':appliances', implode("|", $contract -> getAppliances()));
+ $query -> execute();
+ $query->closeCursor();
+ }
+
+ public function getContract($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM contracts WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $contract = new Contract($result['id'], $result['number'], $result['state'], explode("|", $result['appliances']));
+
+ $query->closeCursor();
+
+ return $contract;
+ }
+
+ public function getContractByNumber($number) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM contracts WHERE number = :number');
+ $query -> bindValue(':number', $number);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $contract = new Contract($result['id'], $result['number'], $result['state'], explode("|", $result['appliances']));
+
+ $query->closeCursor();
+
+ return $contract;
+ }
+
+ public function getContracts() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM contracts');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $contracts = array();
+ foreach ($results as $result) {
+ $contracts[] = new Contract($result['id'], $result['number'], $result['state'], explode("|", $result['appliances']));
+ }
+
+ $query->closeCursor();
+
+ return $contracts;
+ }
+
+ public function removeContract($contract) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM contracts WHERE id = :id');
+ $query -> bindValue('id', $contract -> getId());
+ $query -> execute();
+ }
+
+ }
+