<?php


abstract class BaseDepartamento extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id_depto;


	
	protected $descripcion;


	
	protected $id_pais;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	protected $collDestinoss;

	
	public function getIdDepto()
	{

		return $this->id_depto;
	}

	
	public function getDescripcion()
	{

		return $this->descripcion;
	}

	
	public function getIdPais()
	{

		return $this->id_pais;
	}

	
	public function setIdDepto($v)
	{

		if ($this->id_depto !== $v) {
			$this->id_depto = $v;
			$this->modifiedColumns[] = DepartamentoPeer::ID_DEPTO;
		}

	} 
	
	public function setDescripcion($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->descripcion !== $v) {
			$this->descripcion = $v;
			$this->modifiedColumns[] = DepartamentoPeer::DESCRIPCION;
		}

	} 
	
	public function setIdPais($v)
	{

		if ($this->id_pais !== $v) {
			$this->id_pais = $v;
			$this->modifiedColumns[] = DepartamentoPeer::ID_PAIS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id_depto = $rs->getFloat($startcol + 0);

			$this->descripcion = $rs->getString($startcol + 1);

			$this->id_pais = $rs->getFloat($startcol + 2);

			$this->resetModified();

			$this->setNew(false);

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

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(DepartamentoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			DepartamentoPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(DepartamentoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = DepartamentoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += DepartamentoPeer::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 (($retval = DepartamentoPeer::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 = DepartamentoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getIdDepto();
				break;
			case 1:
				return $this->getDescripcion();
				break;
			case 2:
				return $this->getIdPais();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = DepartamentoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getIdDepto(),
			$keys[1] => $this->getDescripcion(),
			$keys[2] => $this->getIdPais(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setIdDepto($value);
				break;
			case 1:
				$this->setDescripcion($value);
				break;
			case 2:
				$this->setIdPais($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setIdDepto($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setDescripcion($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setIdPais($arr[$keys[2]]);
	}

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

		if ($this->isColumnModified(DepartamentoPeer::ID_DEPTO)) $criteria->add(DepartamentoPeer::ID_DEPTO, $this->id_depto);
		if ($this->isColumnModified(DepartamentoPeer::DESCRIPCION)) $criteria->add(DepartamentoPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(DepartamentoPeer::ID_PAIS)) $criteria->add(DepartamentoPeer::ID_PAIS, $this->id_pais);

		return $criteria;
	}

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

		$criteria->add(DepartamentoPeer::ID_DEPTO, $this->id_depto);

		return $criteria;
	}
	

	public function initDestinoss()
	{
		if ($this->collDestinoss === null) {
			$this->collDestinoss = array();
		}
	}

	public function addDestinos(Destinos $l)
	{
		$this->collDestinoss[] = $l;
		$l->setDepartamentos($this);
	}
	
	public function getPrimaryKey()
	{
		return $this->getIdDepto();
	}

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

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

		$copyObj->setDescripcion($this->descripcion);

		$copyObj->setIdPais($this->id_pais);


		$copyObj->setNew(true);

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

} 
