<?php


abstract class BaseTblscormcmiinteractionPeer {

	
	const DATABASE_NAME = 'propel';

	
	const TABLE_NAME = 'tblscormcmiinteraction';

	
	const CLASS_DEFAULT = 'lib.model.Tblscormcmiinteraction';

	
	const NUM_COLUMNS = 10;

	
	const NUM_LAZY_LOAD_COLUMNS = 0;

	
	const CMI_INTERACTION_ID = 'tblscormcmiinteraction.CMI_INTERACTION_ID';

	
	const CMI_NODE_ID = 'tblscormcmiinteraction.CMI_NODE_ID';

	
	const DESCRIPTION = 'tblscormcmiinteraction.DESCRIPTION';

	
	const ID = 'tblscormcmiinteraction.ID';

	
	const LATENCY = 'tblscormcmiinteraction.LATENCY';

	
	const LEARNER_RESPONSE = 'tblscormcmiinteraction.LEARNER_RESPONSE';

	
	const RESULT = 'tblscormcmiinteraction.RESULT';

	
	const C_TIMESTAMP = 'tblscormcmiinteraction.C_TIMESTAMP';

	
	const C_TYPE = 'tblscormcmiinteraction.C_TYPE';

	
	const WEIGHTING = 'tblscormcmiinteraction.WEIGHTING';

	
	public static $instances = array();

	
	private static $mapBuilder = null;

	
	private static $fieldNames = array (
		BasePeer::TYPE_PHPNAME => array ('CmiInteractionId', 'CmiNodeId', 'Description', 'Id', 'Latency', 'LearnerResponse', 'Result', 'CTimestamp', 'CType', 'Weighting', ),
		BasePeer::TYPE_STUDLYPHPNAME => array ('cmiInteractionId', 'cmiNodeId', 'description', 'id', 'latency', 'learnerResponse', 'result', 'cTimestamp', 'cType', 'weighting', ),
		BasePeer::TYPE_COLNAME => array (self::CMI_INTERACTION_ID, self::CMI_NODE_ID, self::DESCRIPTION, self::ID, self::LATENCY, self::LEARNER_RESPONSE, self::RESULT, self::C_TIMESTAMP, self::C_TYPE, self::WEIGHTING, ),
		BasePeer::TYPE_FIELDNAME => array ('cmi_interaction_id', 'cmi_node_id', 'description', 'id', 'latency', 'learner_response', 'result', 'c_timestamp', 'c_type', 'weighting', ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
	);

	
	private static $fieldKeys = array (
		BasePeer::TYPE_PHPNAME => array ('CmiInteractionId' => 0, 'CmiNodeId' => 1, 'Description' => 2, 'Id' => 3, 'Latency' => 4, 'LearnerResponse' => 5, 'Result' => 6, 'CTimestamp' => 7, 'CType' => 8, 'Weighting' => 9, ),
		BasePeer::TYPE_STUDLYPHPNAME => array ('cmiInteractionId' => 0, 'cmiNodeId' => 1, 'description' => 2, 'id' => 3, 'latency' => 4, 'learnerResponse' => 5, 'result' => 6, 'cTimestamp' => 7, 'cType' => 8, 'weighting' => 9, ),
		BasePeer::TYPE_COLNAME => array (self::CMI_INTERACTION_ID => 0, self::CMI_NODE_ID => 1, self::DESCRIPTION => 2, self::ID => 3, self::LATENCY => 4, self::LEARNER_RESPONSE => 5, self::RESULT => 6, self::C_TIMESTAMP => 7, self::C_TYPE => 8, self::WEIGHTING => 9, ),
		BasePeer::TYPE_FIELDNAME => array ('cmi_interaction_id' => 0, 'cmi_node_id' => 1, 'description' => 2, 'id' => 3, 'latency' => 4, 'learner_response' => 5, 'result' => 6, 'c_timestamp' => 7, 'c_type' => 8, 'weighting' => 9, ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
	);

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

	
	public static function addSelectColumns(Criteria $criteria)
	{

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::CMI_INTERACTION_ID);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::CMI_NODE_ID);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::DESCRIPTION);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::ID);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::LATENCY);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::LEARNER_RESPONSE);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::RESULT);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::C_TIMESTAMP);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::C_TYPE);

		$criteria->addSelectColumn(TblscormcmiinteractionPeer::WEIGHTING);

	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

		$criteria = new Criteria(TblscormcmiinteractionPeer::DATABASE_NAME);
		$criteria->add(TblscormcmiinteractionPeer::CMI_INTERACTION_ID, $pk);

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

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

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

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

} 

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

