<?php


abstract class BaseTblcategory extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $cg_id;

	
	protected $cg_name;

	
	protected $cg_parentid;

	
	protected $cg_child;

	
	protected $cg_family;

	
	protected $cg_desc;

	
	protected $cg_visited;

	
	protected $cg_image;

	
	protected $cg_path;

	
	protected $cg_public;

	
	protected $cg_sort;

	
	protected $collTblblogcategorys;

	
	private $lastTblblogcategoryCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->cg_visited = 0;
		$this->cg_public = 0;
		$this->cg_sort = 0;
	}

	
	public function getCgId()
	{
		return $this->cg_id;
	}

	
	public function getCgName()
	{
		return $this->cg_name;
	}

	
	public function getCgParentid()
	{
		return $this->cg_parentid;
	}

	
	public function getCgChild()
	{
		return $this->cg_child;
	}

	
	public function getCgFamily()
	{
		return $this->cg_family;
	}

	
	public function getCgDesc()
	{
		return $this->cg_desc;
	}

	
	public function getCgVisited()
	{
		return $this->cg_visited;
	}

	
	public function getCgImage()
	{
		return $this->cg_image;
	}

	
	public function getCgPath()
	{
		return $this->cg_path;
	}

	
	public function getCgPublic()
	{
		return $this->cg_public;
	}

	
	public function getCgSort()
	{
		return $this->cg_sort;
	}

	
	public function setCgId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->cg_id !== $v) {
			$this->cg_id = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_ID;
		}

		return $this;
	} 
	
	public function setCgName($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->cg_name !== $v) {
			$this->cg_name = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_NAME;
		}

		return $this;
	} 
	
	public function setCgParentid($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->cg_parentid !== $v) {
			$this->cg_parentid = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_PARENTID;
		}

		return $this;
	} 
	
	public function setCgChild($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->cg_child !== $v) {
			$this->cg_child = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_CHILD;
		}

		return $this;
	} 
	
	public function setCgFamily($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->cg_family !== $v) {
			$this->cg_family = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_FAMILY;
		}

		return $this;
	} 
	
	public function setCgDesc($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->cg_desc !== $v) {
			$this->cg_desc = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_DESC;
		}

		return $this;
	} 
	
	public function setCgVisited($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->cg_visited !== $v || $v === 0) {
			$this->cg_visited = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_VISITED;
		}

		return $this;
	} 
	
	public function setCgImage($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->cg_image !== $v) {
			$this->cg_image = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_IMAGE;
		}

		return $this;
	} 
	
	public function setCgPath($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->cg_path !== $v) {
			$this->cg_path = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_PATH;
		}

		return $this;
	} 
	
	public function setCgPublic($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->cg_public !== $v || $v === 0) {
			$this->cg_public = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_PUBLIC;
		}

		return $this;
	} 
	
	public function setCgSort($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->cg_sort !== $v || $v === 0) {
			$this->cg_sort = $v;
			$this->modifiedColumns[] = TblcategoryPeer::CG_SORT;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(TblcategoryPeer::CG_VISITED,TblcategoryPeer::CG_PUBLIC,TblcategoryPeer::CG_SORT))) {
				return false;
			}

			if ($this->cg_visited !== 0) {
				return false;
			}

			if ($this->cg_public !== 0) {
				return false;
			}

			if ($this->cg_sort !== 0) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->cg_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->cg_name = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->cg_parentid = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
			$this->cg_child = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->cg_family = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->cg_desc = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->cg_visited = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->cg_image = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->cg_path = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
			$this->cg_public = ($row[$startcol + 9] !== null) ? (int) $row[$startcol + 9] : null;
			$this->cg_sort = ($row[$startcol + 10] !== null) ? (int) $row[$startcol + 10] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 11; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Tblcategory object", $e);
		}
	}

	
	public function ensureConsistency()
	{

	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TblcategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = TblcategoryPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->collTblblogcategorys = null;
			$this->lastTblblogcategoryCriteria = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TblcategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblcategoryPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TblcategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblcategoryPeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

			if ($this->isNew() ) {
				$this->modifiedColumns[] = TblcategoryPeer::CG_ID;
			}

						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TblcategoryPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setCgId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TblcategoryPeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->collTblblogcategorys !== null) {
				foreach ($this->collTblblogcategorys as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = TblcategoryPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collTblblogcategorys !== null) {
					foreach ($this->collTblblogcategorys as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TblcategoryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCgId();
				break;
			case 1:
				return $this->getCgName();
				break;
			case 2:
				return $this->getCgParentid();
				break;
			case 3:
				return $this->getCgChild();
				break;
			case 4:
				return $this->getCgFamily();
				break;
			case 5:
				return $this->getCgDesc();
				break;
			case 6:
				return $this->getCgVisited();
				break;
			case 7:
				return $this->getCgImage();
				break;
			case 8:
				return $this->getCgPath();
				break;
			case 9:
				return $this->getCgPublic();
				break;
			case 10:
				return $this->getCgSort();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblcategoryPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCgId(),
			$keys[1] => $this->getCgName(),
			$keys[2] => $this->getCgParentid(),
			$keys[3] => $this->getCgChild(),
			$keys[4] => $this->getCgFamily(),
			$keys[5] => $this->getCgDesc(),
			$keys[6] => $this->getCgVisited(),
			$keys[7] => $this->getCgImage(),
			$keys[8] => $this->getCgPath(),
			$keys[9] => $this->getCgPublic(),
			$keys[10] => $this->getCgSort(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TblcategoryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCgId($value);
				break;
			case 1:
				$this->setCgName($value);
				break;
			case 2:
				$this->setCgParentid($value);
				break;
			case 3:
				$this->setCgChild($value);
				break;
			case 4:
				$this->setCgFamily($value);
				break;
			case 5:
				$this->setCgDesc($value);
				break;
			case 6:
				$this->setCgVisited($value);
				break;
			case 7:
				$this->setCgImage($value);
				break;
			case 8:
				$this->setCgPath($value);
				break;
			case 9:
				$this->setCgPublic($value);
				break;
			case 10:
				$this->setCgSort($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TblcategoryPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setCgId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCgName($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCgParentid($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCgChild($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCgFamily($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCgDesc($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setCgVisited($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setCgImage($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCgPath($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setCgPublic($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setCgSort($arr[$keys[10]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TblcategoryPeer::DATABASE_NAME);

		if ($this->isColumnModified(TblcategoryPeer::CG_ID)) $criteria->add(TblcategoryPeer::CG_ID, $this->cg_id);
		if ($this->isColumnModified(TblcategoryPeer::CG_NAME)) $criteria->add(TblcategoryPeer::CG_NAME, $this->cg_name);
		if ($this->isColumnModified(TblcategoryPeer::CG_PARENTID)) $criteria->add(TblcategoryPeer::CG_PARENTID, $this->cg_parentid);
		if ($this->isColumnModified(TblcategoryPeer::CG_CHILD)) $criteria->add(TblcategoryPeer::CG_CHILD, $this->cg_child);
		if ($this->isColumnModified(TblcategoryPeer::CG_FAMILY)) $criteria->add(TblcategoryPeer::CG_FAMILY, $this->cg_family);
		if ($this->isColumnModified(TblcategoryPeer::CG_DESC)) $criteria->add(TblcategoryPeer::CG_DESC, $this->cg_desc);
		if ($this->isColumnModified(TblcategoryPeer::CG_VISITED)) $criteria->add(TblcategoryPeer::CG_VISITED, $this->cg_visited);
		if ($this->isColumnModified(TblcategoryPeer::CG_IMAGE)) $criteria->add(TblcategoryPeer::CG_IMAGE, $this->cg_image);
		if ($this->isColumnModified(TblcategoryPeer::CG_PATH)) $criteria->add(TblcategoryPeer::CG_PATH, $this->cg_path);
		if ($this->isColumnModified(TblcategoryPeer::CG_PUBLIC)) $criteria->add(TblcategoryPeer::CG_PUBLIC, $this->cg_public);
		if ($this->isColumnModified(TblcategoryPeer::CG_SORT)) $criteria->add(TblcategoryPeer::CG_SORT, $this->cg_sort);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TblcategoryPeer::DATABASE_NAME);

		$criteria->add(TblcategoryPeer::CG_ID, $this->cg_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getCgId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setCgId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCgName($this->cg_name);

		$copyObj->setCgParentid($this->cg_parentid);

		$copyObj->setCgChild($this->cg_child);

		$copyObj->setCgFamily($this->cg_family);

		$copyObj->setCgDesc($this->cg_desc);

		$copyObj->setCgVisited($this->cg_visited);

		$copyObj->setCgImage($this->cg_image);

		$copyObj->setCgPath($this->cg_path);

		$copyObj->setCgPublic($this->cg_public);

		$copyObj->setCgSort($this->cg_sort);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getTblblogcategorys() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addTblblogcategory($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setCgId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TblcategoryPeer();
		}
		return self::$peer;
	}

	
	public function clearTblblogcategorys()
	{
		$this->collTblblogcategorys = null; 	}

	
	public function initTblblogcategorys()
	{
		$this->collTblblogcategorys = array();
	}

	
	public function getTblblogcategorys($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(TblcategoryPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTblblogcategorys === null) {
			if ($this->isNew()) {
			   $this->collTblblogcategorys = array();
			} else {

				$criteria->add(TblblogcategoryPeer::CAT_BASE, $this->cg_id);

				TblblogcategoryPeer::addSelectColumns($criteria);
				$this->collTblblogcategorys = TblblogcategoryPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TblblogcategoryPeer::CAT_BASE, $this->cg_id);

				TblblogcategoryPeer::addSelectColumns($criteria);
				if (!isset($this->lastTblblogcategoryCriteria) || !$this->lastTblblogcategoryCriteria->equals($criteria)) {
					$this->collTblblogcategorys = TblblogcategoryPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTblblogcategoryCriteria = $criteria;
		return $this->collTblblogcategorys;
	}

	
	public function countTblblogcategorys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(TblcategoryPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collTblblogcategorys === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(TblblogcategoryPeer::CAT_BASE, $this->cg_id);

				$count = TblblogcategoryPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TblblogcategoryPeer::CAT_BASE, $this->cg_id);

				if (!isset($this->lastTblblogcategoryCriteria) || !$this->lastTblblogcategoryCriteria->equals($criteria)) {
					$count = TblblogcategoryPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collTblblogcategorys);
				}
			} else {
				$count = count($this->collTblblogcategorys);
			}
		}
		$this->lastTblblogcategoryCriteria = $criteria;
		return $count;
	}

	
	public function addTblblogcategory(Tblblogcategory $l)
	{
		if ($this->collTblblogcategorys === null) {
			$this->initTblblogcategorys();
		}
		if (!in_array($l, $this->collTblblogcategorys, true)) { 			array_push($this->collTblblogcategorys, $l);
			$l->setTblcategory($this);
		}
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->collTblblogcategorys) {
				foreach ((array) $this->collTblblogcategorys as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} 
		$this->collTblblogcategorys = null;
	}

} 