<?php


abstract class BaseTblscormcpnode extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $cp_node_id;

	
	protected $nodename;

	
	protected $slm_id;

	
	protected $collTblscormcminodes;

	
	private $lastTblscormcminodeCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

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

	
	public function applyDefaultValues()
	{
	}

	
	public function getCpNodeId()
	{
		return $this->cp_node_id;
	}

	
	public function getNodename()
	{
		return $this->nodename;
	}

	
	public function getSlmId()
	{
		return $this->slm_id;
	}

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

		if ($this->cp_node_id !== $v) {
			$this->cp_node_id = $v;
			$this->modifiedColumns[] = TblscormcpnodePeer::CP_NODE_ID;
		}

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

		if ($this->nodename !== $v) {
			$this->nodename = $v;
			$this->modifiedColumns[] = TblscormcpnodePeer::NODENAME;
		}

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

		if ($this->slm_id !== $v) {
			$this->slm_id = $v;
			$this->modifiedColumns[] = TblscormcpnodePeer::SLM_ID;
		}

		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->cp_node_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->nodename = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->slm_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
			$this->resetModified();

			$this->setNew(false);

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

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

	
	public function ensureConsistency()
	{

	} 
	
	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(TblscormcpnodePeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = TblscormcpnodePeer::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->collTblscormcminodes = null;
			$this->lastTblscormcminodeCriteria = 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(TblscormcpnodePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblscormcpnodePeer::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(TblscormcpnodePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblscormcpnodePeer::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->isNew() ) {
				$this->modifiedColumns[] = TblscormcpnodePeer::CP_NODE_ID;
			}

						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TblscormcpnodePeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setCpNodeId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TblscormcpnodePeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->collTblscormcminodes !== null) {
				foreach ($this->collTblscormcminodes as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$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 (($retval = TblscormcpnodePeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collTblscormcminodes !== null) {
					foreach ($this->collTblscormcminodes as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TblscormcpnodePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCpNodeId();
				break;
			case 1:
				return $this->getNodename();
				break;
			case 2:
				return $this->getSlmId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblscormcpnodePeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCpNodeId(),
			$keys[1] => $this->getNodename(),
			$keys[2] => $this->getSlmId(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCpNodeId($value);
				break;
			case 1:
				$this->setNodename($value);
				break;
			case 2:
				$this->setSlmId($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setCpNodeId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setNodename($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setSlmId($arr[$keys[2]]);
	}

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

		if ($this->isColumnModified(TblscormcpnodePeer::CP_NODE_ID)) $criteria->add(TblscormcpnodePeer::CP_NODE_ID, $this->cp_node_id);
		if ($this->isColumnModified(TblscormcpnodePeer::NODENAME)) $criteria->add(TblscormcpnodePeer::NODENAME, $this->nodename);
		if ($this->isColumnModified(TblscormcpnodePeer::SLM_ID)) $criteria->add(TblscormcpnodePeer::SLM_ID, $this->slm_id);

		return $criteria;
	}

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

		$criteria->add(TblscormcpnodePeer::CP_NODE_ID, $this->cp_node_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getCpNodeId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setCpNodeId($key);
	}

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

		$copyObj->setNodename($this->nodename);

		$copyObj->setSlmId($this->slm_id);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getTblscormcminodes() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addTblscormcminode($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setCpNodeId(NULL); 
	}

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

	
	public function clearTblscormcminodes()
	{
		$this->collTblscormcminodes = null; 	}

	
	public function initTblscormcminodes()
	{
		$this->collTblscormcminodes = array();
	}

	
	public function getTblscormcminodes($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(TblscormcpnodePeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTblscormcminodes === null) {
			if ($this->isNew()) {
			   $this->collTblscormcminodes = array();
			} else {

				$criteria->add(TblscormcminodePeer::CP_NODE_ID, $this->cp_node_id);

				TblscormcminodePeer::addSelectColumns($criteria);
				$this->collTblscormcminodes = TblscormcminodePeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TblscormcminodePeer::CP_NODE_ID, $this->cp_node_id);

				TblscormcminodePeer::addSelectColumns($criteria);
				if (!isset($this->lastTblscormcminodeCriteria) || !$this->lastTblscormcminodeCriteria->equals($criteria)) {
					$this->collTblscormcminodes = TblscormcminodePeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTblscormcminodeCriteria = $criteria;
		return $this->collTblscormcminodes;
	}

	
	public function countTblscormcminodes(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(TblscormcpnodePeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collTblscormcminodes === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(TblscormcminodePeer::CP_NODE_ID, $this->cp_node_id);

				$count = TblscormcminodePeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TblscormcminodePeer::CP_NODE_ID, $this->cp_node_id);

				if (!isset($this->lastTblscormcminodeCriteria) || !$this->lastTblscormcminodeCriteria->equals($criteria)) {
					$count = TblscormcminodePeer::doCount($criteria, $con);
				} else {
					$count = count($this->collTblscormcminodes);
				}
			} else {
				$count = count($this->collTblscormcminodes);
			}
		}
		$this->lastTblscormcminodeCriteria = $criteria;
		return $count;
	}

	
	public function addTblscormcminode(Tblscormcminode $l)
	{
		if ($this->collTblscormcminodes === null) {
			$this->initTblscormcminodes();
		}
		if (!in_array($l, $this->collTblscormcminodes, true)) { 			array_push($this->collTblscormcminodes, $l);
			$l->setTblscormcpnode($this);
		}
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->collTblscormcminodes) {
				foreach ((array) $this->collTblscormcminodes as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} 
		$this->collTblscormcminodes = null;
	}

} 