1 |
rodolico |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class Client {
|
|
|
4 |
private static $TABLENAME = 'client';
|
|
|
5 |
private $id; // the unique id of the client
|
|
|
6 |
private $name; // client name for display
|
|
|
7 |
private $notes; // any notes about this client
|
|
|
8 |
|
|
|
9 |
/* constructor. Pass in id, name and notes. If id passed but not name
|
|
|
10 |
will attempt to load information from the database
|
|
|
11 |
*/
|
|
|
12 |
function __construct ( $id = '', $name = '', $notes = '' ) {
|
|
|
13 |
$this->id = $id;
|
|
|
14 |
$this->name = $name;
|
|
|
15 |
$this->notes = $notes;
|
|
|
16 |
if ( $this->id and ! $this->name ) {
|
|
|
17 |
$this->loadFromDatabase();
|
|
|
18 |
}
|
|
|
19 |
} // constructor
|
|
|
20 |
|
|
|
21 |
function loadFromDatabase () {
|
|
|
22 |
$query = "select name, notes from $TABLENAME where id = $this->id";
|
|
|
23 |
// loadFromDatabase
|
|
|
24 |
} // loadFromDatabase
|
|
|
25 |
|
|
|
26 |
function saveToDatabase () {
|
|
|
27 |
if ( $this->id ) { // we are doing an update
|
|
|
28 |
$query = "update $TABLENAME set name = $this->name, notes = $this->notes where id = $this->id";
|
|
|
29 |
// do the save
|
|
|
30 |
} else { // this is a new record
|
|
|
31 |
$query = "insert into $TABLENAME ( id, name, notes ) values ( null, $this->name, $this->notes" );
|
|
|
32 |
}
|
|
|
33 |
} // saveToDatabase
|
|
|
34 |
} // class Client
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
?>
|