<?php


abstract class BaseProyectos extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $ano_fiscal;


	
	protected $descripcion;


	
	protected $id_area_lider;


	
	protected $valor_proyecto;


	
	protected $codigo;

        protected $collComisioness;


	protected $lastComisionesCriteria = null;
	
	protected $estado;

	
	protected $aAreas;

	protected $id_cdp_global;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getAnoFiscal()
	{

		return $this->ano_fiscal;
	}

	
	public function getDescripcion()
	{

		return $this->descripcion;
	}

	
	public function getIdAreaLider()
	{

		return $this->id_area_lider;
	}

	
	public function getValorProyecto()
	{

		return $this->valor_proyecto;
	}

	
	public function getCodigo()
	{

		return $this->codigo;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

    public function getIdCdpGlobal()
	{

		return $this->id_cdp_global;
	}    
	
	public function setId($v)
	{

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ProyectosPeer::ID;
		}

	} 
	
	public function setAnoFiscal($v)
	{

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

		if ($this->ano_fiscal !== $v) {
			$this->ano_fiscal = $v;
			$this->modifiedColumns[] = ProyectosPeer::ANO_FISCAL;
		}

	} 
	
	public function setDescripcion($v)
	{

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

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

	} 
	
	public function setIdAreaLider($v)
	{

		if ($this->id_area_lider !== $v) {
			$this->id_area_lider = $v;
			$this->modifiedColumns[] = ProyectosPeer::ID_AREA_LIDER;
		}

		if ($this->aAreas !== null && $this->aAreas->getIdArea() !== $v) {
			$this->aAreas = null;
		}

	} 
	
	public function setValorProyecto($v)
	{

		if ($this->valor_proyecto !== $v) {
			$this->valor_proyecto = $v;
			$this->modifiedColumns[] = ProyectosPeer::VALOR_PROYECTO;
		}

	} 
	
	public function setCodigo($v)
	{

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

		if ($this->codigo !== $v) {
			$this->codigo = $v;
			$this->modifiedColumns[] = ProyectosPeer::CODIGO;
		}

	} 
	
	public function setEstado($v)
	{

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

	} 

	public function setIdCdpGlobal($v)
	{

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

		if ($this->id_cdp_global !== $v) {
			$this->id_cdp_global = $v;
			$this->modifiedColumns[] = ProyectosPeer::ID_CDP_GLOBAL;
		}

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

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

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

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

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

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

			$this->codigo = $rs->getString($startcol + 5);

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

			$this->id_cdp_global = $rs->getFloat($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

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

        public function addComisiones(Comisiones $l)
	{
		$this->collComisioness[] = $l;
		$l->setProyectos($this);
	}
	public function initComisioness()
	{
		if ($this->collComisioness === null) {
			$this->collComisioness = array();
		}
	}
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

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

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


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


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

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getAnoFiscal();
				break;
			case 2:
				return $this->getDescripcion();
				break;
			case 3:
				return $this->getIdAreaLider();
				break;
			case 4:
				return $this->getValorProyecto();
				break;
			case 5:
				return $this->getCodigo();
				break;
			case 6:
				return $this->getEstado();
				break;
			case 7:
				return $this->getIdCdpGlobal();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ProyectosPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getAnoFiscal(),
			$keys[2] => $this->getDescripcion(),
			$keys[3] => $this->getIdAreaLider(),
			$keys[4] => $this->getValorProyecto(),
			$keys[5] => $this->getCodigo(),
			$keys[6] => $this->getEstado(),
			$keys[7] => $this->getIdCdpGlobal(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setAnoFiscal($value);
				break;
			case 2:
				$this->setDescripcion($value);
				break;
			case 3:
				$this->setIdAreaLider($value);
				break;
			case 4:
				$this->setValorProyecto($value);
				break;
			case 5:
				$this->setCodigo($value);
				break;
			case 6:
				$this->setEstado($value);
				break;
			case 7:
				$this->setIdCdpGlobal($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setAnoFiscal($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setDescripcion($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setIdAreaLider($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setValorProyecto($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCodigo($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setEstado($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setIdCdpGlobal($arr[$keys[7]]);
	}

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

		if ($this->isColumnModified(ProyectosPeer::ID)) $criteria->add(ProyectosPeer::ID, $this->id);
		if ($this->isColumnModified(ProyectosPeer::ANO_FISCAL)) $criteria->add(ProyectosPeer::ANO_FISCAL, $this->ano_fiscal);
		if ($this->isColumnModified(ProyectosPeer::DESCRIPCION)) $criteria->add(ProyectosPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(ProyectosPeer::ID_AREA_LIDER)) $criteria->add(ProyectosPeer::ID_AREA_LIDER, $this->id_area_lider);
		if ($this->isColumnModified(ProyectosPeer::VALOR_PROYECTO)) $criteria->add(ProyectosPeer::VALOR_PROYECTO, $this->valor_proyecto);
		if ($this->isColumnModified(ProyectosPeer::CODIGO)) $criteria->add(ProyectosPeer::CODIGO, $this->codigo);
		if ($this->isColumnModified(ProyectosPeer::ESTADO)) $criteria->add(ProyectosPeer::ESTADO, $this->estado);
		if ($this->isColumnModified(ProyectosPeer::ID_CDP_GLOBAL)) $criteria->add(ProyectosPeer::ID_CDP_GLOBAL, $this->id_cdp_global);
		return $criteria;
	}

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

		$criteria->add(ProyectosPeer::ID, $this->id);

		return $criteria;
	}

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

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

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

		$copyObj->setAnoFiscal($this->ano_fiscal);

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

		$copyObj->setIdAreaLider($this->id_area_lider);

		$copyObj->setValorProyecto($this->valor_proyecto);

		$copyObj->setCodigo($this->codigo);

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

		$copyObj->setIdCdpGlobal($this->id_cdp_global);


		$copyObj->setNew(true);

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

	
	public function setAreas($v)
	{


		if ($v === null) {
			$this->setIdAreaLider(NULL);
		} else {
			$this->setIdAreaLider($v->getIdArea());
		}


		$this->aAreas = $v;
	}


	
	public function getAreas($con = null)
	{
		if ($this->aAreas === null && ($this->id_area_lider > 0)) {
						$this->aAreas = AreasPeer::retrieveByPK($this->id_area_lider, $con);

			
		}
		return $this->aAreas;
	}

} 