<?php


abstract class BaseLog extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $stamp;


	
	protected $id_usuario;


	
	protected $accion;


	
	protected $ip;

	
	protected $aUsuarios;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getStamp()
	{

		return $this->stamp;
	}

	
	public function getUsername()
	{

		return $this->id_usuario;
	}

	
	public function getAccion()
	{

		return $this->accion;
	}

	
	public function getIp()
	{

		return $this->ip;
	}

	
	public function setId($v)
	{

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

	} 
	
	public function setStamp($v)
	{

		if ($this->stamp !== $v) {
			$this->stamp = $v;
			$this->modifiedColumns[] = LogPeer::STAMP;
		}

	} 
	
	public function setUsername($v)
	{

		if ($this->id_usuario !== $v) {
			$this->id_usuario = $v;
			$this->modifiedColumns[] = LogPeer::ID_USUARIO;
		}

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

	} 
	
	public function setAccion($v)
	{

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

		if ($this->accion !== $v) {
			$this->accion = $v;
			$this->modifiedColumns[] = LogPeer::ACCION;
		}

	} 
	
	public function setIp($v)
	{

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

		if ($this->ip !== $v) {
			$this->ip = $v;
			$this->modifiedColumns[] = LogPeer::IP;
		}

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

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

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

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

			$this->accion = $rs->getString($startcol + 3);

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

			$this->resetModified();

			$this->setNew(false);

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

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


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


			if (($retval = LogPeer::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 = LogPeer::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->getStamp();
				break;
			case 2:
				return $this->getIdUsuario();
				break;
			case 3:
				return $this->getAccion();
				break;
			case 4:
				return $this->getIp();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = LogPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getStamp(),
			$keys[2] => $this->getIdUsuario(),
			$keys[3] => $this->getAccion(),
			$keys[4] => $this->getIp(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = LogPeer::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->setStamp($value);
				break;
			case 2:
				$this->setIdUsuario($value);
				break;
			case 3:
				$this->setAccion($value);
				break;
			case 4:
				$this->setIp($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setStamp($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setIdUsuario($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setAccion($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setIp($arr[$keys[4]]);
	}

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

		if ($this->isColumnModified(LogPeer::ID)) $criteria->add(LogPeer::ID, $this->id);
		if ($this->isColumnModified(LogPeer::STAMP)) $criteria->add(LogPeer::STAMP, $this->stamp);
		if ($this->isColumnModified(LogPeer::ID_USUARIO)) $criteria->add(LogPeer::ID_USUARIO, $this->id_usuario);
		if ($this->isColumnModified(LogPeer::ACCION)) $criteria->add(LogPeer::ACCION, $this->accion);
		if ($this->isColumnModified(LogPeer::IP)) $criteria->add(LogPeer::IP, $this->ip);

		return $criteria;
	}

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

		$criteria->add(LogPeer::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->setStamp($this->stamp);

		$copyObj->setIdUsuario($this->id_usuario);

		$copyObj->setAccion($this->accion);

		$copyObj->setIp($this->ip);


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

	
	public function setUsuarios($v)
	{


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


		$this->aUsuarios = $v;
	}


	
	public function getUsuarios($con = null)
	{
		if ($this->aUsuarios === null && ($this->id_usuario > 0)) {
						$this->aUsuarios = UsuariosPeer::retrieveByPK($this->id_usuario, $con);

			
		}
		return $this->aUsuarios;
	}

} 