<?php


abstract class BaseTblbloguser extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $us_blog;

	
	protected $us_user;

	
	protected $us_role;

	
	protected $us_categories;

	
	protected $us_picture;

	
	protected $us_lastvisit;

	
	protected $us_joindate;

	
	protected $us_fullname;

	
	protected $us_nickname;

	
	protected $us_email;

	
	protected $us_managecat;

	
	protected $aTbluser;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

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

	
	public function applyDefaultValues()
	{
	}

	
	public function getUsBlog()
	{
		return $this->us_blog;
	}

	
	public function getUsUser()
	{
		return $this->us_user;
	}

	
	public function getUsRole()
	{
		return $this->us_role;
	}

	
	public function getUsCategories()
	{
		return $this->us_categories;
	}

	
	public function getUsPicture()
	{
		return $this->us_picture;
	}

	
	public function getUsLastvisit($format = 'Y-m-d H:i:s')
	{
		if ($this->us_lastvisit === null) {
			return null;
		}


		if ($this->us_lastvisit === '0000-00-00 00:00:00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->us_lastvisit);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->us_lastvisit, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getUsJoindate($format = 'Y-m-d H:i:s')
	{
		if ($this->us_joindate === null) {
			return null;
		}


		if ($this->us_joindate === '0000-00-00 00:00:00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->us_joindate);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->us_joindate, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getUsFullname()
	{
		return $this->us_fullname;
	}

	
	public function getUsNickname()
	{
		return $this->us_nickname;
	}

	
	public function getUsEmail()
	{
		return $this->us_email;
	}

	
	public function getUsManagecat()
	{
		return $this->us_managecat;
	}

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

		if ($this->us_blog !== $v) {
			$this->us_blog = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_BLOG;
		}

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

		if ($this->us_user !== $v) {
			$this->us_user = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_USER;
		}

		if ($this->aTbluser !== null && $this->aTbluser->getUsId() !== $v) {
			$this->aTbluser = null;
		}

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

		if ($this->us_role !== $v) {
			$this->us_role = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_ROLE;
		}

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

		if ($this->us_categories !== $v) {
			$this->us_categories = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_CATEGORIES;
		}

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

		if ($this->us_picture !== $v) {
			$this->us_picture = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_PICTURE;
		}

		return $this;
	} 
	
	public function setUsLastvisit($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->us_lastvisit !== null || $dt !== null ) {
			
			$currNorm = ($this->us_lastvisit !== null && $tmpDt = new DateTime($this->us_lastvisit)) ? $tmpDt->format('Y-m-d H:i:s') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->us_lastvisit = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = TblbloguserPeer::US_LASTVISIT;
			}
		} 
		return $this;
	} 
	
	public function setUsJoindate($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->us_joindate !== null || $dt !== null ) {
			
			$currNorm = ($this->us_joindate !== null && $tmpDt = new DateTime($this->us_joindate)) ? $tmpDt->format('Y-m-d H:i:s') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->us_joindate = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = TblbloguserPeer::US_JOINDATE;
			}
		} 
		return $this;
	} 
	
	public function setUsFullname($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->us_fullname !== $v) {
			$this->us_fullname = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_FULLNAME;
		}

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

		if ($this->us_nickname !== $v) {
			$this->us_nickname = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_NICKNAME;
		}

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

		if ($this->us_email !== $v) {
			$this->us_email = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_EMAIL;
		}

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

		if ($this->us_managecat !== $v) {
			$this->us_managecat = $v;
			$this->modifiedColumns[] = TblbloguserPeer::US_MANAGECAT;
		}

		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->us_blog = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->us_user = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->us_role = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
			$this->us_categories = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->us_picture = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->us_lastvisit = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->us_joindate = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
			$this->us_fullname = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->us_nickname = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
			$this->us_email = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
			$this->us_managecat = ($row[$startcol + 10] !== null) ? (string) $row[$startcol + 10] : null;
			$this->resetModified();

			$this->setNew(false);

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

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

	
	public function ensureConsistency()
	{

		if ($this->aTbluser !== null && $this->us_user !== $this->aTbluser->getUsId()) {
			$this->aTbluser = 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(TblbloguserPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

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


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


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

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getUsBlog();
				break;
			case 1:
				return $this->getUsUser();
				break;
			case 2:
				return $this->getUsRole();
				break;
			case 3:
				return $this->getUsCategories();
				break;
			case 4:
				return $this->getUsPicture();
				break;
			case 5:
				return $this->getUsLastvisit();
				break;
			case 6:
				return $this->getUsJoindate();
				break;
			case 7:
				return $this->getUsFullname();
				break;
			case 8:
				return $this->getUsNickname();
				break;
			case 9:
				return $this->getUsEmail();
				break;
			case 10:
				return $this->getUsManagecat();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblbloguserPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getUsBlog(),
			$keys[1] => $this->getUsUser(),
			$keys[2] => $this->getUsRole(),
			$keys[3] => $this->getUsCategories(),
			$keys[4] => $this->getUsPicture(),
			$keys[5] => $this->getUsLastvisit(),
			$keys[6] => $this->getUsJoindate(),
			$keys[7] => $this->getUsFullname(),
			$keys[8] => $this->getUsNickname(),
			$keys[9] => $this->getUsEmail(),
			$keys[10] => $this->getUsManagecat(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setUsBlog($value);
				break;
			case 1:
				$this->setUsUser($value);
				break;
			case 2:
				$this->setUsRole($value);
				break;
			case 3:
				$this->setUsCategories($value);
				break;
			case 4:
				$this->setUsPicture($value);
				break;
			case 5:
				$this->setUsLastvisit($value);
				break;
			case 6:
				$this->setUsJoindate($value);
				break;
			case 7:
				$this->setUsFullname($value);
				break;
			case 8:
				$this->setUsNickname($value);
				break;
			case 9:
				$this->setUsEmail($value);
				break;
			case 10:
				$this->setUsManagecat($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setUsBlog($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUsUser($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setUsRole($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setUsCategories($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setUsPicture($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setUsLastvisit($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setUsJoindate($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setUsFullname($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setUsNickname($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setUsEmail($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setUsManagecat($arr[$keys[10]]);
	}

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

		if ($this->isColumnModified(TblbloguserPeer::US_BLOG)) $criteria->add(TblbloguserPeer::US_BLOG, $this->us_blog);
		if ($this->isColumnModified(TblbloguserPeer::US_USER)) $criteria->add(TblbloguserPeer::US_USER, $this->us_user);
		if ($this->isColumnModified(TblbloguserPeer::US_ROLE)) $criteria->add(TblbloguserPeer::US_ROLE, $this->us_role);
		if ($this->isColumnModified(TblbloguserPeer::US_CATEGORIES)) $criteria->add(TblbloguserPeer::US_CATEGORIES, $this->us_categories);
		if ($this->isColumnModified(TblbloguserPeer::US_PICTURE)) $criteria->add(TblbloguserPeer::US_PICTURE, $this->us_picture);
		if ($this->isColumnModified(TblbloguserPeer::US_LASTVISIT)) $criteria->add(TblbloguserPeer::US_LASTVISIT, $this->us_lastvisit);
		if ($this->isColumnModified(TblbloguserPeer::US_JOINDATE)) $criteria->add(TblbloguserPeer::US_JOINDATE, $this->us_joindate);
		if ($this->isColumnModified(TblbloguserPeer::US_FULLNAME)) $criteria->add(TblbloguserPeer::US_FULLNAME, $this->us_fullname);
		if ($this->isColumnModified(TblbloguserPeer::US_NICKNAME)) $criteria->add(TblbloguserPeer::US_NICKNAME, $this->us_nickname);
		if ($this->isColumnModified(TblbloguserPeer::US_EMAIL)) $criteria->add(TblbloguserPeer::US_EMAIL, $this->us_email);
		if ($this->isColumnModified(TblbloguserPeer::US_MANAGECAT)) $criteria->add(TblbloguserPeer::US_MANAGECAT, $this->us_managecat);

		return $criteria;
	}

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

		$criteria->add(TblbloguserPeer::US_BLOG, $this->us_blog);
		$criteria->add(TblbloguserPeer::US_USER, $this->us_user);

		return $criteria;
	}

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

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

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

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

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

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

	}

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

		$copyObj->setUsBlog($this->us_blog);

		$copyObj->setUsUser($this->us_user);

		$copyObj->setUsRole($this->us_role);

		$copyObj->setUsCategories($this->us_categories);

		$copyObj->setUsPicture($this->us_picture);

		$copyObj->setUsLastvisit($this->us_lastvisit);

		$copyObj->setUsJoindate($this->us_joindate);

		$copyObj->setUsFullname($this->us_fullname);

		$copyObj->setUsNickname($this->us_nickname);

		$copyObj->setUsEmail($this->us_email);

		$copyObj->setUsManagecat($this->us_managecat);


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

	
	public function setTbluser(Tbluser $v = null)
	{
		if ($v === null) {
			$this->setUsUser(NULL);
		} else {
			$this->setUsUser($v->getUsId());
		}

		$this->aTbluser = $v;

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

		return $this;
	}


	
	public function getTbluser(PropelPDO $con = null)
	{
		if ($this->aTbluser === null && ($this->us_user !== null)) {
			$this->aTbluser = TbluserPeer::retrieveByPK($this->us_user, $con);
			
		}
		return $this->aTbluser;
	}

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

} 