added some things to model class

added user_model.php for user handling
added user_controller.php for controlling user missgin view for output.


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@933 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Valkum 14 years ago
parent 0ca6c9f239
commit f73c7cbad2

@ -1,41 +1,62 @@
<?php
class model {
class Model {
public $errormsg = array();
private $table = array();
private $columns = array();
private $values = array();
protected $table;
protected $columns = array();
protected $values = array();
/**
* id of database entry
* @access private
*/
private $id;
protected $id;
protected $column_id;
public save() {
public function save() {
$db = new Database;
#Pseudecode if new
$db->insert($this->table, $this->values);
$db->insert( $this->table, $this->values );
#pseudocode else
$db->update( $this->table, $this->id, $this->values );
}
public load( $parameter = array() ) {
##pseudocode if where is key in parameters
public function load( $parameter = array() ) {
$sql = '';
$db = new Database;
if (array_key_exists( 'where', $parameter) ) {
$w = $parameters['where']; # where = array('column', 'value' )
$sql = " WHERE $where['column'] = $where['value']";
## elseif limit is key in parameters
$l = $parameter['limit']
$sq = " LIMIT $l[1], $l[2]";
$sql .= " WHERE $w[0] = $w[1]";
} elseif ( array_key_exists('limit', $parameter ) ) {
$l = $parameter['limit'] # limit = array(start, length)
$sql .= " LIMIT $l[0], $l[1]";
}
$db->query("SELECT * FROM $this->table $sql");
$this->query = $db->query("SELECT * FROM \{ $this->table \} $sql");
}
public function delete( $parameter = array() ) {
}
public function Assoc() {
$db = new Database();
return $db->getAssoc($this->query);
}
public function Array() {
$db = new Database();
return $db->getArray($this->query);
}
public function Object() {
$db = new Database();
return $db->getObject($this->query);
}
public function Row() {
$db = new Database();
return $db->getRow($this->query);
}
}

@ -0,0 +1,60 @@
<?php
class UserController extends Controller {
public function view($id = NULL) {
if ($id != NULL) {
$this->User->load( array( 'where' => array( $this->User->coloumn_id, $id ) ) );
} else {
$this->Userload();
}
//function for sending the layout the arg $this->User->Assoc();
//return $this->User->Assoc();
}
public function edit($id) {
if($id == NULL) {
$this->errormsg[] = 'The User is nonexistent.';
return false;
}
$this->User->load(array( 'where' => array( $this->User->coloumn_id, $id )));
//function for sending the layout the arg $this->User->Assoc();
//postswtich
//bla bla smarty stuff for getting the values
//$this->User->values = array('frit@example.com', 'hased HMAC_MD5 PW', 'Fritz', '/home/fritz/maildir', 51200000, 'fritz', 'example.com', '{[CREATED]}', '{[MODIFIED]}'); {} = Model should replace something, [] = constant not tablenames
if( ! $this->User->save() ) {
$this->errormsg[] = 'The data can't be saved.';
return false;
}
//redirect to view($id)
}
public function add() {
//only if $_POST of $_GET
//bla bla smarty stuff for filling the values
//$this->User->values = array('frit@example.com', 'hased HMAC_MD5 PW', 'Fritz', '/home/fritz/maildir', 51200000, 'fritz', 'example.com', '{[CREATED]}', '{[MODIFIED]}'); {} = Model should replace something, [] = constant not tablenames
if( ! $this->User->save() ) {
$this->errormsg[] = 'The data can't be saved.';
return false;
}
//redirect to view($id)
}
public function delete($id) {
}
public function activate() {
}
public function deactivate() {
}

@ -0,0 +1,24 @@
<?php
class UserModel extends Model {
public function __construct() {
$this->table = 'mailbox';
$this->columns = array('username' => array('varchar(255)', false),
'password' => array('varchar(255)', false),
'name' => array('varchar(255)', false),
'maildir' => array('varchar(255)', false),
'quota' => array('bigint', false, 0),
'local_part' => array('varchar(255)', false),
'domain' => array('varchar(255)', false),
'created' => array('datetime', false),
'modified' => array('datetime', false),
'active' => array('tinyint(1)', false, 1) );
$this->coloumn_id = 'username';
}
}
Loading…
Cancel
Save