<?php


abstract class BaseTblblogdepends extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $dp_blog;

	
	protected $dp_parent;

	
	protected $aTblblog;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

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

	
	public function applyDefaultValues()
	{
	}

	
	public function getDpBlog()
	{
		return $this->dp_blog;
	}

	
	public function getDpParent()
	{
		return $this->dp_parent;
	}

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

		if ($this->dp_blog !== $v) {
			$this->dp_blog = $v;
			$this->modifiedColumns[] = TblblogdependsPeer::DP_BLOG;
		}

		if ($this->aTblblog !== null && $this->aTblblog->getBlId() !== $v) {
			$this->aTblblog = null;
		}

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

		if ($this->dp_parent !== $v) {
			$this->dp_parent = $v;
			$this->modifiedColumns[] = TblblogdependsPeer::DP_PARENT;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array())) {
				return false;
			}

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

			$this->dp_blog = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->dp_parent = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->resetModified();

			$this->setNew(false);

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

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

	
	public function ensureConsistency()
	{

		if ($this->aTblblog !== null && $this->dp_blog !== $this->aTblblog->getBlId()) {
			$this->aTblblog = null;
		}
	} 
	
	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(TblblogdependsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = TblblogdependsPeer::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->aTblblog = 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(TblblogdependsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblblogdependsPeer::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(TblblogdependsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblblogdependsPeer::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->aTblblog !== null) {
				if ($this->aTblblog->isModified() || $this->aTblblog->isNew()) {
					$affectedRows += $this->aTblblog->save($con);
				}
				$this->setTblblog($this->aTblblog);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TblblogdependsPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += TblblogdependsPeer::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 ($this->aTblblog !== null) {
				if (!$this->aTblblog->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTblblog->getValidationFailures());
				}
			}


			if (($retval = TblblogdependsPeer::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 = TblblogdependsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getDpBlog();
				break;
			case 1:
				return $this->getDpParent();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblblogdependsPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getDpBlog(),
			$keys[1] => $this->getDpParent(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setDpBlog($value);
				break;
			case 1:
				$this->setDpParent($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setDpBlog($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setDpParent($arr[$keys[1]]);
	}

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

		if ($this->isColumnModified(TblblogdependsPeer::DP_BLOG)) $criteria->add(TblblogdependsPeer::DP_BLOG, $this->dp_blog);
		if ($this->isColumnModified(TblblogdependsPeer::DP_PARENT)) $criteria->add(TblblogdependsPeer::DP_PARENT, $this->dp_parent);

		return $criteria;
	}

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

		$criteria->add(TblblogdependsPeer::DP_BLOG, $this->dp_blog);
		$criteria->add(TblblogdependsPeer::DP_PARENT, $this->dp_parent);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		$pks = array();

		$pks[0] = $this->getDpBlog();

		$pks[1] = $this->getDpParent();

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

		$this->setDpBlog($keys[0]);

		$this->setDpParent($keys[1]);

	}

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

		$copyObj->setDpBlog($this->dp_blog);

		$copyObj->setDpParent($this->dp_parent);


		$copyObj->setNew(true);

	}

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

	
	public function setTblblog(Tblblog $v = null)
	{
		if ($v === null) {
			$this->setDpBlog(NULL);
		} else {
			$this->setDpBlog($v->getBlId());
		}

		$this->aTblblog = $v;

						if ($v !== null) {
			$v->addTblblogdepends($this);
		}

		return $this;
	}


	
	public function getTblblog(PropelPDO $con = null)
	{
		if ($this->aTblblog === null && ($this->dp_blog !== null)) {
			$this->aTblblog = TblblogPeer::retrieveByPK($this->dp_blog, $con);
			
		}
		return $this->aTblblog;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
		} 
			$this->aTblblog = null;
	}

} 