<?php
/**
 *	Generated by miceCMS
 *	Date: 2010-11-18 10:50:22
 */
class model_Usergroup {
	private $subsection="";
	private $setstr="";
	private $fields="";
	private $values="";
	private $nrows="";
	private $offset="";
	private $pages=10;
	private $pagenum=1;
	private $usergroupId=Null;		//	 field type: "int(11+int)"
	private $name=Null;		//	 field type: "varchar(255+varchar)"
	private $level=0;		//	 field type: "int(11+int)"
	private $menu=Null;		//	 field type: "text(+text)"
	private $module=Null;		//	 field type: "text(+text)"
	private $intro=Null;		//	 field type: "varchar(255+varchar)"

	public function getUsergroupId(){
		return $this->usergroupId;
	}
	public function setUsergroupId($usergroupId){
		$this->usergroupId=$usergroupId;
		if($this->setstr=="")
			$this->setstr="usergroup_id=".$usergroupId."";
		else
			$this->setstr.=",usergroup_id=".$usergroupId."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="usergroup_id";
			$this->values="".$usergroupId."";
		}else{
			$this->fields.=",usergroup_id";
			$this->values.=",".$usergroupId."";
		}
	}
	public function getName(){
		return $this->name;
	}
	public function setName($name){
		$this->name=$name;
		if($this->setstr=="")
			$this->setstr="name='".$name."'";
		else
			$this->setstr.=",name='".$name."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="name";
			$this->values="'".$name."'";
		}else{
			$this->fields.=",name";
			$this->values.=",'".$name."'";
		}
	}
	public function getLevel(){
		return $this->level;
	}
	public function setLevel($level){
		$this->level=$level;
		if($this->setstr=="")
			$this->setstr="level=".$level."";
		else
			$this->setstr.=",level=".$level."";
		if($this->fields=="" AND $this->values==""){
			$this->fields="level";
			$this->values="".$level."";
		}else{
			$this->fields.=",level";
			$this->values.=",".$level."";
		}
	}
	public function getMenu(){
		return $this->menu;
	}
	public function setMenu($menu){
		$this->menu=$menu;
		if($this->setstr=="")
			$this->setstr="menu='".$menu."'";
		else
			$this->setstr.=",menu='".$menu."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="menu";
			$this->values="'".$menu."'";
		}else{
			$this->fields.=",menu";
			$this->values.=",'".$menu."'";
		}
	}
	public function getModule(){
		return $this->module;
	}
	public function setModule($module){
		$this->module=$module;
		if($this->setstr=="")
			$this->setstr="module='".$module."'";
		else
			$this->setstr.=",module='".$module."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="module";
			$this->values="'".$module."'";
		}else{
			$this->fields.=",module";
			$this->values.=",'".$module."'";
		}
	}
	public function getIntro(){
		return $this->intro;
	}
	public function setIntro($intro){
		$this->intro=$intro;
		if($this->setstr=="")
			$this->setstr="intro='".$intro."'";
		else
			$this->setstr.=",intro='".$intro."'";
		if($this->fields=="" AND $this->values==""){
			$this->fields="intro";
			$this->values="'".$intro."'";
		}else{
			$this->fields.=",intro";
			$this->values.=",'".$intro."'";
		}
	}
	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("#__usergroup ","*",$this->subsection);
		return $this->fetchResult($result);
	}
	public function doSelectLimit() {
		global $conn;
		$result=$conn->SelectArrayLimit("#__usergroup ","*",$this->subsection,$this->nrows,$this->offset);
		return $this->fetchResult($result);
	}
	public function doSelectOne() {
		global $conn;
		$result=$conn->SelectRow("#__usergroup ","*",$this->subsection,$this->nrows,$this->offset);
		return $this->fetchResultOne($result);
	}
	public function doCount() {
		global $conn;
		return $conn->SelectCount("#__usergroup ","*",$this->subsection);
	}
	public function doInsert() {
		global $conn;
		return $conn->Insert("#__usergroup ",$this->fields,$this->values);
	}
	public function doDelete() {
		global $conn;
		return $conn->Delete("#__usergroup ",$this->subsection);
	}
	public function doUpdate() {
		global $conn;
		return $conn->Update("#__usergroup ",$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++){
			$usergroup=new model_Usergroup();
			$usergroup->usergroupId=$result[$i]["usergroup_id"];
			$usergroup->name=$result[$i]["name"];
			$usergroup->level=$result[$i]["level"];
			$usergroup->menu=$result[$i]["menu"];
			$usergroup->module=$result[$i]["module"];
			$usergroup->intro=$result[$i]["intro"];
			$array->append($usergroup);
		}
		return $array;
	}
	public function fetchResultOne($result){
		if(!$result){
			return $result;
		}
		$usergroup=new model_Usergroup();
		$usergroup->usergroupId=$result["usergroup_id"];
		$usergroup->name=$result["name"];
		$usergroup->level=$result["level"];
		$usergroup->menu=$result["menu"];
		$usergroup->module=$result["module"];
		$usergroup->intro=$result["intro"];
		return $usergroup;
	}
}
?>