<?php


abstract class BasePerfiles extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $descripcion;


	
	protected $username;


	
	protected $created_at;


	
	protected $update_at;


	
	protected $estado = 1;

	
	protected $collUsuarioss;

	
	protected $lastUsuariosCriteria = null;

	
	protected $collPerfilesCredencialess;

	
	protected $lastPerfilesCredencialesCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getDescripcion()
	{

		return $this->descripcion;
	}

	
	public function getUsername()
	{

		return $this->username;
	}

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

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

	
	public function getUpdateAt()
	{

		return $this->update_at;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function setId($v)
	{

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

	} 
	
	public function setDescripcion($v)
	{

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

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

	} 
	
	public function setUsername($v)
	{

		if ($this->username !== $v) {
			$this->username = $v;
			$this->modifiedColumns[] = PerfilesPeer::USERNAME;
		}

	} 
	
	public function setCreatedAt($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 [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = PerfilesPeer::CREATED_AT;
		}

	} 
	
	public function setUpdateAt($v)
	{

		if ($this->update_at !== $v) {
			$this->update_at = $v;
			$this->modifiedColumns[] = PerfilesPeer::UPDATE_AT;
		}

	} 
	
	public function setEstado($v)
	{

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

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

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

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

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

			$this->created_at = $rs->getDate($startcol + 3, null);

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

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

			$this->resetModified();

			$this->setNew(false);

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

		try {
			$con->begin();
			PerfilesPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isNew() && !$this->isColumnModified(PerfilesPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(PerfilesPeer::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 = PerfilesPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += PerfilesPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

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

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


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

				if ($this->collPerfilesCredencialess !== null) {
					foreach($this->collPerfilesCredencialess 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 = PerfilesPeer::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->getUsername();
				break;
			case 3:
				return $this->getCreatedAt();
				break;
			case 4:
				return $this->getUpdateAt();
				break;
			case 5:
				return $this->getEstado();
				break;
			default:
				return null;
				break;
		} 	}

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

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = PerfilesPeer::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->setUsername($value);
				break;
			case 3:
				$this->setCreatedAt($value);
				break;
			case 4:
				$this->setUpdateAt($value);
				break;
			case 5:
				$this->setEstado($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = PerfilesPeer::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->setUsername($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setUpdateAt($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setEstado($arr[$keys[5]]);
	}

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

		if ($this->isColumnModified(PerfilesPeer::ID)) $criteria->add(PerfilesPeer::ID, $this->id);
		if ($this->isColumnModified(PerfilesPeer::DESCRIPCION)) $criteria->add(PerfilesPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(PerfilesPeer::USERNAME)) $criteria->add(PerfilesPeer::USERNAME, $this->username);
		if ($this->isColumnModified(PerfilesPeer::CREATED_AT)) $criteria->add(PerfilesPeer::CREATED_AT, $this->created_at);
		if ($this->isColumnModified(PerfilesPeer::UPDATE_AT)) $criteria->add(PerfilesPeer::UPDATE_AT, $this->update_at);
		if ($this->isColumnModified(PerfilesPeer::ESTADO)) $criteria->add(PerfilesPeer::ESTADO, $this->estado);

		return $criteria;
	}

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

		$criteria->add(PerfilesPeer::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->setUsername($this->username);

		$copyObj->setCreatedAt($this->created_at);

		$copyObj->setUpdateAt($this->update_at);

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


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

			foreach($this->getUsuarioss() as $relObj) {
				$copyObj->addUsuarios($relObj->copy($deepCopy));
			}

			foreach($this->getPerfilesCredencialess() as $relObj) {
				$copyObj->addPerfilesCredenciales($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 PerfilesPeer();
		}
		return self::$peer;
	}

	
	public function initUsuarioss()
	{
		if ($this->collUsuarioss === null) {
			$this->collUsuarioss = array();
		}
	}

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

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

				$criteria->add(UsuariosPeer::ID_PERFIL, $this->getId());

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

				$criteria->add(UsuariosPeer::ID_PERFIL, $this->getId());

				UsuariosPeer::addSelectColumns($criteria);
				if (!isset($this->lastUsuariosCriteria) || !$this->lastUsuariosCriteria->equals($criteria)) {
					$this->collUsuarioss = UsuariosPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastUsuariosCriteria = $criteria;
		return $this->collUsuarioss;
	}

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

		$criteria->add(UsuariosPeer::ID_PERFIL, $this->getId());

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

	
	public function addUsuarios(Usuarios $l)
	{
		$this->collUsuarioss[] = $l;
		$l->setPerfiles($this);
	}


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

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

				$criteria->add(UsuariosPeer::ID_PERFIL, $this->getId());

				$this->collUsuarioss = UsuariosPeer::doSelectJoinTerceros($criteria, $con);
			}
		} else {
									
			$criteria->add(UsuariosPeer::ID_PERFIL, $this->getId());

			if (!isset($this->lastUsuariosCriteria) || !$this->lastUsuariosCriteria->equals($criteria)) {
				$this->collUsuarioss = UsuariosPeer::doSelectJoinTerceros($criteria, $con);
			}
		}
		$this->lastUsuariosCriteria = $criteria;

		return $this->collUsuarioss;
	}

	
	public function initPerfilesCredencialess()
	{
		if ($this->collPerfilesCredencialess === null) {
			$this->collPerfilesCredencialess = array();
		}
	}

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

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

				$criteria->add(PerfilesCredencialesPeer::ID_PERFIL, $this->getId());

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

				$criteria->add(PerfilesCredencialesPeer::ID_PERFIL, $this->getId());

				PerfilesCredencialesPeer::addSelectColumns($criteria);
				if (!isset($this->lastPerfilesCredencialesCriteria) || !$this->lastPerfilesCredencialesCriteria->equals($criteria)) {
					$this->collPerfilesCredencialess = PerfilesCredencialesPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastPerfilesCredencialesCriteria = $criteria;
		return $this->collPerfilesCredencialess;
	}

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

		$criteria->add(PerfilesCredencialesPeer::ID_PERFIL, $this->getId());

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

	
	public function addPerfilesCredenciales(PerfilesCredenciales $l)
	{
		$this->collPerfilesCredencialess[] = $l;
		$l->setPerfiles($this);
	}


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

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

				$criteria->add(PerfilesCredencialesPeer::ID_PERFIL, $this->getId());

				$this->collPerfilesCredencialess = PerfilesCredencialesPeer::doSelectJoinCredenciales($criteria, $con);
			}
		} else {
									
			$criteria->add(PerfilesCredencialesPeer::ID_PERFIL, $this->getId());

			if (!isset($this->lastPerfilesCredencialesCriteria) || !$this->lastPerfilesCredencialesCriteria->equals($criteria)) {
				$this->collPerfilesCredencialess = PerfilesCredencialesPeer::doSelectJoinCredenciales($criteria, $con);
			}
		}
		$this->lastPerfilesCredencialesCriteria = $criteria;

		return $this->collPerfilesCredencialess;
	}

} 