.

--

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

 * 
 * Generic Table Editor
 * 
 * Baseclass for Models in this imaginary ORM
 * 
 * Inspired by http://extjs.com/deploy/dev/examples/writer/writer.html
 *
 * @author Bernhard Woehrlin
 * @copyright (c) 2008-2009, IT.CappuccinoNet.com
 * @date 2009-09-01 16:27:36
 * @version 1.3
 * @class Model
 * 
 */
class Model {
    
		public $id, $attributes;
		
    public function __construct($params) {
    	
        $this->id = $params["id"] || null;
        $this->attributes = $params;
    }
    
		
		static function get($id) {
        global $dbh;
        $found = null;
        $found = $dbh->get($id);
				
        return $found;
    }
    static function getAll($limit=null, $start=null,$archive = null, $orderby=null) {
      
        global $dbh;       
				#print_r($dbh);
        $rs = $dbh->getAll($limit, $start, $archive, $orderby);
				
			  return $rs;
    }
		static function getNumRows() {
      
        global $dbh;       
        
        return $dbh->getNumRows();
    }
    
    static function update($id, $params) {
        global $dbh;
        $res = $dbh->update($id, $params);
				$rec = ($res != null) ? $dbh->get($id): null;
				
				return $rec;
    }
    
		static function insert($params) {
      global $dbh;
     
      $obj = new self($params);
			#print_r($obj);
		  $id = $dbh->insert($params);			
      $found = ($id != null) ? $dbh->get($id): null;
			
			return $found;
    }
    
		static function delete($id) {
        global $dbh;
        $rec = null;
        $response = $dbh->delete($id);
				return $response;
    }
    
    
    
}