<?php


abstract class BaseTbluserPeer {

	
	const DATABASE_NAME = 'propel';

	
	const TABLE_NAME = 'tbluser';

	
	const CLASS_DEFAULT = 'lib.model.Tbluser';

	
	const NUM_COLUMNS = 25;

	
	const NUM_LAZY_LOAD_COLUMNS = 0;

	
	const US_ID = 'tbluser.US_ID';

	
	const US_USERNAME = 'tbluser.US_USERNAME';

	
	const US_PASSWORD = 'tbluser.US_PASSWORD';

	
	const US_FIRSTNAME = 'tbluser.US_FIRSTNAME';

	
	const US_LASTNAME = 'tbluser.US_LASTNAME';

	
	const US_SEX = 'tbluser.US_SEX';

	
	const US_EMAIL = 'tbluser.US_EMAIL';

	
	const US_PHONE = 'tbluser.US_PHONE';

	
	const US_ACLGROUP = 'tbluser.US_ACLGROUP';

	
	const US_SCHOOL = 'tbluser.US_SCHOOL';

	
	const US_PROVINCE = 'tbluser.US_PROVINCE';

	
	const US_LASTVISITED = 'tbluser.US_LASTVISITED';

	
	const US_REGISTERDATE = 'tbluser.US_REGISTERDATE';

	
	const US_RATING = 'tbluser.US_RATING';

	
	const US_DOWNLOAD = 'tbluser.US_DOWNLOAD';

	
	const US_AVATAR = 'tbluser.US_AVATAR';

	
	const US_STATUS = 'tbluser.US_STATUS';

	
	const US_KEY = 'tbluser.US_KEY';

	
	const US_SCORE = 'tbluser.US_SCORE';

	
	const US_POINTPLUS = 'tbluser.US_POINTPLUS';

	
	const US_CHECKED = 'tbluser.US_CHECKED';

	
	const US_CHECKINFO = 'tbluser.US_CHECKINFO';

	
	const US_IDMD5 = 'tbluser.US_IDMD5';

	
	const US_HOMEPAGE = 'tbluser.US_HOMEPAGE';

	
	const US_MONEY = 'tbluser.US_MONEY';

	
	public static $instances = array();

	
	private static $mapBuilder = null;

	
	private static $fieldNames = array (
		BasePeer::TYPE_PHPNAME => array ('UsId', 'UsUsername', 'UsPassword', 'UsFirstname', 'UsLastname', 'UsSex', 'UsEmail', 'UsPhone', 'UsAclgroup', 'UsSchool', 'UsProvince', 'UsLastvisited', 'UsRegisterdate', 'UsRating', 'UsDownload', 'UsAvatar', 'UsStatus', 'UsKey', 'UsScore', 'UsPointplus', 'UsChecked', 'UsCheckinfo', 'UsIdmd5', 'UsHomepage', 'UsMoney', ),
		BasePeer::TYPE_STUDLYPHPNAME => array ('usId', 'usUsername', 'usPassword', 'usFirstname', 'usLastname', 'usSex', 'usEmail', 'usPhone', 'usAclgroup', 'usSchool', 'usProvince', 'usLastvisited', 'usRegisterdate', 'usRating', 'usDownload', 'usAvatar', 'usStatus', 'usKey', 'usScore', 'usPointplus', 'usChecked', 'usCheckinfo', 'usIdmd5', 'usHomepage', 'usMoney', ),
		BasePeer::TYPE_COLNAME => array (self::US_ID, self::US_USERNAME, self::US_PASSWORD, self::US_FIRSTNAME, self::US_LASTNAME, self::US_SEX, self::US_EMAIL, self::US_PHONE, self::US_ACLGROUP, self::US_SCHOOL, self::US_PROVINCE, self::US_LASTVISITED, self::US_REGISTERDATE, self::US_RATING, self::US_DOWNLOAD, self::US_AVATAR, self::US_STATUS, self::US_KEY, self::US_SCORE, self::US_POINTPLUS, self::US_CHECKED, self::US_CHECKINFO, self::US_IDMD5, self::US_HOMEPAGE, self::US_MONEY, ),
		BasePeer::TYPE_FIELDNAME => array ('us_id', 'us_username', 'us_password', 'us_firstname', 'us_lastname', 'us_sex', 'us_email', 'us_phone', 'us_aclgroup', 'us_school', 'us_province', 'us_lastvisited', 'us_registerdate', 'us_rating', 'us_download', 'us_avatar', 'us_status', 'us_key', 'us_score', 'us_pointplus', 'us_checked', 'us_checkinfo', 'us_idmd5', 'us_homepage', 'us_money', ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, )
	);

	
	private static $fieldKeys = array (
		BasePeer::TYPE_PHPNAME => array ('UsId' => 0, 'UsUsername' => 1, 'UsPassword' => 2, 'UsFirstname' => 3, 'UsLastname' => 4, 'UsSex' => 5, 'UsEmail' => 6, 'UsPhone' => 7, 'UsAclgroup' => 8, 'UsSchool' => 9, 'UsProvince' => 10, 'UsLastvisited' => 11, 'UsRegisterdate' => 12, 'UsRating' => 13, 'UsDownload' => 14, 'UsAvatar' => 15, 'UsStatus' => 16, 'UsKey' => 17, 'UsScore' => 18, 'UsPointplus' => 19, 'UsChecked' => 20, 'UsCheckinfo' => 21, 'UsIdmd5' => 22, 'UsHomepage' => 23, 'UsMoney' => 24, ),
		BasePeer::TYPE_STUDLYPHPNAME => array ('usId' => 0, 'usUsername' => 1, 'usPassword' => 2, 'usFirstname' => 3, 'usLastname' => 4, 'usSex' => 5, 'usEmail' => 6, 'usPhone' => 7, 'usAclgroup' => 8, 'usSchool' => 9, 'usProvince' => 10, 'usLastvisited' => 11, 'usRegisterdate' => 12, 'usRating' => 13, 'usDownload' => 14, 'usAvatar' => 15, 'usStatus' => 16, 'usKey' => 17, 'usScore' => 18, 'usPointplus' => 19, 'usChecked' => 20, 'usCheckinfo' => 21, 'usIdmd5' => 22, 'usHomepage' => 23, 'usMoney' => 24, ),
		BasePeer::TYPE_COLNAME => array (self::US_ID => 0, self::US_USERNAME => 1, self::US_PASSWORD => 2, self::US_FIRSTNAME => 3, self::US_LASTNAME => 4, self::US_SEX => 5, self::US_EMAIL => 6, self::US_PHONE => 7, self::US_ACLGROUP => 8, self::US_SCHOOL => 9, self::US_PROVINCE => 10, self::US_LASTVISITED => 11, self::US_REGISTERDATE => 12, self::US_RATING => 13, self::US_DOWNLOAD => 14, self::US_AVATAR => 15, self::US_STATUS => 16, self::US_KEY => 17, self::US_SCORE => 18, self::US_POINTPLUS => 19, self::US_CHECKED => 20, self::US_CHECKINFO => 21, self::US_IDMD5 => 22, self::US_HOMEPAGE => 23, self::US_MONEY => 24, ),
		BasePeer::TYPE_FIELDNAME => array ('us_id' => 0, 'us_username' => 1, 'us_password' => 2, 'us_firstname' => 3, 'us_lastname' => 4, 'us_sex' => 5, 'us_email' => 6, 'us_phone' => 7, 'us_aclgroup' => 8, 'us_school' => 9, 'us_province' => 10, 'us_lastvisited' => 11, 'us_registerdate' => 12, 'us_rating' => 13, 'us_download' => 14, 'us_avatar' => 15, 'us_status' => 16, 'us_key' => 17, 'us_score' => 18, 'us_pointplus' => 19, 'us_checked' => 20, 'us_checkinfo' => 21, 'us_idmd5' => 22, 'us_homepage' => 23, 'us_money' => 24, ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, )
	);

	
	public static function getMapBuilder()
	{
		if (self::$mapBuilder === null) {
			self::$mapBuilder = new TbluserMapBuilder();
		}
		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(TbluserPeer::TABLE_NAME.'.', $alias.'.', $column);
	}

	
	public static function addSelectColumns(Criteria $criteria)
	{

		$criteria->addSelectColumn(TbluserPeer::US_ID);

		$criteria->addSelectColumn(TbluserPeer::US_USERNAME);

		$criteria->addSelectColumn(TbluserPeer::US_PASSWORD);

		$criteria->addSelectColumn(TbluserPeer::US_FIRSTNAME);

		$criteria->addSelectColumn(TbluserPeer::US_LASTNAME);

		$criteria->addSelectColumn(TbluserPeer::US_SEX);

		$criteria->addSelectColumn(TbluserPeer::US_EMAIL);

		$criteria->addSelectColumn(TbluserPeer::US_PHONE);

		$criteria->addSelectColumn(TbluserPeer::US_ACLGROUP);

		$criteria->addSelectColumn(TbluserPeer::US_SCHOOL);

		$criteria->addSelectColumn(TbluserPeer::US_PROVINCE);

		$criteria->addSelectColumn(TbluserPeer::US_LASTVISITED);

		$criteria->addSelectColumn(TbluserPeer::US_REGISTERDATE);

		$criteria->addSelectColumn(TbluserPeer::US_RATING);

		$criteria->addSelectColumn(TbluserPeer::US_DOWNLOAD);

		$criteria->addSelectColumn(TbluserPeer::US_AVATAR);

		$criteria->addSelectColumn(TbluserPeer::US_STATUS);

		$criteria->addSelectColumn(TbluserPeer::US_KEY);

		$criteria->addSelectColumn(TbluserPeer::US_SCORE);

		$criteria->addSelectColumn(TbluserPeer::US_POINTPLUS);

		$criteria->addSelectColumn(TbluserPeer::US_CHECKED);

		$criteria->addSelectColumn(TbluserPeer::US_CHECKINFO);

		$criteria->addSelectColumn(TbluserPeer::US_IDMD5);

		$criteria->addSelectColumn(TbluserPeer::US_HOMEPAGE);

		$criteria->addSelectColumn(TbluserPeer::US_MONEY);

	}

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

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

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

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

		$criteria->clearOrderByColumns(); 		$criteria->setDbName(self::DATABASE_NAME); 
		if ($con === null) {
			$con = Propel::getConnection(TbluserPeer::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 = TbluserPeer::doSelect($critcopy, $con);
		if ($objects) {
			return $objects[0];
		}
		return null;
	}
	
	public static function doSelect(Criteria $criteria, PropelPDO $con = null)
	{
		return TbluserPeer::populateObjects(TbluserPeer::doSelectStmt($criteria, $con));
	}
	
	public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(TbluserPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

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

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

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

	
	public static function removeInstanceFromPool($value)
	{
		if (Propel::isInstancePoolingEnabled() && $value !== null) {
			if (is_object($value) && $value instanceof Tbluser) {
				$key = (string) $value->getUsId();
			} elseif (is_scalar($value)) {
								$key = (string) $value;
			} else {
				$e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or Tbluser 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 = TbluserPeer::getOMClass();
		$cls = substr('.'.$cls, strrpos('.'.$cls, '.') + 1);
				while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$key = TbluserPeer::getPrimaryKeyHashFromRow($row, 0);
			if (null !== ($obj = TbluserPeer::getInstanceFromPool($key))) {
																$results[] = $obj;
			} else {
		
				$obj = new $cls();
				$obj->hydrate($row);
				$results[] = $obj;
				TbluserPeer::addInstanceToPool($obj, $key);
			} 		}
		$stmt->closeCursor();
		return $results;
	}
	
	public static function getTableMap()
	{
		return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
	}

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

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

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

		if ($criteria->containsKey(TbluserPeer::US_ID) && $criteria->keyContainsValue(TbluserPeer::US_ID) ) {
			throw new PropelException('Cannot insert a value for auto-increment primary key ('.TbluserPeer::US_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(TbluserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

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

		if ($values instanceof Criteria) {
			$criteria = clone $values; 
			$comparison = $criteria->getComparison(TbluserPeer::US_ID);
			$selectCriteria->add(TbluserPeer::US_ID, $criteria->remove(TbluserPeer::US_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(TbluserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		$affectedRows = 0; 		try {
									$con->beginTransaction();
			$affectedRows += BasePeer::doDeleteAll(TbluserPeer::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(TbluserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

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

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


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

			foreach ((array) $values as $singleval) {
								TbluserPeer::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(Tbluser $obj, $cols = null)
	{
		$columns = array();

		if ($cols) {
			$dbMap = Propel::getDatabaseMap(TbluserPeer::DATABASE_NAME);
			$tableMap = $dbMap->getTable(TbluserPeer::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(TbluserPeer::DATABASE_NAME, TbluserPeer::TABLE_NAME, $columns);
    if ($res !== true) {
        $request = sfContext::getInstance()->getRequest();
        foreach ($res as $failed) {
            $col = TbluserPeer::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 = TbluserPeer::getInstanceFromPool((string) $pk))) {
			return $obj;
		}

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

		$criteria = new Criteria(TbluserPeer::DATABASE_NAME);
		$criteria->add(TbluserPeer::US_ID, $pk);

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

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

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

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

} 

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

