<?php


abstract class BaseTblblogPeer {

	
	const DATABASE_NAME = 'propel';

	
	const TABLE_NAME = 'tblblog';

	
	const CLASS_DEFAULT = 'lib.model.Tblblog';

	
	const NUM_COLUMNS = 14;

	
	const NUM_LAZY_LOAD_COLUMNS = 1;

	
	const BL_ID = 'tblblog.BL_ID';

	
	const BL_SHORTNAME = 'tblblog.BL_SHORTNAME';

	
	const BL_TITLE = 'tblblog.BL_TITLE';

	
	const BL_USER = 'tblblog.BL_USER';

	
	const BL_MODULE_CONFIG = 'tblblog.BL_MODULE_CONFIG';

	
	const BL_CATEGORY = 'tblblog.BL_CATEGORY';

	
	const BL_HIT = 'tblblog.BL_HIT';

	
	const BL_TYPE = 'tblblog.BL_TYPE';

	
	const BL_ACTIVE = 'tblblog.BL_ACTIVE';

	
	const BL_LASTUPDATE = 'tblblog.BL_LASTUPDATE';

	
	const BL_SCHOOL = 'tblblog.BL_SCHOOL';

	
	const BL_PAGEVIEWS = 'tblblog.BL_PAGEVIEWS';

	
	const BL_HOST = 'tblblog.BL_HOST';

	
	const BL_COMMEXPIRE = 'tblblog.BL_COMMEXPIRE';

	
	public static $instances = array();

	
	private static $mapBuilder = null;

	
	private static $fieldNames = array (
		BasePeer::TYPE_PHPNAME => array ('BlId', 'BlShortname', 'BlTitle', 'BlUser', 'BlModuleConfig', 'BlCategory', 'BlHit', 'BlType', 'BlActive', 'BlLastupdate', 'BlSchool', 'BlPageviews', 'BlHost', 'BlCommexpire', ),
		BasePeer::TYPE_STUDLYPHPNAME => array ('blId', 'blShortname', 'blTitle', 'blUser', 'blModuleConfig', 'blCategory', 'blHit', 'blType', 'blActive', 'blLastupdate', 'blSchool', 'blPageviews', 'blHost', 'blCommexpire', ),
		BasePeer::TYPE_COLNAME => array (self::BL_ID, self::BL_SHORTNAME, self::BL_TITLE, self::BL_USER, self::BL_MODULE_CONFIG, self::BL_CATEGORY, self::BL_HIT, self::BL_TYPE, self::BL_ACTIVE, self::BL_LASTUPDATE, self::BL_SCHOOL, self::BL_PAGEVIEWS, self::BL_HOST, self::BL_COMMEXPIRE, ),
		BasePeer::TYPE_FIELDNAME => array ('bl_id', 'bl_shortname', 'bl_title', 'bl_user', 'bl_module_config', 'bl_category', 'bl_hit', 'bl_type', 'bl_active', 'bl_lastupdate', 'bl_school', 'bl_pageviews', 'bl_host', 'bl_commexpire', ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, )
	);

	
	private static $fieldKeys = array (
		BasePeer::TYPE_PHPNAME => array ('BlId' => 0, 'BlShortname' => 1, 'BlTitle' => 2, 'BlUser' => 3, 'BlModuleConfig' => 4, 'BlCategory' => 5, 'BlHit' => 6, 'BlType' => 7, 'BlActive' => 8, 'BlLastupdate' => 9, 'BlSchool' => 10, 'BlPageviews' => 11, 'BlHost' => 12, 'BlCommexpire' => 13, ),
		BasePeer::TYPE_STUDLYPHPNAME => array ('blId' => 0, 'blShortname' => 1, 'blTitle' => 2, 'blUser' => 3, 'blModuleConfig' => 4, 'blCategory' => 5, 'blHit' => 6, 'blType' => 7, 'blActive' => 8, 'blLastupdate' => 9, 'blSchool' => 10, 'blPageviews' => 11, 'blHost' => 12, 'blCommexpire' => 13, ),
		BasePeer::TYPE_COLNAME => array (self::BL_ID => 0, self::BL_SHORTNAME => 1, self::BL_TITLE => 2, self::BL_USER => 3, self::BL_MODULE_CONFIG => 4, self::BL_CATEGORY => 5, self::BL_HIT => 6, self::BL_TYPE => 7, self::BL_ACTIVE => 8, self::BL_LASTUPDATE => 9, self::BL_SCHOOL => 10, self::BL_PAGEVIEWS => 11, self::BL_HOST => 12, self::BL_COMMEXPIRE => 13, ),
		BasePeer::TYPE_FIELDNAME => array ('bl_id' => 0, 'bl_shortname' => 1, 'bl_title' => 2, 'bl_user' => 3, 'bl_module_config' => 4, 'bl_category' => 5, 'bl_hit' => 6, 'bl_type' => 7, 'bl_active' => 8, 'bl_lastupdate' => 9, 'bl_school' => 10, 'bl_pageviews' => 11, 'bl_host' => 12, 'bl_commexpire' => 13, ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, )
	);

	
	public static function getMapBuilder()
	{
		if (self::$mapBuilder === null) {
			self::$mapBuilder = new TblblogMapBuilder();
		}
		return self::$mapBuilder;
	}
	
	static public function translateFieldName($name, $fromType, $toType)
	{
		$toNames = self::getFieldNames($toType);
		$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
		if ($key === null) {
			throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
		}
		return $toNames[$key];
	}

	

	static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
	{
		if (!array_key_exists($type, self::$fieldNames)) {
			throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
		}
		return self::$fieldNames[$type];
	}

	
	public static function alias($alias, $column)
	{
		return str_replace(TblblogPeer::TABLE_NAME.'.', $alias.'.', $column);
	}

	
	public static function addSelectColumns(Criteria $criteria)
	{

		$criteria->addSelectColumn(TblblogPeer::BL_ID);

		$criteria->addSelectColumn(TblblogPeer::BL_SHORTNAME);

		$criteria->addSelectColumn(TblblogPeer::BL_TITLE);

		$criteria->addSelectColumn(TblblogPeer::BL_USER);

		$criteria->addSelectColumn(TblblogPeer::BL_CATEGORY);

		$criteria->addSelectColumn(TblblogPeer::BL_HIT);

		$criteria->addSelectColumn(TblblogPeer::BL_TYPE);

		$criteria->addSelectColumn(TblblogPeer::BL_ACTIVE);

		$criteria->addSelectColumn(TblblogPeer::BL_LASTUPDATE);

		$criteria->addSelectColumn(TblblogPeer::BL_SCHOOL);

		$criteria->addSelectColumn(TblblogPeer::BL_PAGEVIEWS);

		$criteria->addSelectColumn(TblblogPeer::BL_HOST);

		$criteria->addSelectColumn(TblblogPeer::BL_COMMEXPIRE);

	}

	
	public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
	{
				$criteria = clone $criteria;

								$criteria->setPrimaryTableName(TblblogPeer::TABLE_NAME);

		if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
			$criteria->setDistinct();
		}

		if (!$criteria->hasSelectClause()) {
			TblblogPeer::addSelectColumns($criteria);
		}

		$criteria->clearOrderByColumns(); 		$criteria->setDbName(self::DATABASE_NAME); 
		if ($con === null) {
			$con = Propel::getConnection(TblblogPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}
				$stmt = BasePeer::doCount($criteria, $con);

		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$count = (int) $row[0];
		} else {
			$count = 0; 		}
		$stmt->closeCursor();
		return $count;
	}
	
	public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
	{
		$critcopy = clone $criteria;
		$critcopy->setLimit(1);
		$objects = TblblogPeer::doSelect($critcopy, $con);
		if ($objects) {
			return $objects[0];
		}
		return null;
	}
	
	public static function doSelect(Criteria $criteria, PropelPDO $con = null)
	{
		return TblblogPeer::populateObjects(TblblogPeer::doSelectStmt($criteria, $con));
	}
	
	public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(TblblogPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

		if (!$criteria->hasSelectClause()) {
			$criteria = clone $criteria;
			TblblogPeer::addSelectColumns($criteria);
		}

				$criteria->setDbName(self::DATABASE_NAME);

				return BasePeer::doSelect($criteria, $con);
	}
	
	public static function addInstanceToPool(Tblblog $obj, $key = null)
	{
		if (Propel::isInstancePoolingEnabled()) {
			if ($key === null) {
				$key = (string) $obj->getBlId();
			} 			self::$instances[$key] = $obj;
		}
	}

	
	public static function removeInstanceFromPool($value)
	{
		if (Propel::isInstancePoolingEnabled() && $value !== null) {
			if (is_object($value) && $value instanceof Tblblog) {
				$key = (string) $value->getBlId();
			} elseif (is_scalar($value)) {
								$key = (string) $value;
			} else {
				$e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or Tblblog object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
				throw $e;
			}

			unset(self::$instances[$key]);
		}
	} 
	
	public static function getInstanceFromPool($key)
	{
		if (Propel::isInstancePoolingEnabled()) {
			if (isset(self::$instances[$key])) {
				return self::$instances[$key];
			}
		}
		return null; 	}
	
	
	public static function clearInstancePool()
	{
		self::$instances = array();
	}
	
	
	public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
	{
				if ($row[$startcol + 0] === null) {
			return null;
		}
		return (string) $row[$startcol + 0];
	}

	
	public static function populateObjects(PDOStatement $stmt)
	{
		$results = array();
	
				$cls = TblblogPeer::getOMClass();
		$cls = substr('.'.$cls, strrpos('.'.$cls, '.') + 1);
				while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$key = TblblogPeer::getPrimaryKeyHashFromRow($row, 0);
			if (null !== ($obj = TblblogPeer::getInstanceFromPool($key))) {
																$results[] = $obj;
			} else {
		
				$obj = new $cls();
				$obj->hydrate($row);
				$results[] = $obj;
				TblblogPeer::addInstanceToPool($obj, $key);
			} 		}
		$stmt->closeCursor();
		return $results;
	}

	
	public static function doCountJoinTbluser(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
				$criteria = clone $criteria;

								$criteria->setPrimaryTableName(TblblogPeer::TABLE_NAME);

		if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
			$criteria->setDistinct();
		}

		if (!$criteria->hasSelectClause()) {
			TblblogPeer::addSelectColumns($criteria);
		}
		
		$criteria->clearOrderByColumns(); 		
				$criteria->setDbName(self::DATABASE_NAME);

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

		$criteria->addJoin(array(TblblogPeer::BL_USER,), array(TbluserPeer::US_ID,), $join_behavior);
		$stmt = BasePeer::doCount($criteria, $con);

		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$count = (int) $row[0];
		} else {
			$count = 0; 		}
		$stmt->closeCursor();
		return $count;
	}


	
	public static function doSelectJoinTbluser(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		$c = clone $c;

				if ($c->getDbName() == Propel::getDefaultDB()) {
			$c->setDbName(self::DATABASE_NAME);
		}

		TblblogPeer::addSelectColumns($c);
		$startcol = (TblblogPeer::NUM_COLUMNS - TblblogPeer::NUM_LAZY_LOAD_COLUMNS);
		TbluserPeer::addSelectColumns($c);

		$c->addJoin(array(TblblogPeer::BL_USER,), array(TbluserPeer::US_ID,), $join_behavior);
		$stmt = BasePeer::doSelect($c, $con);
		$results = array();

		while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$key1 = TblblogPeer::getPrimaryKeyHashFromRow($row, 0);
			if (null !== ($obj1 = TblblogPeer::getInstanceFromPool($key1))) {
															} else {

				$omClass = TblblogPeer::getOMClass();

				$cls = substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1);
				$obj1 = new $cls();
				$obj1->hydrate($row);
				TblblogPeer::addInstanceToPool($obj1, $key1);
			} 
			$key2 = TbluserPeer::getPrimaryKeyHashFromRow($row, $startcol);
			if ($key2 !== null) {
				$obj2 = TbluserPeer::getInstanceFromPool($key2);
				if (!$obj2) {

					$omClass = TbluserPeer::getOMClass();

					$cls = substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1);
					$obj2 = new $cls();
					$obj2->hydrate($row, $startcol);
					TbluserPeer::addInstanceToPool($obj2, $key2);
				} 
								$obj2->addTblblog($obj1);

			} 
			$results[] = $obj1;
		}
		$stmt->closeCursor();
		return $results;
	}


	
	public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
				$criteria = clone $criteria;

								$criteria->setPrimaryTableName(TblblogPeer::TABLE_NAME);

		if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
			$criteria->setDistinct();
		}

		if (!$criteria->hasSelectClause()) {
			TblblogPeer::addSelectColumns($criteria);
		}
		
		$criteria->clearOrderByColumns(); 		
				$criteria->setDbName(self::DATABASE_NAME);

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

		$criteria->addJoin(array(TblblogPeer::BL_USER,), array(TbluserPeer::US_ID,), $join_behavior);
		$stmt = BasePeer::doCount($criteria, $con);

		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$count = (int) $row[0];
		} else {
			$count = 0; 		}
		$stmt->closeCursor();
		return $count;
	}

	
	public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		$c = clone $c;

				if ($c->getDbName() == Propel::getDefaultDB()) {
			$c->setDbName(self::DATABASE_NAME);
		}

		TblblogPeer::addSelectColumns($c);
		$startcol2 = (TblblogPeer::NUM_COLUMNS - TblblogPeer::NUM_LAZY_LOAD_COLUMNS);

		TbluserPeer::addSelectColumns($c);
		$startcol3 = $startcol2 + (TbluserPeer::NUM_COLUMNS - TbluserPeer::NUM_LAZY_LOAD_COLUMNS);

		$c->addJoin(array(TblblogPeer::BL_USER,), array(TbluserPeer::US_ID,), $join_behavior);
		$stmt = BasePeer::doSelect($c, $con);
		$results = array();

		while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$key1 = TblblogPeer::getPrimaryKeyHashFromRow($row, 0);
			if (null !== ($obj1 = TblblogPeer::getInstanceFromPool($key1))) {
															} else {
				$omClass = TblblogPeer::getOMClass();

				$cls = substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1);
				$obj1 = new $cls();
				$obj1->hydrate($row);
				TblblogPeer::addInstanceToPool($obj1, $key1);
			} 
			
			$key2 = TbluserPeer::getPrimaryKeyHashFromRow($row, $startcol2);
			if ($key2 !== null) {
				$obj2 = TbluserPeer::getInstanceFromPool($key2);
				if (!$obj2) {

					$omClass = TbluserPeer::getOMClass();


					$cls = substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1);
					$obj2 = new $cls();
					$obj2->hydrate($row, $startcol2);
					TbluserPeer::addInstanceToPool($obj2, $key2);
				} 
								$obj2->addTblblog($obj1);
			} 
			$results[] = $obj1;
		}
		$stmt->closeCursor();
		return $results;
	}

	
	public static function getTableMap()
	{
		return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
	}

	
	public static function getOMClass()
	{
		return TblblogPeer::CLASS_DEFAULT;
	}

	
	public static function doInsert($values, PropelPDO $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(TblblogPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		if ($values instanceof Criteria) {
			$criteria = clone $values; 		} else {
			$criteria = $values->buildCriteria(); 		}

		if ($criteria->containsKey(TblblogPeer::BL_ID) && $criteria->keyContainsValue(TblblogPeer::BL_ID) ) {
			throw new PropelException('Cannot insert a value for auto-increment primary key ('.TblblogPeer::BL_ID.')');
		}


				$criteria->setDbName(self::DATABASE_NAME);

		try {
									$con->beginTransaction();
			$pk = BasePeer::doInsert($criteria, $con);
			$con->commit();
		} catch(PropelException $e) {
			$con->rollBack();
			throw $e;
		}

		return $pk;
	}

	
	public static function doUpdate($values, PropelPDO $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(TblblogPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		$selectCriteria = new Criteria(self::DATABASE_NAME);

		if ($values instanceof Criteria) {
			$criteria = clone $values; 
			$comparison = $criteria->getComparison(TblblogPeer::BL_ID);
			$selectCriteria->add(TblblogPeer::BL_ID, $criteria->remove(TblblogPeer::BL_ID), $comparison);

		} else { 			$criteria = $values->buildCriteria(); 			$selectCriteria = $values->buildPkeyCriteria(); 		}

				$criteria->setDbName(self::DATABASE_NAME);

		return BasePeer::doUpdate($selectCriteria, $criteria, $con);
	}

	
	public static function doDeleteAll($con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(TblblogPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		$affectedRows = 0; 		try {
									$con->beginTransaction();
			$affectedRows += BasePeer::doDeleteAll(TblblogPeer::TABLE_NAME, $con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	 public static function doDelete($values, PropelPDO $con = null)
	 {
		if ($con === null) {
			$con = Propel::getConnection(TblblogPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		if ($values instanceof Criteria) {
												TblblogPeer::clearInstancePool();

						$criteria = clone $values;
		} elseif ($values instanceof Tblblog) {
						TblblogPeer::removeInstanceFromPool($values);
						$criteria = $values->buildPkeyCriteria();
		} else {
			


			$criteria = new Criteria(self::DATABASE_NAME);
			$criteria->add(TblblogPeer::BL_ID, (array) $values, Criteria::IN);

			foreach ((array) $values as $singleval) {
								TblblogPeer::removeInstanceFromPool($singleval);
			}
		}

				$criteria->setDbName(self::DATABASE_NAME);

		$affectedRows = 0; 
		try {
									$con->beginTransaction();
			
			$affectedRows += BasePeer::doDelete($criteria, $con);

			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public static function doValidate(Tblblog $obj, $cols = null)
	{
		$columns = array();

		if ($cols) {
			$dbMap = Propel::getDatabaseMap(TblblogPeer::DATABASE_NAME);
			$tableMap = $dbMap->getTable(TblblogPeer::TABLE_NAME);

			if (! is_array($cols)) {
				$cols = array($cols);
			}

			foreach ($cols as $colName) {
				if ($tableMap->containsColumn($colName)) {
					$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
					$columns[$colName] = $obj->$get();
				}
			}
		} else {

		}

		$res =  BasePeer::doValidate(TblblogPeer::DATABASE_NAME, TblblogPeer::TABLE_NAME, $columns);
    if ($res !== true) {
        $request = sfContext::getInstance()->getRequest();
        foreach ($res as $failed) {
            $col = TblblogPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
            $request->setError($col, $failed->getMessage());
        }
    }

    return $res;
	}

	
	public static function retrieveByPK($pk, PropelPDO $con = null)
	{

		if (null !== ($obj = TblblogPeer::getInstanceFromPool((string) $pk))) {
			return $obj;
		}

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

		$criteria = new Criteria(TblblogPeer::DATABASE_NAME);
		$criteria->add(TblblogPeer::BL_ID, $pk);

		$v = TblblogPeer::doSelect($criteria, $con);

		return !empty($v) > 0 ? $v[0] : null;
	}

	
	public static function retrieveByPKs($pks, PropelPDO $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(TblblogPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

		$objs = null;
		if (empty($pks)) {
			$objs = array();
		} else {
			$criteria = new Criteria(TblblogPeer::DATABASE_NAME);
			$criteria->add(TblblogPeer::BL_ID, $pks, Criteria::IN);
			$objs = TblblogPeer::doSelect($criteria, $con);
		}
		return $objs;
	}

} 

Propel::getDatabaseMap(BaseTblblogPeer::DATABASE_NAME)->addTableBuilder(BaseTblblogPeer::TABLE_NAME, BaseTblblogPeer::getMapBuilder());

