<?php


abstract class BaseCredenciales extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $id_menu;


	
	protected $name;


	
	protected $descripcion;


	
	protected $orden;


	
	protected $update_at;


	
	protected $ruta;

	
	protected $aMenus;

	
	protected $collPerfilesCredencialess;

	
	protected $lastPerfilesCredencialesCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getIdMenu()
	{

		return $this->id_menu;
	}

	
	public function getName()
	{

		return $this->name;
	}

	
	public function getDescripcion()
	{

		return $this->descripcion;
	}

	
	public function getOrden()
	{

		return $this->orden;
	}

	
	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 getRuta()
	{

		return $this->ruta;
	}

	
	public function setId($v)
	{

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

	} 
	
	public function setIdMenu($v)
	{

		if ($this->id_menu !== $v) {
			$this->id_menu = $v;
			$this->modifiedColumns[] = CredencialesPeer::ID_MENU;
		}

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

	} 
	
	public function setName($v)
	{

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

		if ($this->name !== $v) {
			$this->name = $v;
			$this->modifiedColumns[] = CredencialesPeer::NAME;
		}

	} 
	
	public function setDescripcion($v)
	{

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

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

	} 
	
	public function setOrden($v)
	{

		if ($this->orden !== $v) {
			$this->orden = $v;
			$this->modifiedColumns[] = CredencialesPeer::ORDEN;
		}

	} 
	
	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[] = CredencialesPeer::UPDATE_AT;
		}

	} 
	
	public function setRuta($v)
	{

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

		if ($this->ruta !== $v) {
			$this->ruta = $v;
			$this->modifiedColumns[] = CredencialesPeer::RUTA;
		}

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

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

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

			$this->name = $rs->getString($startcol + 2);

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

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

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

			$this->ruta = $rs->getString($startcol + 6);

			$this->resetModified();

			$this->setNew(false);

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

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


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = CredencialesPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += CredencialesPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			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 ($this->aMenus !== null) {
				if (!$this->aMenus->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aMenus->getValidationFailures());
				}
			}


			if (($retval = CredencialesPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				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 = CredencialesPeer::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->getIdMenu();
				break;
			case 2:
				return $this->getName();
				break;
			case 3:
				return $this->getDescripcion();
				break;
			case 4:
				return $this->getOrden();
				break;
			case 5:
				return $this->getUpdateAt();
				break;
			case 6:
				return $this->getRuta();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CredencialesPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getIdMenu(),
			$keys[2] => $this->getName(),
			$keys[3] => $this->getDescripcion(),
			$keys[4] => $this->getOrden(),
			$keys[5] => $this->getUpdateAt(),
			$keys[6] => $this->getRuta(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CredencialesPeer::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->setIdMenu($value);
				break;
			case 2:
				$this->setName($value);
				break;
			case 3:
				$this->setDescripcion($value);
				break;
			case 4:
				$this->setOrden($value);
				break;
			case 5:
				$this->setUpdateAt($value);
				break;
			case 6:
				$this->setRuta($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setIdMenu($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setName($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setDescripcion($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setOrden($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setUpdateAt($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setRuta($arr[$keys[6]]);
	}

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

		if ($this->isColumnModified(CredencialesPeer::ID)) $criteria->add(CredencialesPeer::ID, $this->id);
		if ($this->isColumnModified(CredencialesPeer::ID_MENU)) $criteria->add(CredencialesPeer::ID_MENU, $this->id_menu);
		if ($this->isColumnModified(CredencialesPeer::NAME)) $criteria->add(CredencialesPeer::NAME, $this->name);
		if ($this->isColumnModified(CredencialesPeer::DESCRIPCION)) $criteria->add(CredencialesPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(CredencialesPeer::ORDEN)) $criteria->add(CredencialesPeer::ORDEN, $this->orden);
		if ($this->isColumnModified(CredencialesPeer::UPDATE_AT)) $criteria->add(CredencialesPeer::UPDATE_AT, $this->update_at);
		if ($this->isColumnModified(CredencialesPeer::RUTA)) $criteria->add(CredencialesPeer::RUTA, $this->ruta);

		return $criteria;
	}

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

		$criteria->add(CredencialesPeer::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->setIdMenu($this->id_menu);

		$copyObj->setName($this->name);

		$copyObj->setDescripcion($this->descripcion);

		$copyObj->setOrden($this->orden);

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

		$copyObj->setRuta($this->ruta);


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

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

	
	public function setMenus($v)
	{


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


		$this->aMenus = $v;
	}


	
	public function getMenus($con = null)
	{
		if ($this->aMenus === null && ($this->id_menu > 0)) {
						$this->aMenus = MenusPeer::retrieveByPK($this->id_menu, $con);

			
		}
		return $this->aMenus;
	}

	
	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_CREDENCIAL, $this->getId());

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

				$criteria->add(PerfilesCredencialesPeer::ID_CREDENCIAL, $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_CREDENCIAL, $this->getId());

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

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


	
	public function getPerfilesCredencialessJoinPerfiles($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_CREDENCIAL, $this->getId());

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

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

		return $this->collPerfilesCredencialess;
	}

} 