<?php


abstract class BaseTarifasTaxis extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $descripcion;


	
	protected $tarifa;


	
	protected $estado = 1;

	
	protected $collTarifasDestinos;

	
	protected $lastTarifasDestinoCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getDescripcion()
	{

		return $this->descripcion;
	}

	
	public function getTarifa()
	{

		return $this->tarifa;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function setId($v)
	{

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

	} 
	
	public function setDescripcion($v)
	{

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

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

	} 
	
	public function setTarifa($v)
	{

		if ($this->tarifa !== $v) {
			$this->tarifa = $v;
			$this->modifiedColumns[] = TarifasTaxisPeer::TARIFA;
		}

	} 
	
	public function setEstado($v)
	{

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

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

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

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

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

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

			$this->resetModified();

			$this->setNew(false);

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

		try {
			$con->begin();
			TarifasTaxisPeer::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(TarifasTaxisPeer::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 = TarifasTaxisPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += TarifasTaxisPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collTarifasDestinos !== null) {
				foreach($this->collTarifasDestinos as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$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 = TarifasTaxisPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collTarifasDestinos !== null) {
					foreach($this->collTarifasDestinos as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TarifasTaxisPeer::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->getDescripcion();
				break;
			case 2:
				return $this->getTarifa();
				break;
			case 3:
				return $this->getEstado();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TarifasTaxisPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getDescripcion(),
			$keys[2] => $this->getTarifa(),
			$keys[3] => $this->getEstado(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TarifasTaxisPeer::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->setDescripcion($value);
				break;
			case 2:
				$this->setTarifa($value);
				break;
			case 3:
				$this->setEstado($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setDescripcion($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setTarifa($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setEstado($arr[$keys[3]]);
	}

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

		if ($this->isColumnModified(TarifasTaxisPeer::ID)) $criteria->add(TarifasTaxisPeer::ID, $this->id);
		if ($this->isColumnModified(TarifasTaxisPeer::DESCRIPCION)) $criteria->add(TarifasTaxisPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(TarifasTaxisPeer::TARIFA)) $criteria->add(TarifasTaxisPeer::TARIFA, $this->tarifa);
		if ($this->isColumnModified(TarifasTaxisPeer::ESTADO)) $criteria->add(TarifasTaxisPeer::ESTADO, $this->estado);

		return $criteria;
	}

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

		$criteria->add(TarifasTaxisPeer::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->setDescripcion($this->descripcion);

		$copyObj->setTarifa($this->tarifa);

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


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getTarifasDestinos() as $relObj) {
				$copyObj->addTarifasDestino($relObj->copy($deepCopy));
			}

		} 

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

	
	public function initTarifasDestinos()
	{
		if ($this->collTarifasDestinos === null) {
			$this->collTarifasDestinos = array();
		}
	}

	
	public function getTarifasDestinos($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTarifasDestinos === null) {
			if ($this->isNew()) {
			   $this->collTarifasDestinos = array();
			} else {

				$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->getId());

				TarifasDestinoPeer::addSelectColumns($criteria);
				$this->collTarifasDestinos = TarifasDestinoPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->getId());

				TarifasDestinoPeer::addSelectColumns($criteria);
				if (!isset($this->lastTarifasDestinoCriteria) || !$this->lastTarifasDestinoCriteria->equals($criteria)) {
					$this->collTarifasDestinos = TarifasDestinoPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTarifasDestinoCriteria = $criteria;
		return $this->collTarifasDestinos;
	}

	
	public function countTarifasDestinos($criteria = null, $distinct = false, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->getId());

		return TarifasDestinoPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addTarifasDestino(TarifasDestino $l)
	{
		$this->collTarifasDestinos[] = $l;
		$l->setTarifasTaxis($this);
	}


	
	public function getTarifasDestinosJoinTerceros($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTarifasDestinos === null) {
			if ($this->isNew()) {
				$this->collTarifasDestinos = array();
			} else {

				$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->getId());

				$this->collTarifasDestinos = TarifasDestinoPeer::doSelectJoinTerceros($criteria, $con);
			}
		} else {
									
			$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->getId());

			if (!isset($this->lastTarifasDestinoCriteria) || !$this->lastTarifasDestinoCriteria->equals($criteria)) {
				$this->collTarifasDestinos = TarifasDestinoPeer::doSelectJoinTerceros($criteria, $con);
			}
		}
		$this->lastTarifasDestinoCriteria = $criteria;

		return $this->collTarifasDestinos;
	}


	
	public function getTarifasDestinosJoinComisiones($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTarifasDestinos === null) {
			if ($this->isNew()) {
				$this->collTarifasDestinos = array();
			} else {

				$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->getId());

				$this->collTarifasDestinos = TarifasDestinoPeer::doSelectJoinComisiones($criteria, $con);
			}
		} else {
									
			$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->getId());

			if (!isset($this->lastTarifasDestinoCriteria) || !$this->lastTarifasDestinoCriteria->equals($criteria)) {
				$this->collTarifasDestinos = TarifasDestinoPeer::doSelectJoinComisiones($criteria, $con);
			}
		}
		$this->lastTarifasDestinoCriteria = $criteria;

		return $this->collTarifasDestinos;
	}

} 