<?php


abstract class BaseDestinosComisionados extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $nitocc;


	
	protected $id_comision;


	
	protected $codmun;


	
	protected $orden;


	
	protected $estado = 0;


	
	protected $vigencia;


	
	protected $id_transporte;

	protected $fecha_ini;

	protected $fecha_fin;

	protected $num_dias;

	
	protected $aTerceros;

	
	protected $aMunicipios;

	
	protected $aTransportes;

	
	protected $aComisiones;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getNitocc()
	{

		return $this->nitocc;
	}

	
	public function getIdComision()
	{

		return $this->id_comision;
	}

	
	public function getCodmun()
	{

		return $this->codmun;
	}

	
	public function getOrden()
	{

		return $this->orden;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function getVigencia()
	{

		return $this->vigencia;
	}

	
	public function getIdTransporte()
	{

		return $this->id_transporte;
	}

	public function getFechaIni($format = 'Y-m-d')
	{

		if ($this->fecha_ini === null || $this->fecha_ini === '') {
			return null;
		} elseif (!is_int($this->fecha_ini)) {
						$ts = strtotime($this->fecha_ini);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_salida] as date/time value: " . var_export($this->fecha_ini, true));
			}
		} else {
			$ts = $this->fecha_ini;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	public function getFechaFin($format = 'Y-m-d')
	{

		if ($this->fecha_fin === null || $this->fecha_fin === '') {
			return null;
		} elseif (!is_int($this->fecha_fin)) {
						$ts = strtotime($this->fecha_fin);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_salida] as date/time value: " . var_export($this->fecha_fin, true));
			}
		} else {
			$ts = $this->fecha_fin;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	public function getNumDias()
	{

		return $this->num_dias;
	}

	
	public function setNitocc($v)
	{

		if ($this->nitocc !== $v) {
			$this->nitocc = $v;
			$this->modifiedColumns[] = DestinosComisionadosPeer::NITOCC;
		}

		if ($this->aTerceros !== null && $this->aTerceros->getNitocc() !== $v) {
			$this->aTerceros = null;
		}

	} 
	
	public function setIdComision($v)
	{

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

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

	} 
	
	public function setCodmun($v)
	{

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

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

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

	} 
	
	public function setOrden($v)
	{

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

	} 
	
	public function setEstado($v)
	{

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

	} 
	
	public function setVigencia($v)
	{

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

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

	} 
	
	public function setIdTransporte($v)
	{

		if ($this->id_transporte !== $v) {
			$this->id_transporte = $v;
			$this->modifiedColumns[] = DestinosComisionadosPeer::ID_TRANSPORTE;
		}

		if ($this->aTransportes !== null && $this->aTransportes->getId() !== $v) {
			$this->aTransportes = null;
		}

	} 

	public function setFechaIni($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_salida] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_ini !== $ts) {
			$this->fecha_ini = $ts;
			$this->modifiedColumns[] = DestinosComisionadosPeer::FECHA_INI;
		}

	} 

	public function setFechaFin($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_salida] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_fin !== $ts) {
			$this->fecha_fin = $ts;
			$this->modifiedColumns[] = DestinosComisionadosPeer::FECHA_FIN;
		}


	} 

	public function setNumDias($v)
	{

		if ($this->num_dias !== $v || $v === 0) {
			$this->num_dias = $v;
			$this->modifiedColumns[] = DestinosComisionadosPeer::NUM_DIAS;
		}

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

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

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

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

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

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

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

			$this->id_transporte = $rs->getFloat($startcol + 6);

			$this->fecha_ini = $rs->getDate($startcol + 7, null);

			$this->fecha_fin = $rs->getDate($startcol + 8, null);

			$this->num_dias = $rs->getFloat($startcol + 9);

			$this->resetModified();

			$this->setNew(false);

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

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

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

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

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


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

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

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

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


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

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getNitocc();
				break;
			case 1:
				return $this->getIdComision();
				break;
			case 2:
				return $this->getCodmun();
				break;
			case 3:
				return $this->getOrden();
				break;
			case 4:
				return $this->getEstado();
				break;
			case 5:
				return $this->getVigencia();
				break;
			case 6:
				return $this->getIdTransporte();
				break;
			case 7:
				return $this->getFechaIni();
				break;
			case 8:
				return $this->getFechaFin();
				break;
			case 9:
				return $this->getNumDias();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = DestinosComisionadosPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getNitocc(),
			$keys[1] => $this->getIdComision(),
			$keys[2] => $this->getCodmun(),
			$keys[3] => $this->getOrden(),
			$keys[4] => $this->getEstado(),
			$keys[5] => $this->getVigencia(),
			$keys[6] => $this->getIdTransporte(),
			$keys[7] => $this->getFechaIni(),
			$keys[8] => $this->getFechaFin(),
			$keys[9] => $this->getNumDias(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setNitocc($value);
				break;
			case 1:
				$this->setIdComision($value);
				break;
			case 2:
				$this->setCodmun($value);
				break;
			case 3:
				$this->setOrden($value);
				break;
			case 4:
				$this->setEstado($value);
				break;
			case 5:
				$this->setVigencia($value);
				break;
			case 6:
				$this->setIdTransporte($value);
				break;
			case 7:
				$this->setFechaIni($value);
				break;
			case 8:
				$this->setFechaFin($value);
				break;
			case 9:
				$this->setNumDias($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setNitocc($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setIdComision($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCodmun($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setOrden($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setEstado($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setVigencia($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setIdTransporte($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setFechaIni($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setFechaFin($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setNumDias($arr[$keys[9]]);
	}

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

		if ($this->isColumnModified(DestinosComisionadosPeer::NITOCC)) $criteria->add(DestinosComisionadosPeer::NITOCC, $this->nitocc);
		if ($this->isColumnModified(DestinosComisionadosPeer::ID_COMISION)) $criteria->add(DestinosComisionadosPeer::ID_COMISION, $this->id_comision);
		if ($this->isColumnModified(DestinosComisionadosPeer::CODMUN)) $criteria->add(DestinosComisionadosPeer::CODMUN, $this->codmun);
		if ($this->isColumnModified(DestinosComisionadosPeer::ORDEN)) $criteria->add(DestinosComisionadosPeer::ORDEN, $this->orden);
		if ($this->isColumnModified(DestinosComisionadosPeer::ESTADO)) $criteria->add(DestinosComisionadosPeer::ESTADO, $this->estado);
		if ($this->isColumnModified(DestinosComisionadosPeer::VIGENCIA)) $criteria->add(DestinosComisionadosPeer::VIGENCIA, $this->vigencia);
		if ($this->isColumnModified(DestinosComisionadosPeer::ID_TRANSPORTE)) $criteria->add(DestinosComisionadosPeer::ID_TRANSPORTE, $this->id_transporte);
		if ($this->isColumnModified(DestinosComisionadosPeer::FECHA_INI)) $criteria->add(DestinosComisionadosPeer::FECHA_INI, $this->fecha_ini);
		if ($this->isColumnModified(DestinosComisionadosPeer::FECHA_FIN)) $criteria->add(DestinosComisionadosPeer::FECHA_FIN, $this->fecha_fin);
		if ($this->isColumnModified(DestinosComisionadosPeer::NUM_DIAS)) $criteria->add(DestinosComisionadosPeer::NUM_DIAS, $this->num_dias);

		return $criteria;
	}

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

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

		return $criteria;
	}

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

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

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

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

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

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

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

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

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

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

	}

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

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

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

		$copyObj->setIdTransporte($this->id_transporte);

		$copyObj->setFechaIni($this->fecha_ini);

		$copyObj->setFechaFin($this->fecha_fin);

		$copyObj->setNumDias($this->num_dias);


		$copyObj->setNew(true);

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

	
	public function setTerceros($v)
	{


		if ($v === null) {
			$this->setNitocc(NULL);
		} else {
			$this->setNitocc($v->getNitocc());
		}


		$this->aTerceros = $v;
	}


	
	public function getTerceros($con = null)
	{
		if ($this->aTerceros === null && ($this->nitocc > 0)) {
						$this->aTerceros = TercerosPeer::retrieveByPK($this->nitocc, $con);

			
		}
		return $this->aTerceros;
	}

	
	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 setTransportes($v)
	{


		if ($v === null) {
			$this->setIdTransporte(NULL);
		} else {
			$this->setIdTransporte($v->getId());
		}


		$this->aTransportes = $v;
	}


	
	public function getTransportes($con = null)
	{
		if ($this->aTransportes === null && ($this->id_transporte > 0)) {
						$this->aTransportes = TransportesPeer::retrieveByPK($this->id_transporte, $con);

			
		}
		return $this->aTransportes;
	}

	
	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;
	}

} 