<?php
/**
 *	Generated by miceCMS
 *	Date: 2010-11-18 10:50:22
 */
class model_Poll {
	private $subsection="";
	private $setstr="";
	private $fields="";
	private $values="";
	private $nrows="";
	private $offset="";
	private $pages=10;
	private $pagenum=1;
	private $pollId=Null;		//	 field type: "int(11+int)"
	private $pollcategoryId=0;		//	 field type: "int(11+int)"
	private $title=Null;		//	 field type: "varchar(255+varchar)"
	private $isdefault=0;		//	 field type: "int(11+int)"
	private $orderid=0;		//	 field type: "int(11+int)"
	private $num=0;		//	 field type: "int(11+int)"

	public function getPollId(){
		return $this->pollId;
	}
	public function setPollId($pollId){
		$this->pollId=$pollId;
		if($this->setstr=="")
			$this->setstr="poll_id=".$pollId."";
		else
			$this->setstr.=",poll_id=".$pollId."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="poll_id";
			$this->values="".$pollId."";
		}else{
			$this->fields.=",poll_id";
			$this->values.=",".$pollId."";
		}
	}
	public function getPollcategoryId(){
		return $this->pollcategoryId;
	}
	public function setPollcategoryId($pollcategoryId){
		$this->pollcategoryId=$pollcategoryId;
		if($this->setstr=="")
			$this->setstr="pollcategory_id=".$pollcategoryId."";
		else
			$this->setstr.=",pollcategory_id=".$pollcategoryId."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="pollcategory_id";
			$this->values="".$pollcategoryId."";
		}else{
			$this->fields.=",pollcategory_id";
			$this->values.=",".$pollcategoryId."";
		}
	}
	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 getIsdefault(){
		return $this->isdefault;
	}
	public function setIsdefault($isdefault){
		$this->isdefault=$isdefault;
		if($this->setstr=="")
			$this->setstr="isdefault=".$isdefault."";
		else
			$this->setstr.=",isdefault=".$isdefault."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="isdefault";
			$this->values="".$isdefault."";
		}else{
			$this->fields.=",isdefault";
			$this->values.=",".$isdefault."";
		}
	}
	public function getOrderid(){
		return $this->orderid;
	}
	public function setOrderid($orderid){
		$this->orderid=$orderid;
		if($this->setstr=="")
			$this->setstr="orderid=".$orderid."";
		else
			$this->setstr.=",orderid=".$orderid."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="orderid";
			$this->values="".$orderid."";
		}else{
			$this->fields.=",orderid";
			$this->values.=",".$orderid."";
		}
	}
	public function getNum(){
		return $this->num;
	}
	public function setNum($num){
		$this->num=$num;
		if($this->setstr=="")
			$this->setstr="num=".$num."";
		else
			$this->setstr.=",num=".$num."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="num";
			$this->values="".$num."";
		}else{
			$this->fields.=",num";
			$this->values.=",".$num."";
		}
	}
	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("#__poll ","*",$this->subsection);
		return $this->fetchResult($result);
	}
	public function doSelectLimit() {
		global $conn;
		$result=$conn->SelectArrayLimit("#__poll ","*",$this->subsection,$this->nrows,$this->offset);
		return $this->fetchResult($result);
	}
	public function doSelectOne() {
		global $conn;
		$result=$conn->SelectRow("#__poll ","*",$this->subsection,$this->nrows,$this->offset);
		return $this->fetchResultOne($result);
	}
	public function doCount() {
		global $conn;
		return $conn->SelectCount("#__poll ","*",$this->subsection);
	}
	public function doInsert() {
		global $conn;
		return $conn->Insert("#__poll ",$this->fields,$this->values);
	}
	public function doDelete() {
		global $conn;
		return $conn->Delete("#__poll ",$this->subsection);
	}
	public function doUpdate() {
		global $conn;
		return $conn->Update("#__poll ",$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++){
			$poll=new model_Poll();
			$poll->pollId=$result[$i]["poll_id"];
			$poll->pollcategoryId=$result[$i]["pollcategory_id"];
			$poll->title=$result[$i]["title"];
			$poll->isdefault=$result[$i]["isdefault"];
			$poll->orderid=$result[$i]["orderid"];
			$poll->num=$result[$i]["num"];
			$array->append($poll);
		}
		return $array;
	}
	public function fetchResultOne($result){
		if(!$result){
			return $result;
		}
		$poll=new model_Poll();
		$poll->pollId=$result["poll_id"];
		$poll->pollcategoryId=$result["pollcategory_id"];
		$poll->title=$result["title"];
		$poll->isdefault=$result["isdefault"];
		$poll->orderid=$result["orderid"];
		$poll->num=$result["num"];
		return $poll;
	}
}
?>