<?php


abstract class BaseNviatico extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $viaticoa;


	
	protected $viaticob;


	
	protected $tipo_tarifa;


	
	protected $rango1;


	
	protected $rango2;


	
	protected $estado = 1;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getViaticoa()
	{

		return $this->viaticoa;
	}

	
	public function getViaticob()
	{

		return $this->viaticob;
	}

	
	public function getTipoTarifa()
	{

		return $this->tipo_tarifa;
	}

	
	public function getRango1()
	{

		return $this->rango1;
	}

	
	public function getRango2()
	{

		return $this->rango2;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function setId($v)
	{

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

	} 
	
	public function setViaticoa($v)
	{

		if ($this->viaticoa !== $v) {
			$this->viaticoa = $v;
			$this->modifiedColumns[] = NviaticoPeer::VIATICOA;
		}

	} 
	
	public function setViaticob($v)
	{

		if ($this->viaticob !== $v) {
			$this->viaticob = $v;
			$this->modifiedColumns[] = NviaticoPeer::VIATICOB;
		}

	} 
	
	public function setTipoTarifa($v)
	{

		if ($this->tipo_tarifa !== $v) {
			$this->tipo_tarifa = $v;
			$this->modifiedColumns[] = NviaticoPeer::TIPO_TARIFA;
		}

	} 
	
	public function setRango1($v)
	{

		if ($this->rango1 !== $v) {
			$this->rango1 = $v;
			$this->modifiedColumns[] = NviaticoPeer::RANGO1;
		}

	} 
	
	public function setRango2($v)
	{

		if ($this->rango2 !== $v) {
			$this->rango2 = $v;
			$this->modifiedColumns[] = NviaticoPeer::RANGO2;
		}

	} 
	
	public function setEstado($v)
	{

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

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

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

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

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

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

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

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

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

			$this->resetModified();

			$this->setNew(false);

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

		try {
			$con->begin();
			NviaticoPeer::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(NviaticoPeer::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 = NviaticoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += NviaticoPeer::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 = NviaticoPeer::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 = NviaticoPeer::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->getViaticoa();
				break;
			case 2:
				return $this->getViaticob();
				break;
			case 3:
				return $this->getTipoTarifa();
				break;
			case 4:
				return $this->getRango1();
				break;
			case 5:
				return $this->getRango2();
				break;
			case 6:
				return $this->getEstado();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = NviaticoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getViaticoa(),
			$keys[2] => $this->getViaticob(),
			$keys[3] => $this->getTipoTarifa(),
			$keys[4] => $this->getRango1(),
			$keys[5] => $this->getRango2(),
			$keys[6] => $this->getEstado(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = NviaticoPeer::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->setViaticoa($value);
				break;
			case 2:
				$this->setViaticob($value);
				break;
			case 3:
				$this->setTipoTarifa($value);
				break;
			case 4:
				$this->setRango1($value);
				break;
			case 5:
				$this->setRango2($value);
				break;
			case 6:
				$this->setEstado($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setViaticoa($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setViaticob($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setTipoTarifa($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setRango1($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setRango2($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setEstado($arr[$keys[6]]);
	}

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

		if ($this->isColumnModified(NviaticoPeer::ID)) $criteria->add(NviaticoPeer::ID, $this->id);
		if ($this->isColumnModified(NviaticoPeer::VIATICOA)) $criteria->add(NviaticoPeer::VIATICOA, $this->viaticoa);
		if ($this->isColumnModified(NviaticoPeer::VIATICOB)) $criteria->add(NviaticoPeer::VIATICOB, $this->viaticob);
		if ($this->isColumnModified(NviaticoPeer::TIPO_TARIFA)) $criteria->add(NviaticoPeer::TIPO_TARIFA, $this->tipo_tarifa);
		if ($this->isColumnModified(NviaticoPeer::RANGO1)) $criteria->add(NviaticoPeer::RANGO1, $this->rango1);
		if ($this->isColumnModified(NviaticoPeer::RANGO2)) $criteria->add(NviaticoPeer::RANGO2, $this->rango2);
		if ($this->isColumnModified(NviaticoPeer::ESTADO)) $criteria->add(NviaticoPeer::ESTADO, $this->estado);

		return $criteria;
	}

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

		$criteria->add(NviaticoPeer::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->setViaticoa($this->viaticoa);

		$copyObj->setViaticob($this->viaticob);

		$copyObj->setTipoTarifa($this->tipo_tarifa);

		$copyObj->setRango1($this->rango1);

		$copyObj->setRango2($this->rango2);

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


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

} 