<?php


abstract class BasePerfilesCredenciales extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id_perfil;


	
	protected $id_credencial;


	
	protected $username;


	
	protected $created_at;


	
	protected $update_at;


	
	protected $estado = 1;

	
	protected $aPerfiles;

	
	protected $aCredenciales;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getIdPerfil()
	{

		return $this->id_perfil;
	}

	
	public function getIdCredencial()
	{

		return $this->id_credencial;
	}

	
	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($format = 'Y-m-d')
	{

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

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function setIdPerfil($v)
	{

		if ($this->id_perfil !== $v) {
			$this->id_perfil = $v;
			$this->modifiedColumns[] = PerfilesCredencialesPeer::ID_PERFIL;
		}

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

	} 
	
	public function setIdCredencial($v)
	{

		if ($this->id_credencial !== $v) {
			$this->id_credencial = $v;
			$this->modifiedColumns[] = PerfilesCredencialesPeer::ID_CREDENCIAL;
		}

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

	} 
	
	public function setUsername($v)
	{

		if ($this->username !== $v) {
			$this->username = $v;
			$this->modifiedColumns[] = PerfilesCredencialesPeer::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[] = PerfilesCredencialesPeer::CREATED_AT;
		}

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

	} 
	
	public function setEstado($v)
	{

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

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

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

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

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

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

			$this->update_at = $rs->getDate($startcol + 4, null);

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

			$this->resetModified();

			$this->setNew(false);

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

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

			if ($this->aCredenciales !== null) {
				if ($this->aCredenciales->isModified()) {
					$affectedRows += $this->aCredenciales->save($con);
				}
				$this->setCredenciales($this->aCredenciales);
			}


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

			if ($this->aCredenciales !== null) {
				if (!$this->aCredenciales->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aCredenciales->getValidationFailures());
				}
			}


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

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getIdPerfil();
				break;
			case 1:
				return $this->getIdCredencial();
				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 = PerfilesCredencialesPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getIdPerfil(),
			$keys[1] => $this->getIdCredencial(),
			$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 = PerfilesCredencialesPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setIdPerfil($value);
				break;
			case 1:
				$this->setIdCredencial($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 = PerfilesCredencialesPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setIdPerfil($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setIdCredencial($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(PerfilesCredencialesPeer::DATABASE_NAME);

		if ($this->isColumnModified(PerfilesCredencialesPeer::ID_PERFIL)) $criteria->add(PerfilesCredencialesPeer::ID_PERFIL, $this->id_perfil);
		if ($this->isColumnModified(PerfilesCredencialesPeer::ID_CREDENCIAL)) $criteria->add(PerfilesCredencialesPeer::ID_CREDENCIAL, $this->id_credencial);
		if ($this->isColumnModified(PerfilesCredencialesPeer::USERNAME)) $criteria->add(PerfilesCredencialesPeer::USERNAME, $this->username);
		if ($this->isColumnModified(PerfilesCredencialesPeer::CREATED_AT)) $criteria->add(PerfilesCredencialesPeer::CREATED_AT, $this->created_at);
		if ($this->isColumnModified(PerfilesCredencialesPeer::UPDATE_AT)) $criteria->add(PerfilesCredencialesPeer::UPDATE_AT, $this->update_at);
		if ($this->isColumnModified(PerfilesCredencialesPeer::ESTADO)) $criteria->add(PerfilesCredencialesPeer::ESTADO, $this->estado);

		return $criteria;
	}

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

		$criteria->add(PerfilesCredencialesPeer::ID_PERFIL, $this->id_perfil);
		$criteria->add(PerfilesCredencialesPeer::ID_CREDENCIAL, $this->id_credencial);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		$pks = array();

		$pks[0] = $this->getIdPerfil();

		$pks[1] = $this->getIdCredencial();

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

		$this->setIdPerfil($keys[0]);

		$this->setIdCredencial($keys[1]);

	}

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

		$copyObj->setUsername($this->username);

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

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

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


		$copyObj->setNew(true);

		$copyObj->setIdPerfil(NULL); 
		$copyObj->setIdCredencial(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 PerfilesCredencialesPeer();
		}
		return self::$peer;
	}

	
	public function setPerfiles($v)
	{


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


		$this->aPerfiles = $v;
	}


	
	public function getPerfiles($con = null)
	{
		if ($this->aPerfiles === null && ($this->id_perfil > 0)) {
						$this->aPerfiles = PerfilesPeer::retrieveByPK($this->id_perfil, $con);

			
		}
		return $this->aPerfiles;
	}

	
	public function setCredenciales($v)
	{


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


		$this->aCredenciales = $v;
	}


	
	public function getCredenciales($con = null)
	{
		if ($this->aCredenciales === null && ($this->id_credencial > 0)) {
						$this->aCredenciales = CredencialesPeer::retrieveByPK($this->id_credencial, $con);

			
		}
		return $this->aCredenciales;
	}

} 