<?php


abstract class BaseDestinos extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $codmun;


	
	protected $id_comision;


	
	protected $orden;


	
	protected $estado = 1;


	
	protected $observacion;


	
	protected $vigencia;


	
	protected $coddepto;

	
	protected $aMunicipios;

	
	protected $aDepartamentos;

	
	protected $aComisiones;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getCodmun()
	{

		return $this->codmun;
	}

	
	public function getIdComision()
	{

		return $this->id_comision;
	}

	
	public function getOrden()
	{

		return $this->orden;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function getObservacion()
	{

		return $this->observacion;
	}

	
	public function getVigencia()
	{

		return $this->vigencia;
	}

	
	public function getCoddepto()
	{

		return $this->coddepto;
	}

	
	public function setCodmun($v)
	{

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

		if ($this->codmun !== $v) {
			$this->codmun = $v;
			$this->modifiedColumns[] = DestinosPeer::CODMUN;
		}

		if ($this->aMunicipios !== null && $this->aMunicipios->getCodmun() !== $v) {
			$this->aMunicipios = null;
		}

	} 
	
	public function setIdComision($v)
	{

		if ($this->id_comision !== $v) {
			$this->id_comision = $v;
			$this->modifiedColumns[] = DestinosPeer::ID_COMISION;
		}

		if ($this->aComisiones !== null && $this->aComisiones->getVigencia() !== $v) {
			$this->aComisiones = null;
		}

	} 
	
	public function setOrden($v)
	{

		if ($this->orden !== $v) {
			$this->orden = $v;
			$this->modifiedColumns[] = DestinosPeer::ORDEN;
		}

	} 
	
	public function setEstado($v)
	{

		if ($this->estado !== $v || $v === 1) {
			$this->estado = $v;
			$this->modifiedColumns[] = DestinosPeer::ESTADO;
		}

	} 
	
	public function setObservacion($v)
	{

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

		if ($this->observacion !== $v) {
			$this->observacion = $v;
			$this->modifiedColumns[] = DestinosPeer::OBSERVACION;
		}

	} 
	
	public function setVigencia($v)
	{

		if ($this->vigencia !== $v) {
			$this->vigencia = $v;
			$this->modifiedColumns[] = DestinosPeer::VIGENCIA;
		}

		if ($this->aComisiones !== null && $this->aComisiones->getVigencia() !== $v) {
			$this->aComisiones = null;
		}

	} 
	
	public function setCoddepto($v)
	{

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

		if ($this->coddepto !== $v) {
			$this->coddepto = $v;
			$this->modifiedColumns[] = DestinosPeer::CODDEPTO;
		}

		if ($this->aDepartamentos !== null && $this->aDepartamentos->getCoddepto() !== $v) {
			$this->aDepartamentos = null;
		}

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

			$this->codmun = $rs->getString($startcol + 0);

			$this->id_comision = $rs->getFloat($startcol + 1);

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

			$this->estado = $rs->getFloat($startcol + 3);

			$this->observacion = $rs->getString($startcol + 4);

			$this->vigencia = $rs->getFloat($startcol + 5);

			$this->coddepto = $rs->getString($startcol + 6);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 7; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Destinos 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(DestinosPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			DestinosPeer::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(DestinosPeer::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->aMunicipios !== null) {
				if ($this->aMunicipios->isModified()) {
					$affectedRows += $this->aMunicipios->save($con);
				}
				$this->setMunicipios($this->aMunicipios);
			}

			if ($this->aDepartamentos !== null) {
				if ($this->aDepartamentos->isModified()) {
					$affectedRows += $this->aDepartamentos->save($con);
				}
				$this->setDepartamentos($this->aDepartamentos);
			}

			if ($this->aComisiones !== null) {
				if ($this->aComisiones->isModified()) {
					$affectedRows += $this->aComisiones->save($con);
				}
				$this->setComisiones($this->aComisiones);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = DestinosPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += DestinosPeer::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 ($this->aMunicipios !== null) {
				if (!$this->aMunicipios->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aMunicipios->getValidationFailures());
				}
			}

			if ($this->aDepartamentos !== null) {
				if (!$this->aDepartamentos->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aDepartamentos->getValidationFailures());
				}
			}

			if ($this->aComisiones !== null) {
				if (!$this->aComisiones->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aComisiones->getValidationFailures());
				}
			}


			if (($retval = DestinosPeer::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 = DestinosPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCodmun();
				break;
			case 1:
				return $this->getIdComision();
				break;
			case 2:
				return $this->getOrden();
				break;
			case 3:
				return $this->getEstado();
				break;
			case 4:
				return $this->getObservacion();
				break;
			case 5:
				return $this->getVigencia();
				break;
			case 6:
				return $this->getCoddepto();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = DestinosPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCodmun(),
			$keys[1] => $this->getIdComision(),
			$keys[2] => $this->getOrden(),
			$keys[3] => $this->getEstado(),
			$keys[4] => $this->getObservacion(),
			$keys[5] => $this->getVigencia(),
			$keys[6] => $this->getCoddepto(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCodmun($value);
				break;
			case 1:
				$this->setIdComision($value);
				break;
			case 2:
				$this->setOrden($value);
				break;
			case 3:
				$this->setEstado($value);
				break;
			case 4:
				$this->setObservacion($value);
				break;
			case 5:
				$this->setVigencia($value);
				break;
			case 6:
				$this->setCoddepto($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setCodmun($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setIdComision($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setOrden($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setEstado($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setObservacion($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setVigencia($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setCoddepto($arr[$keys[6]]);
	}

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

		if ($this->isColumnModified(DestinosPeer::CODMUN)) $criteria->add(DestinosPeer::CODMUN, $this->codmun);
		if ($this->isColumnModified(DestinosPeer::ID_COMISION)) $criteria->add(DestinosPeer::ID_COMISION, $this->id_comision);
		if ($this->isColumnModified(DestinosPeer::ORDEN)) $criteria->add(DestinosPeer::ORDEN, $this->orden);
		if ($this->isColumnModified(DestinosPeer::ESTADO)) $criteria->add(DestinosPeer::ESTADO, $this->estado);
		if ($this->isColumnModified(DestinosPeer::OBSERVACION)) $criteria->add(DestinosPeer::OBSERVACION, $this->observacion);
		if ($this->isColumnModified(DestinosPeer::VIGENCIA)) $criteria->add(DestinosPeer::VIGENCIA, $this->vigencia);
		if ($this->isColumnModified(DestinosPeer::CODDEPTO)) $criteria->add(DestinosPeer::CODDEPTO, $this->coddepto);

		return $criteria;
	}

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

		$criteria->add(DestinosPeer::CODMUN, $this->codmun);
		$criteria->add(DestinosPeer::ID_COMISION, $this->id_comision);
		$criteria->add(DestinosPeer::VIGENCIA, $this->vigencia);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		$pks = array();

		$pks[0] = $this->getCodmun();

		$pks[1] = $this->getIdComision();

		$pks[2] = $this->getVigencia();

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

		$this->setCodmun($keys[0]);

		$this->setIdComision($keys[1]);

		$this->setVigencia($keys[2]);

	}

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

		$copyObj->setOrden($this->orden);

		$copyObj->setEstado($this->estado);

		$copyObj->setObservacion($this->observacion);

		$copyObj->setCoddepto($this->coddepto);


		$copyObj->setNew(true);

		$copyObj->setCodmun(NULL); 
		$copyObj->setIdComision(NULL); 
		$copyObj->setVigencia(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 DestinosPeer();
		}
		return self::$peer;
	}

	
	public function setMunicipios($v)
	{


		if ($v === null) {
			$this->setCodmun(NULL);
		} else {
			$this->setCodmun($v->getCodmun());
		}


		$this->aMunicipios = $v;
	}


	
	public function getMunicipios($con = null)
	{
		if ($this->aMunicipios === null && (($this->codmun !== "" && $this->codmun !== null))) {
						$this->aMunicipios = MunicipiosPeer::retrieveByPK($this->codmun, $con);

			
		}
		return $this->aMunicipios;
	}

	
	public function setDepartamentos($v)
	{


		if ($v === null) {
			$this->setCoddepto(NULL);
		} else {
			$this->setCoddepto($v->getIdDepto());
		}


		$this->aDepartamentos = $v;
	}


	
	public function getDepartamentos($con = null)
	{	
		echo $this->coddepto;
		die();
		if ($this->aDepartamentos === null && (($this->coddepto !== "" && $this->coddepto !== null))) {
						$this->aDepartamentos = DepartamentosPeer::retrieveByPK($this->coddepto, $con);

			
		}
		return $this->aDepartamentos;
	}

	
	public function setComisiones($v)
	{


		if ($v === null) {
			$this->setIdComision(NULL);
		} else {
			$this->setIdComision($v->getVigencia());
		}


		if ($v === null) {
			$this->setIdComision(NULL);
		} else {
			$this->setIdComision($v->getVigencia());
		}


		if ($v === null) {
			$this->setVigencia(NULL);
		} else {
			$this->setVigencia($v->getVigencia());
		}


		if ($v === null) {
			$this->setVigencia(NULL);
		} else {
			$this->setVigencia($v->getVigencia());
		}


		$this->aComisiones = $v;
	}


	
	public function getComisiones($con = null)
	{
		if ($this->aComisiones === null && ($this->id_comision > 0 && $this->id_comision > 0 && $this->vigencia > 0 && $this->vigencia > 0)) {
						$this->aComisiones = ComisionesPeer::retrieveByPK($this->id_comision, $this->id_comision, $this->vigencia, $this->vigencia, $con);

			
		}
		return $this->aComisiones;
	}

} 
