<?php


abstract class BaseTblproduct extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $pro_id;

	
	protected $pro_name;

	
	protected $pro_element;

	
	protected $pro_title;

	
	protected $pro_desc;

	
	protected $pro_version;

	
	protected $pro_type;

	
	protected $pro_level;

	
	protected $pro_price;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

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

	
	public function applyDefaultValues()
	{
		$this->pro_type = 0;
		$this->pro_level = 1;
		$this->pro_price = 0;
	}

	
	public function getProId()
	{
		return $this->pro_id;
	}

	
	public function getProName()
	{
		return $this->pro_name;
	}

	
	public function getProElement()
	{
		return $this->pro_element;
	}

	
	public function getProTitle()
	{
		return $this->pro_title;
	}

	
	public function getProDesc()
	{
		return $this->pro_desc;
	}

	
	public function getProVersion()
	{
		return $this->pro_version;
	}

	
	public function getProType()
	{
		return $this->pro_type;
	}

	
	public function getProLevel()
	{
		return $this->pro_level;
	}

	
	public function getProPrice()
	{
		return $this->pro_price;
	}

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

		if ($this->pro_id !== $v) {
			$this->pro_id = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_ID;
		}

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

		if ($this->pro_name !== $v) {
			$this->pro_name = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_NAME;
		}

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

		if ($this->pro_element !== $v) {
			$this->pro_element = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_ELEMENT;
		}

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

		if ($this->pro_title !== $v) {
			$this->pro_title = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_TITLE;
		}

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

		if ($this->pro_desc !== $v) {
			$this->pro_desc = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_DESC;
		}

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

		if ($this->pro_version !== $v) {
			$this->pro_version = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_VERSION;
		}

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

		if ($this->pro_type !== $v || $v === 0) {
			$this->pro_type = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_TYPE;
		}

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

		if ($this->pro_level !== $v || $v === 1) {
			$this->pro_level = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_LEVEL;
		}

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

		if ($this->pro_price !== $v || $v === 0) {
			$this->pro_price = $v;
			$this->modifiedColumns[] = TblproductPeer::PRO_PRICE;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(TblproductPeer::PRO_TYPE,TblproductPeer::PRO_LEVEL,TblproductPeer::PRO_PRICE))) {
				return false;
			}

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

			if ($this->pro_level !== 1) {
				return false;
			}

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

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

			$this->pro_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->pro_name = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->pro_element = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
			$this->pro_title = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->pro_desc = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->pro_version = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
			$this->pro_type = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->pro_level = ($row[$startcol + 7] !== null) ? (int) $row[$startcol + 7] : null;
			$this->pro_price = ($row[$startcol + 8] !== null) ? (int) $row[$startcol + 8] : null;
			$this->resetModified();

			$this->setNew(false);

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

						return $startcol + 9; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Tblproduct 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(TblproductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = TblproductPeer::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) {  
		} 	}

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

		if ($con === null) {
			$con = Propel::getConnection(TblproductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblproductPeer::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(TblproductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblproductPeer::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[] = TblproductPeer::PRO_ID;
			}

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

				$this->resetModified(); 			}

			$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 = TblproductPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

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

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

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getProId();
				break;
			case 1:
				return $this->getProName();
				break;
			case 2:
				return $this->getProElement();
				break;
			case 3:
				return $this->getProTitle();
				break;
			case 4:
				return $this->getProDesc();
				break;
			case 5:
				return $this->getProVersion();
				break;
			case 6:
				return $this->getProType();
				break;
			case 7:
				return $this->getProLevel();
				break;
			case 8:
				return $this->getProPrice();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblproductPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getProId(),
			$keys[1] => $this->getProName(),
			$keys[2] => $this->getProElement(),
			$keys[3] => $this->getProTitle(),
			$keys[4] => $this->getProDesc(),
			$keys[5] => $this->getProVersion(),
			$keys[6] => $this->getProType(),
			$keys[7] => $this->getProLevel(),
			$keys[8] => $this->getProPrice(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setProId($value);
				break;
			case 1:
				$this->setProName($value);
				break;
			case 2:
				$this->setProElement($value);
				break;
			case 3:
				$this->setProTitle($value);
				break;
			case 4:
				$this->setProDesc($value);
				break;
			case 5:
				$this->setProVersion($value);
				break;
			case 6:
				$this->setProType($value);
				break;
			case 7:
				$this->setProLevel($value);
				break;
			case 8:
				$this->setProPrice($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setProId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setProName($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setProElement($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setProTitle($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setProDesc($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setProVersion($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setProType($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setProLevel($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setProPrice($arr[$keys[8]]);
	}

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

		if ($this->isColumnModified(TblproductPeer::PRO_ID)) $criteria->add(TblproductPeer::PRO_ID, $this->pro_id);
		if ($this->isColumnModified(TblproductPeer::PRO_NAME)) $criteria->add(TblproductPeer::PRO_NAME, $this->pro_name);
		if ($this->isColumnModified(TblproductPeer::PRO_ELEMENT)) $criteria->add(TblproductPeer::PRO_ELEMENT, $this->pro_element);
		if ($this->isColumnModified(TblproductPeer::PRO_TITLE)) $criteria->add(TblproductPeer::PRO_TITLE, $this->pro_title);
		if ($this->isColumnModified(TblproductPeer::PRO_DESC)) $criteria->add(TblproductPeer::PRO_DESC, $this->pro_desc);
		if ($this->isColumnModified(TblproductPeer::PRO_VERSION)) $criteria->add(TblproductPeer::PRO_VERSION, $this->pro_version);
		if ($this->isColumnModified(TblproductPeer::PRO_TYPE)) $criteria->add(TblproductPeer::PRO_TYPE, $this->pro_type);
		if ($this->isColumnModified(TblproductPeer::PRO_LEVEL)) $criteria->add(TblproductPeer::PRO_LEVEL, $this->pro_level);
		if ($this->isColumnModified(TblproductPeer::PRO_PRICE)) $criteria->add(TblproductPeer::PRO_PRICE, $this->pro_price);

		return $criteria;
	}

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

		$criteria->add(TblproductPeer::PRO_ID, $this->pro_id);

		return $criteria;
	}

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

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

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

		$copyObj->setProName($this->pro_name);

		$copyObj->setProElement($this->pro_element);

		$copyObj->setProTitle($this->pro_title);

		$copyObj->setProDesc($this->pro_desc);

		$copyObj->setProVersion($this->pro_version);

		$copyObj->setProType($this->pro_type);

		$copyObj->setProLevel($this->pro_level);

		$copyObj->setProPrice($this->pro_price);


		$copyObj->setNew(true);

		$copyObj->setProId(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 TblproductPeer();
		}
		return self::$peer;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
		} 
	}

} 