aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorCamil Staps2016-07-27 16:18:13 +0200
committerCamil Staps2016-07-27 16:18:13 +0200
commit08e6ca70604aff5169dbcbf5b74215628ae4097e (patch)
tree2fabea3a1bfd1ebf2d3ab3aa02a93aa8a51a779c /classes
parentInitial Model class (diff)
Reorganise to have client use Model
Diffstat (limited to 'classes')
-rw-r--r--classes/client.php95
1 files changed, 4 insertions, 91 deletions
diff --git a/classes/client.php b/classes/client.php
index f45f562..46e2da2 100644
--- a/classes/client.php
+++ b/classes/client.php
@@ -24,78 +24,10 @@
/**
* An interface to the client table in the database
*/
-class client {
- /**
- * @var pdo $pdo The PDO class for database communication
- * @var int $id The id of the client
- * @var string $name The name of the client
- */
- protected $pdo, $id, $name;
-
- /**
- * Create a new instance
- *
- * @param PDO $pdo The PDO class, to access the database
- * @param int $id The id of the client to fetch
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the client could not be found
- */
- public function __construct($pdo, $id) {
- $this->pdo = $pdo;
-
- $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."client` WHERE `id`=?");
- $stmt->execute(array($id));
- if ($stmt->rowCount() == 0) {
- throw new Exception("The client with id '$id' could not be found.");
- }
- $client = $stmt->fetch(PDO::FETCH_ASSOC);
-
- $this->id = $client['id'];
- $this->name = $client['name'];
- }
-
- //------------------------------------------------------------------------------
- // Getters and setters
- //------------------------------------------------------------------------------
-
- /**
- * Get the ID of the client
- *
- * @return int The ID
- */
- public function getId() {
- return $this->id;
- }
-
- /**
- * Get the name of the client
- *
- * @return string The name
- */
- public function getName() {
- return $this->name;
- }
-
- /**
- * Set the name of the client
- *
- * @param string $name The new name for the client
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setName($name) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."client` SET `name`=? WHERE `id`=?");
- $stmt->execute(array($name, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->name = $name;
- return true;
- } else {
- return false;
- }
- }
+class client extends Model {
+ public
+ $table = 'client',
+ $fillable_columns = ['name'];
/**
* Get all contact ids for this client
@@ -138,25 +70,6 @@ class client {
//------------------------------------------------------------------------------
/**
- * Remove this client from the database
- *
- * If this doesn't succeed (i.e. false is returned), that means the client was removed manually or by another instance of this class
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on success, false on failure
- */
- public function delete() {
- $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."client` WHERE `id`=?");
- $stmt->execute(array($this->id));
- if ($stmt->rowCount() != 1) {
- return false;
- } else {
- return true;
- }
- }
-
- /**
* Make a new contact for this client
*
* @param string $name The name for this contact