<?php
/**
 *	Generated by miceCMS
 *	Date: 2010-11-18 10:50:22
 */
class model_File {
	private $subsection="";
	private $setstr="";
	private $fields="";
	private $values="";
	private $nrows="";
	private $offset="";
	private $pages=10;
	private $pagenum=1;
	private $fileId=Null;		//	 field type: "int(11+int)"
	private $filecategoryId=0;		//	 field type: "int(11+int)"
	private $filename=Null;		//	 field type: "varchar(255+varchar)"
	private $type=Null;		//	 field type: "varchar(25+varchar)"
	private $title=Null;		//	 field type: "varchar(255+varchar)"
	private $summary=Null;		//	 field type: "text(+text)"
	private $link=Null;		//	 field type: "varchar(255+varchar)"
	private $createdat=0;		//	 field type: "int(11+int)"
	private $userId=0;		//	 field type: "int(11+int)"

	public function getFileId(){
		return $this->fileId;
	}
	public function setFileId($fileId){
		$this->fileId=$fileId;
		if($this->setstr=="")
			$this->setstr="file_id=".$fileId."";
		else
			$this->setstr.=",file_id=".$fileId."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="file_id";
			$this->values="".$fileId."";
		}else{
			$this->fields.=",file_id";
			$this->values.=",".$fileId."";
		}
	}
	public function getFilecategoryId(){
		return $this->filecategoryId;
	}
	public function setFilecategoryId($filecategoryId){
		$this->filecategoryId=$filecategoryId;
		if($this->setstr=="")
			$this->setstr="filecategory_id=".$filecategoryId."";
		else
			$this->setstr.=",filecategory_id=".$filecategoryId."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="filecategory_id";
			$this->values="".$filecategoryId."";
		}else{
			$this->fields.=",filecategory_id";
			$this->values.=",".$filecategoryId."";
		}
	}
	public function getFilename(){
		return $this->filename;
	}
	public function setFilename($filename){
		$this->filename=$filename;
		if($this->setstr=="")
			$this->setstr="filename='".$filename."'";
		else
			$this->setstr.=",filename='".$filename."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="filename";
			$this->values="'".$filename."'";
		}else{
			$this->fields.=",filename";
			$this->values.=",'".$filename."'";
		}
	}
	public function getType(){
		return $this->type;
	}
	public function setType($type){
		$this->type=$type;
		if($this->setstr=="")
			$this->setstr="type='".$type."'";
		else
			$this->setstr.=",type='".$type."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="type";
			$this->values="'".$type."'";
		}else{
			$this->fields.=",type";
			$this->values.=",'".$type."'";
		}
	}
	public function getTitle(){
		return $this->title;
	}
	public function setTitle($title){
		$this->title=$title;
		if($this->setstr=="")
			$this->setstr="title='".$title."'";
		else
			$this->setstr.=",title='".$title."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="title";
			$this->values="'".$title."'";
		}else{
			$this->fields.=",title";
			$this->values.=",'".$title."'";
		}
	}
	public function getSummary(){
		return $this->summary;
	}
	public function setSummary($summary){
		$this->summary=$summary;
		if($this->setstr=="")
			$this->setstr="summary='".$summary."'";
		else
			$this->setstr.=",summary='".$summary."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="summary";
			$this->values="'".$summary."'";
		}else{
			$this->fields.=",summary";
			$this->values.=",'".$summary."'";
		}
	}
	public function getLink(){
		return $this->link;
	}
	public function setLink($link){
		$this->link=$link;
		if($this->setstr=="")
			$this->setstr="link='".$link."'";
		else
			$this->setstr.=",link='".$link."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="link";
			$this->values="'".$link."'";
		}else{
			$this->fields.=",link";
			$this->values.=",'".$link."'";
		}
	}
	public function getCreatedat(){
		return $this->createdat;
	}
	public function setCreatedat($createdat){
		$this->createdat=$createdat;
		if($this->setstr=="")
			$this->setstr="createdat=".$createdat."";
		else
			$this->setstr.=",createdat=".$createdat."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="createdat";
			$this->values="".$createdat."";
		}else{
			$this->fields.=",createdat";
			$this->values.=",".$createdat."";
		}
	}
	public function getUserId(){
		return $this->userId;
	}
	public function setUserId($userId){
		$this->userId=$userId;
		if($this->setstr=="")
			$this->setstr="user_id=".$userId."";
		else
			$this->setstr.=",user_id=".$userId."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="user_id";
			$this->values="".$userId."";
		}else{
			$this->fields.=",user_id";
			$this->values.=",".$userId."";
		}
	}
	public function setSubsection($str){
		$this->subsection=" ".$str;
	}
	public function setNrows($str){
		$this->nrows=$str;
	}
	public function setOffset($str){
		$this->offset=$str;
	}
	public function setPages($str){
		$this->pages=$str;
	}
	public function setPagenum($str){
		$this->pagenum=$str;
	}
	public function doSelect() {
		global $conn;
		$result=$conn->SelectArray("#__file ","*",$this->subsection);
		return $this->fetchResult($result);
	}
	public function doSelectLimit() {
		global $conn;
		$result=$conn->SelectArrayLimit("#__file ","*",$this->subsection,$this->nrows,$this->offset);
		return $this->fetchResult($result);
	}
	public function doSelectOne() {
		global $conn;
		$result=$conn->SelectRow("#__file ","*",$this->subsection,$this->nrows,$this->offset);
		return $this->fetchResultOne($result);
	}
	public function doCount() {
		global $conn;
		return $conn->SelectCount("#__file ","*",$this->subsection);
	}
	public function doInsert() {
		global $conn;
		return $conn->Insert("#__file ",$this->fields,$this->values);
	}
	public function doDelete() {
		global $conn;
		return $conn->Delete("#__file ",$this->subsection);
	}
	public function doUpdate() {
		global $conn;
		return $conn->Update("#__file ",$this->setstr,$this->subsection);
	}
	public function Pager() {
		$this->nrows=($this->pagenum-1)*$this->pages;
		$this->offset=$this->pages;
		return $this->doSelectLimit();
	}
	public function Page() {
		return $this->pagenum;
	}
	public function Totals() {
		return $this->doCount();
	}
	public function TotalPages() {
		if (!$this->doCount())	return 0;
		return (int)ceil($this->Totals()/$this->pages);
	}
	public function fetchResult($result){
		if(!$result){
			return $result;
		}
		$array=new ArrayObject();
		for($i=0;$i<count($result);$i++){
			$file=new model_File();
			$file->fileId=$result[$i]["file_id"];
			$file->filecategoryId=$result[$i]["filecategory_id"];
			$file->filename=$result[$i]["filename"];
			$file->type=$result[$i]["type"];
			$file->title=$result[$i]["title"];
			$file->summary=$result[$i]["summary"];
			$file->link=$result[$i]["link"];
			$file->createdat=$result[$i]["createdat"];
			$file->userId=$result[$i]["user_id"];
			$array->append($file);
		}
		return $array;
	}
	public function fetchResultOne($result){
		if(!$result){
			return $result;
		}
		$file=new model_File();
		$file->fileId=$result["file_id"];
		$file->filecategoryId=$result["filecategory_id"];
		$file->filename=$result["filename"];
		$file->type=$result["type"];
		$file->title=$result["title"];
		$file->summary=$result["summary"];
		$file->link=$result["link"];
		$file->createdat=$result["createdat"];
		$file->userId=$result["user_id"];
		return $file;
	}
}
?>